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 org.opensaml.xml.XMLObject;
24  import org.opensaml.xml.encryption.CipherData;
25  import org.opensaml.xml.encryption.CipherReference;
26  import org.opensaml.xml.encryption.CipherValue;
27  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
28  
29  /**
30   * Concrete implementation of {@link org.opensaml.xml.encryption.CipherData}.
31   */
32  public class CipherDataImpl extends AbstractValidatingXMLObject implements CipherData {
33      
34      /** CipherValue child element. */
35      private CipherValue cipherValue;
36      
37      /** CipherReference child element. */
38      private CipherReference cipherReference;
39  
40      /**
41       * Constructor.
42       *
43       * @param namespaceURI namespace URI
44       * @param elementLocalName local name
45       * @param namespacePrefix namespace prefix
46       */
47      protected  CipherDataImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
48          super(namespaceURI, elementLocalName, namespacePrefix);
49      }
50  
51      /** {@inheritDoc} */
52      public CipherValue getCipherValue() {
53          return this.cipherValue;
54      }
55  
56      /** {@inheritDoc} */
57      public void setCipherValue(CipherValue newCipherValue) {
58          this.cipherValue = prepareForAssignment(this.cipherValue, newCipherValue);
59      }
60  
61      /** {@inheritDoc} */
62      public CipherReference getCipherReference() {
63          return this.cipherReference;
64      }
65  
66      /** {@inheritDoc} */
67      public void setCipherReference(CipherReference newCipherReference) {
68          this.cipherReference = prepareForAssignment(this.cipherReference, newCipherReference);
69      }
70  
71      /** {@inheritDoc} */
72      public List<XMLObject> getOrderedChildren() {
73          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
74          
75          if (cipherValue != null) {
76              children.add(cipherValue);
77          }
78          if (cipherReference != null) {
79              children.add(cipherReference);
80          }
81          
82          if (children.size() == 0) {
83              return null;
84          }
85          
86          return Collections.unmodifiableList(children);
87      }
88  
89  }