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 org.opensaml.xml.XMLObject;
24  import org.opensaml.xml.signature.DSAKeyValue;
25  import org.opensaml.xml.signature.KeyValue;
26  import org.opensaml.xml.signature.RSAKeyValue;
27  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
28  
29  /**
30   * Concrete implementation of {@link org.opensaml.xml.signature.KeyValue}
31   */
32  public class KeyValueImpl extends AbstractValidatingXMLObject implements KeyValue {
33      
34      /** DSAKeyValue child element */
35      private DSAKeyValue dsaKeyValue;
36      
37      /** RSAKeyValue child element */
38      private RSAKeyValue rsaKeyValue;
39      
40      /** Wildcard <any> XMLObject child element */
41      private XMLObject unknownXMLObject;
42  
43      /**
44       * Constructor
45       *
46       * @param namespaceURI
47       * @param elementLocalName
48       * @param namespacePrefix
49       */
50      protected KeyValueImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
51          super(namespaceURI, elementLocalName, namespacePrefix);
52      }
53  
54      /** {@inheritDoc} */
55      public DSAKeyValue getDSAKeyValue() {
56          return this.dsaKeyValue;
57      }
58  
59      /** {@inheritDoc} */
60      public void setDSAKeyValue(DSAKeyValue newDSAKeyValue) {
61          this.dsaKeyValue = prepareForAssignment(this.dsaKeyValue, newDSAKeyValue);
62      }
63  
64      /** {@inheritDoc} */
65      public RSAKeyValue getRSAKeyValue() {
66          return this.rsaKeyValue;
67      }
68  
69      /** {@inheritDoc} */
70      public void setRSAKeyValue(RSAKeyValue newRSAKeyValue) {
71          this.rsaKeyValue = prepareForAssignment(this.rsaKeyValue, newRSAKeyValue);
72      }
73  
74      /** {@inheritDoc} */
75      public XMLObject getUnknownXMLObject() {
76          return this.unknownXMLObject;
77      }
78  
79      /** {@inheritDoc} */
80      public void setUnknownXMLObject(XMLObject newXMLObject) {
81          this.unknownXMLObject = prepareForAssignment(this.unknownXMLObject, newXMLObject);
82      }
83  
84      /** {@inheritDoc} */
85      public List<XMLObject> getOrderedChildren() {
86          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
87          
88          if (dsaKeyValue != null) {
89              children.add(dsaKeyValue);
90          }
91          if (rsaKeyValue != null) {
92              children.add(rsaKeyValue);
93          }
94          if (unknownXMLObject != null) {
95              children.add(unknownXMLObject);
96          }
97          
98          if (children.size() == 0) {
99              return null;
100         }
101         
102         return Collections.unmodifiableList(children);
103     }
104 
105 }