View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  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 edu.internet2.middleware.shibboleth.common.xmlobject.impl;
19  
20  import java.util.Map.Entry;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.opensaml.xml.Configuration;
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  import edu.internet2.middleware.shibboleth.common.ShibbolethConstants;
33  import edu.internet2.middleware.shibboleth.common.xmlobject.ShibbolethMetadataKeyAuthority;
34  
35  /**
36   * A thread-safe Marshaller for {@link ShibbolethMetadataKeyAuthority}.
37   */
38  public class ShibbolethMetadataKeyAuthorityMarshaller extends AbstractXMLObjectMarshaller {
39      
40      /** Constructor. */
41      public ShibbolethMetadataKeyAuthorityMarshaller() {
42          super(ShibbolethConstants.SHIB_MDEXT10_NS, ShibbolethMetadataKeyAuthority.DEFAULT_ELEMENT_LOCAL_NAME);
43      }
44  
45      /**
46       * Constructor.
47       * 
48       * @param namespaceURI the namespace URI
49       * @param elementLocalName the element local name
50       */
51      protected ShibbolethMetadataKeyAuthorityMarshaller(String namespaceURI, String elementLocalName) {
52          super(namespaceURI, elementLocalName);
53      }
54  
55      /** {@inheritDoc} */
56      protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
57          ShibbolethMetadataKeyAuthority keyAuthority = (ShibbolethMetadataKeyAuthority) xmlObject;
58          
59          if (keyAuthority.getVerifyDepth() != null) {
60              domElement.setAttributeNS(null, ShibbolethMetadataKeyAuthority.VERIFY_DEPTH_ATTRIB_NAME, 
61                      keyAuthority.getVerifyDepth().toString());
62          }
63          
64          Attr attr;
65          for(Entry<QName, String> entry: keyAuthority.getUnknownAttributes().entrySet()){
66              attr = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
67              attr.setValue(entry.getValue());
68              domElement.setAttributeNodeNS(attr);
69              if (Configuration.isIDAttribute(entry.getKey()) 
70                      || keyAuthority.getUnknownAttributes().isIDAttribute(entry.getKey())) {
71                  attr.getOwnerElement().setIdAttributeNode(attr, true);
72              }
73          }
74  
75      }
76  
77      /** {@inheritDoc} */
78      protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {
79          // nothing to implement
80      }
81  
82  
83  }