View Javadoc

1   /*
2    * Copyright [2005] [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.saml2.metadata.impl;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.joda.time.DateTime;
22  import org.joda.time.chrono.ISOChronology;
23  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
24  import org.opensaml.saml2.common.CacheableSAMLObject;
25  import org.opensaml.saml2.common.Extensions;
26  import org.opensaml.saml2.common.TimeBoundSAMLObject;
27  import org.opensaml.saml2.metadata.AffiliateMember;
28  import org.opensaml.saml2.metadata.AffiliationDescriptor;
29  import org.opensaml.saml2.metadata.KeyDescriptor;
30  import org.opensaml.xml.XMLObject;
31  import org.opensaml.xml.io.UnmarshallingException;
32  import org.opensaml.xml.signature.Signature;
33  import org.opensaml.xml.util.DatatypeHelper;
34  import org.opensaml.xml.util.XMLHelper;
35  import org.w3c.dom.Attr;
36  
37  /**
38   * A thread safe Unmarshaller for {@link org.opensaml.saml2.metadata.AffiliationDescriptor}s.
39   */
40  public class AffiliationDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
41  
42      /** {@inheritDoc} */
43      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
44              throws UnmarshallingException {
45          AffiliationDescriptor descriptor = (AffiliationDescriptor) parentSAMLObject;
46  
47          if (childSAMLObject instanceof Extensions) {
48              descriptor.setExtensions((Extensions) childSAMLObject);
49          } else if (childSAMLObject instanceof Signature) {
50              descriptor.setSignature((Signature) childSAMLObject);
51          } else if (childSAMLObject instanceof AffiliateMember) {
52              descriptor.getMembers().add((AffiliateMember) childSAMLObject);
53          } else if (childSAMLObject instanceof KeyDescriptor) {
54              descriptor.getKeyDescriptors().add((KeyDescriptor) childSAMLObject);
55          } else {
56              super.processChildElement(parentSAMLObject, childSAMLObject);
57          }
58      }
59  
60      /** {@inheritDoc} */
61      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
62          AffiliationDescriptor descriptor = (AffiliationDescriptor) samlObject;
63  
64          if (attribute.getLocalName().equals(AffiliationDescriptor.OWNER_ID_ATTRIB_NAME)) {
65              descriptor.setOwnerID(attribute.getValue());
66          } else if (attribute.getLocalName().equals(AffiliationDescriptor.ID_ATTRIB_NAME)) {
67              descriptor.setID(attribute.getValue());
68              attribute.getOwnerElement().setIdAttributeNode(attribute, true);
69          } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME)
70                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
71              descriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
72          } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) {
73              descriptor.setCacheDuration(XMLHelper.durationToLong(attribute.getValue()));
74          } else {
75              QName attribQName = XMLHelper.getNodeQName(attribute);
76              if (attribute.isId()) {
77                  descriptor.getUnknownAttributes().registerID(attribQName);
78              }
79              descriptor.getUnknownAttributes().put(attribQName, attribute.getValue());
80          }
81      }
82  }