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