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 javax.xml.namespace.QName;
24  
25  import org.joda.time.DateTime;
26  import org.joda.time.chrono.ISOChronology;
27  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
28  import org.opensaml.saml2.core.SubjectConfirmationData;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.io.UnmarshallingException;
31  import org.opensaml.xml.util.DatatypeHelper;
32  import org.opensaml.xml.util.XMLHelper;
33  import org.w3c.dom.Attr;
34  
35  /**
36   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.SubjectConfirmationData} objects.
37   */
38  public class SubjectConfirmationDataUnmarshaller extends AbstractSAMLObjectUnmarshaller {
39  
40      /**
41       * {@inheritDoc}
42       */
43      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
44              throws UnmarshallingException {
45          SubjectConfirmationData subjectCD = (SubjectConfirmationData) parentSAMLObject;
46  
47          subjectCD.getUnknownXMLObjects().add(childSAMLObject);
48      }
49  
50      /** {@inheritDoc} */
51      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
52          SubjectConfirmationData subjectCD = (SubjectConfirmationData) samlObject;
53  
54          if (attribute.getLocalName().equals(SubjectConfirmationData.NOT_BEFORE_ATTRIB_NAME)
55                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
56              subjectCD.setNotBefore(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
57          } else if (attribute.getLocalName().equals(SubjectConfirmationData.NOT_ON_OR_AFTER_ATTRIB_NAME)
58                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
59              subjectCD.setNotOnOrAfter(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
60          } else if (attribute.getLocalName().equals(SubjectConfirmationData.RECIPIENT_ATTRIB_NAME)) {
61              subjectCD.setRecipient(attribute.getValue());
62          } else if (attribute.getLocalName().equals(SubjectConfirmationData.IN_RESPONSE_TO_ATTRIB_NAME)) {
63              subjectCD.setInResponseTo(attribute.getValue());
64          } else if (attribute.getLocalName().equals(SubjectConfirmationData.ADDRESS_ATTRIB_NAME)) {
65              subjectCD.setAddress(attribute.getValue());
66          } else {
67              QName attribQName = XMLHelper.getNodeQName(attribute);
68              if (attribute.isId()) {
69                  subjectCD.getUnknownAttributes().registerID(attribQName);
70              }
71              subjectCD.getUnknownAttributes().put(attribQName, attribute.getValue());
72          }
73      }
74  }