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  /**
18   * 
19   */
20  
21  package org.opensaml.saml2.core.impl;
22  
23  import org.joda.time.DateTime;
24  import org.joda.time.chrono.ISOChronology;
25  import org.opensaml.common.SAMLVersion;
26  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
27  import org.opensaml.saml2.common.Extensions;
28  import org.opensaml.saml2.core.Issuer;
29  import org.opensaml.saml2.core.Status;
30  import org.opensaml.saml2.core.StatusResponseType;
31  import org.opensaml.xml.XMLObject;
32  import org.opensaml.xml.io.UnmarshallingException;
33  import org.opensaml.xml.signature.Signature;
34  import org.opensaml.xml.util.DatatypeHelper;
35  import org.w3c.dom.Attr;
36  
37  /**
38   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.StatusResponseType} objects.
39   */
40  public abstract class StatusResponseTypeUnmarshaller extends AbstractSAMLObjectUnmarshaller {
41  
42      /** {@inheritDoc} */
43      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
44          StatusResponseType sr = (StatusResponseType) samlObject;
45  
46          if (attribute.getLocalName().equals(StatusResponseType.VERSION_ATTRIB_NAME)) {
47              sr.setVersion(SAMLVersion.valueOf(attribute.getValue()));
48          } else if (attribute.getLocalName().equals(StatusResponseType.ID_ATTRIB_NAME)) {
49              sr.setID(attribute.getValue());
50              attribute.getOwnerElement().setIdAttributeNode(attribute, true);
51          } else if (attribute.getLocalName().equals(StatusResponseType.IN_RESPONSE_TO_ATTRIB_NAME)) {
52              sr.setInResponseTo(attribute.getValue());
53          } else if (attribute.getLocalName().equals(StatusResponseType.ISSUE_INSTANT_ATTRIB_NAME)
54                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
55              sr.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
56          } else if (attribute.getLocalName().equals(StatusResponseType.DESTINATION_ATTRIB_NAME)) {
57              sr.setDestination(attribute.getValue());
58          } else if (attribute.getLocalName().equals(StatusResponseType.CONSENT_ATTRIB_NAME)) {
59              sr.setConsent(attribute.getValue());
60          } else {
61              super.processAttribute(samlObject, attribute);
62          }
63      }
64  
65      /** {@inheritDoc} */
66      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
67              throws UnmarshallingException {
68          StatusResponseType sr = (StatusResponseType) parentSAMLObject;
69  
70          if (childSAMLObject instanceof Issuer) {
71              sr.setIssuer((Issuer) childSAMLObject);
72          } else if (childSAMLObject instanceof Signature) {
73              sr.setSignature((Signature) childSAMLObject);
74          } else if (childSAMLObject instanceof Extensions) {
75              sr.setExtensions((Extensions) childSAMLObject);
76          } else if (childSAMLObject instanceof Status) {
77              sr.setStatus((Status) childSAMLObject);
78          } else {
79              super.processChildElement(parentSAMLObject, childSAMLObject);
80          }
81      }
82  }