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