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  package org.opensaml.saml1.core.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.opensaml.common.impl.AbstractSAMLObject;
24  import org.opensaml.saml1.core.ConfirmationMethod;
25  import org.opensaml.saml1.core.SubjectConfirmation;
26  import org.opensaml.xml.XMLObject;
27  import org.opensaml.xml.signature.KeyInfo;
28  import org.opensaml.xml.util.XMLObjectChildrenList;
29  
30  /**
31   * Concrete implementation of a <code> SubjectConfirmation </code> object
32   */
33  public class SubjectConfirmationImpl extends AbstractSAMLObject implements SubjectConfirmation {
34  
35      /** Contains the list of ConfirmationMethods */
36      private final XMLObjectChildrenList<ConfirmationMethod> confirmationMethods;
37  
38      /** Contains the SubjectConfirmationData element */
39      private XMLObject subjectConfirmationData;
40  
41      /** Contains the KeyInfo element */
42      private KeyInfo keyInfo;
43  
44      /**
45       * Constructor
46       * 
47       * @param namespaceURI the namespace the element is in
48       * @param elementLocalName the local name of the XML element this Object represents
49       * @param namespacePrefix the prefix for the given namespace
50       */
51      protected SubjectConfirmationImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
52          super(namespaceURI, elementLocalName, namespacePrefix);
53          confirmationMethods = new XMLObjectChildrenList<ConfirmationMethod>(this);
54      }
55  
56      /** {@inheritDoc} */
57      public List<ConfirmationMethod> getConfirmationMethods() {
58          return confirmationMethods;
59      }
60  
61      /** {@inheritDoc} */
62      public void setSubjectConfirmationData(XMLObject subjectConfirmationData)
63              throws IllegalArgumentException {
64  
65          this.subjectConfirmationData = prepareForAssignment(this.subjectConfirmationData, subjectConfirmationData);
66      }
67  
68      /** {@inheritDoc} */
69      public XMLObject getSubjectConfirmationData() {
70          return subjectConfirmationData;
71      }
72  
73      /** {@inheritDoc} */
74      public KeyInfo getKeyInfo() {
75          return keyInfo;
76      }
77  
78      /** {@inheritDoc} */
79      public void setKeyInfo(KeyInfo keyInfo) {
80          this.keyInfo = prepareForAssignment(this.keyInfo, keyInfo);
81      }
82  
83      /** {@inheritDoc} */
84      public List<XMLObject> getOrderedChildren() {
85  
86          List<XMLObject> list = new ArrayList<XMLObject>(confirmationMethods.size() + 1);
87  
88          list.addAll(confirmationMethods);
89  
90          if (subjectConfirmationData != null) {
91              list.add(subjectConfirmationData);
92          }
93  
94          if(keyInfo != null){
95              list.add(keyInfo);
96          }
97  
98          if (list.size() == 0) {
99              return null;
100         }
101         return Collections.unmodifiableList(list);
102     }
103 }