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.encryption.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.EncryptionMethod;
27  import org.opensaml.xml.encryption.KeySize;
28  import org.opensaml.xml.encryption.OAEPparams;
29  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
30  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
31  
32  /**
33   * Concrete implementation of {@link org.opensaml.xml.encryption.EncryptionMethod}.
34   */
35  public class EncryptionMethodImpl extends AbstractValidatingXMLObject implements EncryptionMethod {
36      
37      /** Algorithm attribute value. */
38      private String algorithm;
39      
40      /** KeySize child element value. */
41      private KeySize keySize;
42      
43      /** OAEPparams child element value. */
44      private OAEPparams oaepParams;
45      
46      /** "any" children. */
47      private final IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
48      
49      /**
50       * Constructor.
51       *
52       * @param namespaceURI
53       * @param elementLocalName
54       * @param namespacePrefix
55       */
56      protected EncryptionMethodImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
57          super(namespaceURI, elementLocalName, namespacePrefix);
58          
59          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
60      }
61  
62      /** {@inheritDoc} */
63      public String getAlgorithm() {
64          return this.algorithm;
65      }
66  
67      /** {@inheritDoc} */
68      public void setAlgorithm(String newAlgorithm) {
69          this.algorithm = prepareForAssignment(this.algorithm, newAlgorithm);
70      }
71  
72      /** {@inheritDoc} */
73      public KeySize getKeySize() {
74          return this.keySize;
75      }
76  
77      /** {@inheritDoc} */
78      public void setKeySize(KeySize newKeySize) {
79          this.keySize = prepareForAssignment(this.keySize, newKeySize);
80      }
81  
82      /** {@inheritDoc} */
83      public OAEPparams getOAEPparams() {
84          return this.oaepParams;
85      }
86  
87      /** {@inheritDoc} */
88      public void setOAEPparams(OAEPparams newOAEPparams) {
89          this.oaepParams = prepareForAssignment(this.oaepParams, newOAEPparams);
90      }
91  
92      /** {@inheritDoc} */
93      public List<XMLObject> getUnknownXMLObjects() {
94          return this.unknownChildren;
95      }
96      /** {@inheritDoc} */
97      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
98          return (List<XMLObject>) unknownChildren.subList(typeOrName);
99      }
100 
101     /** {@inheritDoc} */
102     public List<XMLObject> getOrderedChildren() {
103         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
104         
105         if (keySize != null) {
106             children.add(keySize);
107         }
108         if (oaepParams != null) {
109             children.add(oaepParams);
110         }
111         
112         children.addAll(unknownChildren);
113         
114         if (children.size() == 0) {
115             return null;
116         }
117         
118         return Collections.unmodifiableList(children);
119     }
120 
121 }