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      /** Constructor. */
37      public AbstractExtensibleXMLObjectMarshaller(){
38          super();
39      }
40  
41      /**
42       * Constructor.
43       * 
44       * @deprecated no replacement
45       * 
46       * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this
47       *            unmarshaller operates on
48       * @param targetLocalName the local name of either the schema type QName or element QName of the elements this
49       *            unmarshaller operates on
50       */
51      public AbstractExtensibleXMLObjectMarshaller(String targetNamespaceURI, String targetLocalName) {
52          super(targetNamespaceURI, targetLocalName);
53      }
54  
55      /**
56       * Marshalls the <code>xs:anyAttribute</code> attributes.
57       * 
58       * {@inheritDoc}
59       */
60      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
61          AttributeExtensibleXMLObject anyAttribute = (AttributeExtensibleXMLObject) xmlObject;
62          Attr attribute;
63          Document document = domElement.getOwnerDocument();
64          for (Entry<QName, String> entry : anyAttribute.getUnknownAttributes().entrySet()) {
65              attribute = XMLHelper.constructAttribute(document, entry.getKey());
66              attribute.setValue(entry.getValue());
67              domElement.setAttributeNodeNS(attribute);
68              if (Configuration.isIDAttribute(entry.getKey())
69                      || anyAttribute.getUnknownAttributes().isIDAttribute(entry.getKey())) {
70                  attribute.getOwnerElement().setIdAttributeNode(attribute, true);
71              }
72          }
73      }
74  
75  }