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.metadata.impl;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
26  import org.opensaml.saml2.common.Extensions;
27  import org.opensaml.saml2.metadata.Company;
28  import org.opensaml.saml2.metadata.ContactPerson;
29  import org.opensaml.saml2.metadata.ContactPersonTypeEnumeration;
30  import org.opensaml.saml2.metadata.EmailAddress;
31  import org.opensaml.saml2.metadata.GivenName;
32  import org.opensaml.saml2.metadata.SurName;
33  import org.opensaml.saml2.metadata.TelephoneNumber;
34  import org.opensaml.xml.XMLObject;
35  import org.opensaml.xml.io.UnmarshallingException;
36  import org.opensaml.xml.util.XMLHelper;
37  import org.w3c.dom.Attr;
38  
39  /**
40   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.metadata.ContactPerson} objects.
41   */
42  public class ContactPersonUnmarshaller extends AbstractSAMLObjectUnmarshaller {
43  
44      /** {@inheritDoc} */
45      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
46              throws UnmarshallingException {
47          ContactPerson person = (ContactPerson) parentSAMLObject;
48  
49          if (childSAMLObject instanceof Extensions) {
50              person.setExtensions((Extensions) childSAMLObject);
51          } else if (childSAMLObject instanceof Company) {
52              person.setCompany((Company) childSAMLObject);
53          } else if (childSAMLObject instanceof GivenName) {
54              person.setGivenName((GivenName) childSAMLObject);
55          } else if (childSAMLObject instanceof SurName) {
56              person.setSurName((SurName) childSAMLObject);
57          } else if (childSAMLObject instanceof EmailAddress) {
58              person.getEmailAddresses().add((EmailAddress) childSAMLObject);
59          } else if (childSAMLObject instanceof TelephoneNumber) {
60              person.getTelephoneNumbers().add((TelephoneNumber) childSAMLObject);
61          } else {
62              super.processChildElement(parentSAMLObject, childSAMLObject);
63          }
64      }
65  
66      /** {@inheritDoc} */
67      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
68          ContactPerson person = (ContactPerson) samlObject;
69  
70          if (attribute.getLocalName().equals(ContactPerson.CONTACT_TYPE_ATTRIB_NAME)) {
71              if (ContactPersonTypeEnumeration.TECHNICAL.toString().equals(attribute.getValue())) {
72                  person.setType(ContactPersonTypeEnumeration.TECHNICAL);
73              } else if (ContactPersonTypeEnumeration.SUPPORT.toString().equals(attribute.getValue())) {
74                  person.setType(ContactPersonTypeEnumeration.SUPPORT);
75              } else if (ContactPersonTypeEnumeration.ADMINISTRATIVE.toString().equals(attribute.getValue())) {
76                  person.setType(ContactPersonTypeEnumeration.ADMINISTRATIVE);
77              } else if (ContactPersonTypeEnumeration.BILLING.toString().equals(attribute.getValue())) {
78                  person.setType(ContactPersonTypeEnumeration.BILLING);
79              } else if (ContactPersonTypeEnumeration.OTHER.toString().equals(attribute.getValue())) {
80                  person.setType(ContactPersonTypeEnumeration.OTHER);
81              } else {
82                  super.processAttribute(samlObject, attribute);
83              }
84          } else {
85              QName attribQName = XMLHelper.getNodeQName(attribute);
86              if (attribute.isId()) {
87                  person.getUnknownAttributes().registerID(attribQName);
88              }
89              person.getUnknownAttributes().put(attribQName, attribute.getValue());
90          }
91      }
92  }