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 tests.customext.elt;
20  
21  import org.apache.ws.commons.schema.XmlSchemaObject;
22  import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
23  import org.w3c.dom.Element;
24  import org.w3c.dom.Node;
25  
26  import java.util.Map;
27  
28  /**
29   * Custom element serializer
30   */
31  public class CustomElementSerializer implements ExtensionSerializer {
32      /**
33       * serialize the given element
34       *
35       * @param schemaObject - Parent schema object.contains the extension
36       *                     to be serialized
37       * @param classOfType  - The class of type to be serialized
38       * @param domNode      - the parent DOM Node that will ultimately be serialized. The XMLSchema
39       *                     serialization mechanism is to create a DOM tree first and serialize it
40       */
41      public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
42         Map metaInfoMap = schemaObject.getMetaInfoMap();
43         CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
44  
45          Element elt = (Element)domNode;
46          Element extElt = elt.getOwnerDocument().createElementNS(CustomElement.CUSTOM_ELT_QNAME.getNamespaceURI(),
47                                                               CustomElement.CUSTOM_ELT_QNAME.getLocalPart());
48          extElt.setAttribute("prefix",customElt.getPrefix());
49          extElt.setAttribute("suffix",customElt.getSuffix());
50  
51          elt.appendChild(extElt);
52  
53      }
54  }