View Javadoc

1   /*
2    * Copyright 2008 Members of the EGEE Collaboration.
3    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.opensaml.xml;
19  
20  import java.util.Map.Entry;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.opensaml.xml.io.MarshallingException;
25  import org.opensaml.xml.util.XMLHelper;
26  import org.w3c.dom.Attr;
27  import org.w3c.dom.Document;
28  import org.w3c.dom.Element;
29  
30  /**
31   * AbstractExtensibleXMLObjectMarshaller marshalls element of type <code>xs:any</code> and with
32   * <code>xs:anyAttribute</code> attributes.
33   */
34  public class AbstractExtensibleXMLObjectMarshaller extends AbstractElementExtensibleXMLObjectMarshaller {
35  
36      /**
37       * Constructor.
38       * 
39       * @deprecated no replacement
40       * 
41       * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this
42       *            unmarshaller operates on
43       * @param targetLocalName the local name of either the schema type QName or element QName of the elements this
44       *            unmarshaller operates on
45       */
46      public AbstractExtensibleXMLObjectMarshaller(String targetNamespaceURI, String targetLocalName) {
47          super(targetNamespaceURI, targetLocalName);
48      }
49  
50      /**
51       * Marshalls the <code>xs:anyAttribute</code> attributes.
52       * 
53       * {@inheritDoc}
54       */
55      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
56          AttributeExtensibleXMLObject anyAttribute = (AttributeExtensibleXMLObject) xmlObject;
57          Attr attribute;
58          Document document = domElement.getOwnerDocument();
59          for (Entry<QName, String> entry : anyAttribute.getUnknownAttributes().entrySet()) {
60              attribute = XMLHelper.constructAttribute(document, entry.getKey());
61              attribute.setValue(entry.getValue());
62              domElement.setAttributeNodeNS(attribute);
63              if (Configuration.isIDAttribute(entry.getKey())
64                      || anyAttribute.getUnknownAttributes().isIDAttribute(entry.getKey())) {
65                  attribute.getOwnerElement().setIdAttributeNode(attribute, true);
66              }
67          }
68      }
69  
70  }