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 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
39
40 public class AffiliationDescriptorUnmarshaller extends AbstractSAMLObjectUnmarshaller {
41
42
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
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 }