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 tests.customext.elt;
17  
18  import org.apache.ws.commons.schema.XmlSchemaObject;
19  import org.apache.ws.commons.schema.extensions.ExtensionDeserializer;
20  import org.w3c.dom.Element;
21  import org.w3c.dom.Node;
22  
23  import javax.xml.namespace.QName;
24  
25  /**
26   * Custom element deserializer
27   */
28  public class CustomElementDeserializer implements ExtensionDeserializer {
29      /**
30       * deserialize the given element
31       *
32       * @param schemaObject - Parent schema element
33       * @param name         - the QName of the element/attribute to be deserialized.
34       *                     in the case where a deserializer is used to handle multiple elements/attributes
35       *                     this may be useful to determine the correct deserialization
36       * @param domNode      - the raw DOM Node read from the source. This will be the
37       *                     extension element itself if for an element or the extension attribute object if
38       *                     it is an attribute
39       */
40      public void deserialize(XmlSchemaObject schemaObject, QName name, Node domNode) {
41           if (CustomElement.CUSTOM_ELT_QNAME.equals(name)){
42               Element elt = (Element)domNode;
43  
44               CustomElement customElement = new CustomElement();
45               customElement.setPrefix(elt.getAttribute("prefix"));
46               customElement.setSuffix(elt.getAttribute("suffix"));
47  
48               //put this in the schema object meta info map
49               schemaObject.addMetaInfo(CustomElement.CUSTOM_ELT_QNAME,customElement);
50           }
51      }
52  }