View Javadoc

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