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
53 Map metaInfoMap = schemaObject.getMetaInfoMap();
54 if (metaInfoMap==null){
55 metaInfoMap = new HashMap();
56 }
57
58
59
60 if (node.getNodeType()==Node.ATTRIBUTE_NODE){
61
62 Map attribMap;
63 if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
64 attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
65 }else{
66 attribMap = new HashMap();
67 metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES,attribMap);
68 }
69 attribMap.put(name,node);
70
71 }else if (node.getNodeType()==Node.ELEMENT_NODE){
72 Map elementMap;
73 if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
74 elementMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
75 }else{
76 elementMap = new HashMap();
77 metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ELEMENTS,elementMap);
78 }
79 elementMap.put(name,node);
80 }
81
82 //subsequent processing takes place only if this map is not empty
83 if (!metaInfoMap.isEmpty()){
84 Map metaInfoMapFromSchemaElement = schemaObject.getMetaInfoMap();
85 if (metaInfoMapFromSchemaElement==null){
86 schemaObject.setMetaInfoMap(metaInfoMap);
87 }else{
88 metaInfoMapFromSchemaElement.putAll(metaInfoMap);
89 }
90
91 }
92
93
94 }
95 }