View Javadoc

1   /*
2    * Copyright [2006] [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.xml.signature.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.opensaml.xml.XMLObject;
26  import org.opensaml.xml.encryption.AgreementMethod;
27  import org.opensaml.xml.encryption.EncryptedKey;
28  import org.opensaml.xml.signature.KeyInfoType;
29  import org.opensaml.xml.signature.KeyName;
30  import org.opensaml.xml.signature.KeyValue;
31  import org.opensaml.xml.signature.MgmtData;
32  import org.opensaml.xml.signature.PGPData;
33  import org.opensaml.xml.signature.RetrievalMethod;
34  import org.opensaml.xml.signature.SPKIData;
35  import org.opensaml.xml.signature.X509Data;
36  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
37  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
38  
39  /**
40   * Concrete implementation of {@link org.opensaml.xml.signature.KeyInfoType}
41   */
42  public class KeyInfoTypeImpl extends AbstractValidatingXMLObject implements KeyInfoType {
43      
44      /** The list of XMLObject child elements */
45      private final IndexedXMLObjectChildrenList indexedChildren;
46      
47      /** The Id attribute value */
48      private String id;
49  
50      /**
51       * Constructor
52       *
53       * @param namespaceURI
54       * @param elementLocalName
55       * @param namespacePrefix
56       */
57      protected KeyInfoTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
58          super(namespaceURI, elementLocalName, namespacePrefix);
59          indexedChildren = new IndexedXMLObjectChildrenList(this);
60      }
61      
62      /** {@inheritDoc} */
63      public String getID() {
64          return this.id;
65      }
66  
67      /** {@inheritDoc} */
68      public void setID(String newID) {
69          String oldID = this.id;
70          this.id = prepareForAssignment(this.id, newID);
71          registerOwnID(oldID, this.id);
72      }
73  
74      /** {@inheritDoc} */
75      public List<XMLObject> getXMLObjects() {
76          return (List<XMLObject>) indexedChildren;
77      }
78  
79      /** {@inheritDoc} */
80      public List<XMLObject> getXMLObjects(QName typeOrName) {
81          return (List<XMLObject>) indexedChildren.subList(typeOrName);
82      }
83  
84      /** {@inheritDoc} */
85      public List<KeyName> getKeyNames() {
86          return (List<KeyName>) indexedChildren.subList(KeyName.DEFAULT_ELEMENT_NAME);
87      }
88  
89      /** {@inheritDoc} */
90      public List<KeyValue> getKeyValues() {
91          return (List<KeyValue>) indexedChildren.subList(KeyValue.DEFAULT_ELEMENT_NAME);
92      }
93  
94      /** {@inheritDoc} */
95      public List<RetrievalMethod> getRetrievalMethods() {
96          return (List<RetrievalMethod>) indexedChildren.subList(RetrievalMethod.DEFAULT_ELEMENT_NAME);
97      }
98  
99      /** {@inheritDoc} */
100     public List<X509Data> getX509Datas() {
101         return (List<X509Data>) indexedChildren.subList(X509Data.DEFAULT_ELEMENT_NAME);
102     }
103 
104     /** {@inheritDoc} */
105     public List<PGPData> getPGPDatas() {
106         return (List<PGPData>) indexedChildren.subList(PGPData.DEFAULT_ELEMENT_NAME);
107     }
108 
109     /** {@inheritDoc} */
110     public List<SPKIData> getSPKIDatas() {
111         return (List<SPKIData>) indexedChildren.subList(SPKIData.DEFAULT_ELEMENT_NAME);
112     }
113 
114     /** {@inheritDoc} */
115     public List<MgmtData> getMgmtDatas() {
116         return (List<MgmtData>) indexedChildren.subList(MgmtData.DEFAULT_ELEMENT_NAME);
117     }
118 
119     /** {@inheritDoc} */
120     public List<AgreementMethod> getAgreementMethods() {
121         return (List<AgreementMethod>) indexedChildren.subList(AgreementMethod.DEFAULT_ELEMENT_NAME);
122     }
123 
124     /** {@inheritDoc} */
125     public List<EncryptedKey> getEncryptedKeys() {
126         return (List<EncryptedKey>) indexedChildren.subList(EncryptedKey.DEFAULT_ELEMENT_NAME);
127     }
128 
129     /** {@inheritDoc} */
130     public List<XMLObject> getOrderedChildren() {
131         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
132         
133         children.addAll(indexedChildren);
134         
135         if (children.size() == 0) {
136             return null;
137         }
138         
139         return Collections.unmodifiableList(children);
140     }
141 
142 }