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 org.joda.time.DateTime;
20  import org.joda.time.chrono.ISOChronology;
21  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
22  import org.opensaml.saml2.common.CacheableSAMLObject;
23  import org.opensaml.saml2.common.Extensions;
24  import org.opensaml.saml2.common.TimeBoundSAMLObject;
25  import org.opensaml.saml2.metadata.EntitiesDescriptor;
26  import org.opensaml.saml2.metadata.EntityDescriptor;
27  import org.opensaml.xml.XMLObject;
28  import org.opensaml.xml.io.UnmarshallingException;
29  import org.opensaml.xml.signature.Signature;
30  import org.opensaml.xml.util.DatatypeHelper;
31  import org.opensaml.xml.util.XMLHelper;
32  import org.w3c.dom.Attr;
33  
34  /**
35   * A thread safe Unmarshaller for {@link org.opensaml.saml2.metadata.EntitiesDescriptor} objects.
36   */
37  public class EntitiesDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
38  
39      /** {@inheritDoc} */
40      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
41              throws UnmarshallingException {
42          EntitiesDescriptor entitiesDescriptor = (EntitiesDescriptor) parentSAMLObject;
43  
44          if (childSAMLObject instanceof Extensions) {
45              entitiesDescriptor.setExtensions((Extensions) childSAMLObject);
46          } else if (childSAMLObject instanceof EntitiesDescriptor) {
47              entitiesDescriptor.getEntitiesDescriptors().add((EntitiesDescriptor) childSAMLObject);
48          } else if (childSAMLObject instanceof EntityDescriptor) {
49              entitiesDescriptor.getEntityDescriptors().add((EntityDescriptor) childSAMLObject);
50          } else if (childSAMLObject instanceof Signature) {
51              entitiesDescriptor.setSignature((Signature) childSAMLObject);
52          } else {
53              super.processChildElement(parentSAMLObject, childSAMLObject);
54          }
55      }
56  
57      /** {@inheritDoc} */
58      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
59          EntitiesDescriptor entitiesDescriptor = (EntitiesDescriptor) samlObject;
60  
61          if (attribute.getLocalName().equals(EntitiesDescriptor.ID_ATTRIB_NAME)) {
62              entitiesDescriptor.setID(attribute.getValue());
63              attribute.getOwnerElement().setIdAttributeNode(attribute, true);
64          } else if (attribute.getLocalName().equals(TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME)
65                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
66              entitiesDescriptor.setValidUntil(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
67          } else if (attribute.getLocalName().equals(CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME)) {
68              entitiesDescriptor.setCacheDuration(new Long(XMLHelper.durationToLong(attribute.getValue())));
69          } else if (attribute.getLocalName().equals(EntitiesDescriptor.NAME_ATTRIB_NAME)) {
70              entitiesDescriptor.setName(attribute.getValue());
71          } else {
72              super.processAttribute(samlObject, attribute);
73          }
74      }
75  }