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.attrib;
17  
18  import org.apache.ws.commons.schema.XmlSchemaObject;
19  import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
20  import org.w3c.dom.Attr;
21  import org.w3c.dom.Element;
22  import org.w3c.dom.Node;
23  
24  import java.util.Map;
25  
26  /**
27   * serializer for the custom attribute
28   */
29  public class CustomAttributeSerializer  implements ExtensionSerializer {
30  
31      /**
32       * serialize the given element
33       *
34       * @param schemaObject - Parent schema object.contains the extension
35       *                     to be serialized
36       * @param classOfType  - The class of type to be serialized
37       * @param domNode      - the parent DOM Node that will ultimately be serialized. The XMLSchema
38       *                     serialization mechanism is to create a DOM tree first and serialize it
39       */
40      public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
41          Map metaInfoMap = schemaObject.getMetaInfoMap();
42          CustomAttribute att = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
43  
44          Element elt = (Element)domNode;
45          Attr att1 = elt.getOwnerDocument().createAttributeNS(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getNamespaceURI(),
46                                                               CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getLocalPart());
47          att1.setValue(att.getPrefix() + ":" + att.getSuffix());
48          elt.setAttributeNodeNS(att1);
49      }
50  }