View Javadoc

1   /*
2    * Copyright [2007] [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 edu.internet2.middleware.shibboleth.common.xmlobject.impl;
18  
19  import java.util.Map.Entry;
20  
21  import javax.xml.namespace.QName;
22  
23  import org.opensaml.xml.Configuration;
24  import org.opensaml.xml.XMLObject;
25  import org.opensaml.xml.io.AbstractXMLObjectMarshaller;
26  import org.opensaml.xml.io.MarshallingException;
27  import org.opensaml.xml.util.XMLHelper;
28  import org.w3c.dom.Attr;
29  import org.w3c.dom.Element;
30  
31  import edu.internet2.middleware.shibboleth.common.ShibbolethConstants;
32  import edu.internet2.middleware.shibboleth.common.xmlobject.ShibbolethMetadataKeyAuthority;
33  
34  /**
35   * A thread-safe Marshaller for {@link ShibbolethMetadataKeyAuthority}.
36   */
37  public class ShibbolethMetadataKeyAuthorityMarshaller extends AbstractXMLObjectMarshaller {
38      
39      /** Constructor. */
40      public ShibbolethMetadataKeyAuthorityMarshaller() {
41          super(ShibbolethConstants.SHIB_MDEXT10_NS, ShibbolethMetadataKeyAuthority.DEFAULT_ELEMENT_LOCAL_NAME);
42      }
43  
44      /**
45       * Constructor.
46       * 
47       * @param namespaceURI the namespace URI
48       * @param elementLocalName the element local name
49       */
50      protected ShibbolethMetadataKeyAuthorityMarshaller(String namespaceURI, String elementLocalName) {
51          super(namespaceURI, elementLocalName);
52      }
53  
54      /** {@inheritDoc} */
55      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
56          ShibbolethMetadataKeyAuthority keyAuthority = (ShibbolethMetadataKeyAuthority) xmlObject;
57          
58          if (keyAuthority.getVerifyDepth() != null) {
59              domElement.setAttributeNS(null, ShibbolethMetadataKeyAuthority.VERIFY_DEPTH_ATTRIB_NAME, 
60                      keyAuthority.getVerifyDepth().toString());
61          }
62          
63          Attr attr;
64          for(Entry<QName, String> entry: keyAuthority.getUnknownAttributes().entrySet()){
65              attr = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
66              attr.setValue(entry.getValue());
67              domElement.setAttributeNodeNS(attr);
68              if (Configuration.isIDAttribute(entry.getKey()) 
69                      || keyAuthority.getUnknownAttributes().isIDAttribute(entry.getKey())) {
70                  attr.getOwnerElement().setIdAttributeNode(attr, true);
71              }
72          }
73  
74      }
75  
76      /** {@inheritDoc} */
77      protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
78          // nothing to implement
79      }
80  
81  
82  }