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.RequestAbstractType;
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.w3c.dom.Attr;
35  
36  /**
37   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.RequestAbstractType} objects.
38   */
39  public abstract class RequestAbstractTypeUnmarshaller extends AbstractSAMLObjectUnmarshaller {
40  
41      /** {@inheritDoc} */
42      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
43          RequestAbstractType req = (RequestAbstractType) samlObject;
44  
45          if (attribute.getLocalName().equals(RequestAbstractType.VERSION_ATTRIB_NAME)) {
46              req.setVersion(SAMLVersion.valueOf(attribute.getValue()));
47          } else if (attribute.getLocalName().equals(RequestAbstractType.ID_ATTRIB_NAME)) {
48              req.setID(attribute.getValue());
49              attribute.getOwnerElement().setIdAttributeNode(attribute, true);
50          } else if (attribute.getLocalName().equals(RequestAbstractType.ISSUE_INSTANT_ATTRIB_NAME)
51                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
52              req.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
53          } else if (attribute.getLocalName().equals(RequestAbstractType.DESTINATION_ATTRIB_NAME)) {
54              req.setDestination(attribute.getValue());
55          } else if (attribute.getLocalName().equals(RequestAbstractType.CONSENT_ATTRIB_NAME)) {
56              req.setConsent(attribute.getValue());
57          } else {
58              super.processAttribute(samlObject, attribute);
59          }
60      }
61  
62      /** {@inheritDoc} */
63      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
64              throws UnmarshallingException {
65          RequestAbstractType req = (RequestAbstractType) parentSAMLObject;
66  
67          if (childSAMLObject instanceof Issuer) {
68              req.setIssuer((Issuer) childSAMLObject);
69          } else if (childSAMLObject instanceof Signature) {
70              req.setSignature((Signature) childSAMLObject);
71          } else if (childSAMLObject instanceof Extensions) {
72              req.setExtensions((Extensions) childSAMLObject);
73          } else {
74              super.processChildElement(parentSAMLObject, childSAMLObject);
75          }
76      }
77  }