1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
36
37 public class EntitiesDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
38
39
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
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 }