View Javadoc

1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.ws.commons.schema.extensions;
17  
18  import org.apache.ws.commons.schema.XmlSchemaObject;
19  import org.apache.ws.commons.schema.constants.Constants;
20  import org.w3c.dom.Node;
21  
22  import javax.xml.namespace.QName;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  /**
27   * Default deserializer. The action taken when there is nothing specific
28   * to be done would be to attach the raw element object as it is to the
29   * meta information map for an element or the raw attribute object
30   *
31   */
32  public class DefaultExtensionDeserializer implements ExtensionDeserializer {
33  
34      /**
35       * deserialize the given element
36       *
37       * @param schemaObject - Parent schema element
38       * @param name         - the QName of the element/attribute to be deserialized.
39       *                     in the case where a deserializer is used to handle multiple elements/attributes
40       *                     this may be useful to determine the correct deserialization
41       * @param node - the raw DOM Node read from the source. This will be the
42       * extension element itself if for an element or the extension attribute object if
43       * it is an attribute
44       */
45      public void deserialize(XmlSchemaObject schemaObject, QName name, Node node) {
46  
47          // we just attach the raw node either to the meta map of
48          // elements or the attributes
49          Map metaInfoMap =  new HashMap();
50  
51  
52  
53          if (node.getNodeType()==Node.ATTRIBUTE_NODE){
54  
55              Map attribMap; 
56              if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
57                  attribMap  = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
58              }else{
59                  attribMap = new HashMap();
60                  metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES,attribMap);
61              }
62              attribMap.put(name,node);
63  
64          }else if (node.getNodeType()==Node.ELEMENT_NODE){
65              Map elementMap;
66              if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
67                  elementMap  = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
68              }else{
69                  elementMap = new HashMap();
70                  metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ELEMENTS,elementMap);
71              }
72              elementMap.put(name,node);
73          }
74  
75          //subsequent processing takes place only if this map is not empty
76          if (!metaInfoMap.isEmpty()){
77              Map metaInfoMapFromSchemaElement = schemaObject.getMetaInfoMap();
78              if (metaInfoMapFromSchemaElement==null){
79                  schemaObject.setMetaInfoMap(metaInfoMap);
80              }else{
81                  metaInfoMapFromSchemaElement.putAll(metaInfoMap);
82              }
83  
84          }
85  
86  
87      }
88  }