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.saml2.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.saml2.core.BaseID;
25  import org.opensaml.saml2.core.EncryptedID;
26  import org.opensaml.saml2.core.NameID;
27  import org.opensaml.saml2.core.Subject;
28  import org.opensaml.saml2.core.SubjectConfirmation;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.util.XMLObjectChildrenList;
31  
32  /**
33   * Concrete implementation of {@link org.opensaml.saml2.core.Subject}.
34   */
35  public class SubjectImpl extends AbstractSAMLObject implements Subject {
36  
37      /** BaseID child element. */
38      private BaseID baseID;
39  
40      /** NameID child element. */
41      private NameID nameID;
42  
43      /** EncryptedID child element. */
44      private EncryptedID encryptedID;
45  
46      /** Subject Confirmations of the Subject. */
47      private final XMLObjectChildrenList<SubjectConfirmation> subjectConfirmations;
48  
49      /**
50       * Constructor.
51       * 
52       * @param namespaceURI the namespace the element is in
53       * @param elementLocalName the local name of the XML element this Object represents
54       * @param namespacePrefix the prefix for the given namespace
55       */
56      protected SubjectImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
57          super(namespaceURI, elementLocalName, namespacePrefix);
58          subjectConfirmations = new XMLObjectChildrenList<SubjectConfirmation>(this);
59      }
60  
61      /** {@inheritDoc} */
62      public BaseID getBaseID() {
63          return baseID;
64      }
65  
66      /** {@inheritDoc} */
67      public void setBaseID(BaseID newBaseID) {
68          baseID = prepareForAssignment(baseID, newBaseID);
69      }
70  
71      /** {@inheritDoc} */
72      public NameID getNameID() {
73          return nameID;
74      }
75  
76      /** {@inheritDoc} */
77      public void setNameID(NameID newNameID) {
78          nameID = prepareForAssignment(nameID, newNameID);
79      }
80  
81      /** {@inheritDoc} */
82      public EncryptedID getEncryptedID() {
83          return this.encryptedID;
84      }
85  
86      /** {@inheritDoc} */
87      public void setEncryptedID(EncryptedID newEncryptedID) {
88          this.encryptedID = prepareForAssignment(this.encryptedID, newEncryptedID);
89      }
90  
91      /** {@inheritDoc} */
92      public List<SubjectConfirmation> getSubjectConfirmations() {
93          return subjectConfirmations;
94      }
95  
96      /** {@inheritDoc} */
97      public List<XMLObject> getOrderedChildren() {
98          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
99  
100         if (baseID != null) {
101             children.add(baseID);
102         }
103 
104         if (nameID != null) {
105             children.add(nameID);
106         }
107 
108         if (encryptedID != null) {
109             children.add(encryptedID);
110         }
111 
112         children.addAll(subjectConfirmations);
113 
114         return Collections.unmodifiableList(children);
115     }
116 }