View Javadoc

1   /*
2    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
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  
17  package org.opensaml.xacml.ctx.impl;
18  
19  import java.util.Map.Entry;
20  
21  import javax.xml.namespace.QName;
22  
23  import org.opensaml.Configuration;
24  import org.opensaml.xacml.ctx.ResourceContentType;
25  import org.opensaml.xml.XMLObject;
26  import org.opensaml.xml.io.AbstractXMLObjectMarshaller;
27  import org.opensaml.xml.io.MarshallingException;
28  import org.opensaml.xml.util.XMLHelper;
29  import org.w3c.dom.Attr;
30  import org.w3c.dom.Element;
31  
32  /** Marshaller for {@link ResourceContentType} objects. */
33  public class ResourceContentTypeMarshaller extends AbstractXMLObjectMarshaller {
34      
35      /** Constructor. */
36      public ResourceContentTypeMarshaller() {
37          super();
38      }
39  
40      /**
41       * Constructor.
42       * 
43       * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this
44       *            marshaller operates on
45       * @param targetLocalName the local name of either the schema type QName or element QName of the elements this
46       *            marshaller operates on
47       */
48      protected ResourceContentTypeMarshaller(String targetNamespaceURI, String targetLocalName) {
49          super(targetNamespaceURI, targetLocalName);
50      }
51  
52      /** {@inheritDoc} */
53      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
54          ResourceContentType resourceContent  = (ResourceContentType)xmlObject;
55          
56          Attr attribute;
57          for (Entry<QName, String> entry : resourceContent.getUnknownAttributes().entrySet()) {
58              attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
59              attribute.setValue(entry.getValue());
60              domElement.setAttributeNodeNS(attribute);
61              if (Configuration.isIDAttribute(entry.getKey())
62                      || resourceContent.getUnknownAttributes().isIDAttribute(entry.getKey())) {
63                  attribute.getOwnerElement().setIdAttributeNode(attribute, true);
64              }
65          }
66      }
67  
68      /** {@inheritDoc} */
69      protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
70          ResourceContentType resourceContent = (ResourceContentType) xmlObject;
71          
72          if(resourceContent.getValue() != null){
73              XMLHelper.appendTextContent(domElement, resourceContent.getValue());
74          }
75      }
76  }