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.EncryptedType;
26  import org.opensaml.xml.encryption.EncryptionMethod;
27  import org.opensaml.xml.encryption.EncryptionProperties;
28  import org.opensaml.xml.signature.KeyInfo;
29  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
30  
31  /**
32   * Abstract implementation of {@link org.opensaml.xml.encryption.EncryptedType}.
33   */
34  public abstract class EncryptedTypeImpl extends AbstractValidatingXMLObject implements EncryptedType {
35      
36      /** id attribute value. */
37      private String id;
38      
39      /** Type attribute value. */
40      private String type;
41      
42      /** MimeType attribute value. */
43      private String mimeType;
44      
45      /** Encoding attribute value. */
46      private String encoding;
47      
48      /** EncryptionMethod child element. */
49      private EncryptionMethod encryptionMethod;
50      
51      /** EncryptionMethod child element. */
52      private KeyInfo keyInfo;
53      
54      /** CipherData child element. */
55      private CipherData cipherData;
56      
57      /** EncryptionProperties child element. */
58      private EncryptionProperties encryptionProperties;
59      
60      /**
61       * Constructor
62       * 
63       * @param namespaceURI
64       * @param elementLocalName
65       * @param namespacePrefix
66       */
67      protected EncryptedTypeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
68          super(namespaceURI, elementLocalName, namespacePrefix);
69      }
70      
71      /** {@inheritDoc} */
72      public String getID() {
73          return this.id;
74      }
75      
76      /** {@inheritDoc} */
77      public void setID(String newID) {
78          String oldID = this.id;
79          this.id = prepareForAssignment(this.id, newID);
80          registerOwnID(oldID, this.id);
81      }
82      
83      /** {@inheritDoc} */
84      public String getType() {
85          return this.type;
86      }
87      
88      /** {@inheritDoc} */
89      public void setType(String newType) {
90          this.type = prepareForAssignment(this.type, newType);
91      }
92      
93      /** {@inheritDoc} */
94      public String getMimeType() {
95          return this.mimeType;
96      }
97      
98      /** {@inheritDoc} */
99      public void setMimeType(String newMimeType) {
100         this.mimeType = prepareForAssignment(this.mimeType, newMimeType);
101     }
102     
103     /** {@inheritDoc} */
104     public String getEncoding() {
105         return this.encoding;
106     }
107     
108     /** {@inheritDoc} */
109     public void setEncoding(String newEncoding) {
110         this.encoding = prepareForAssignment(this.encoding, newEncoding);
111     }
112 
113     /** {@inheritDoc} */
114     public EncryptionMethod getEncryptionMethod() {
115         return this.encryptionMethod;
116     }
117 
118     /** {@inheritDoc} */
119     public void setEncryptionMethod(EncryptionMethod newEncryptionMethod) {
120         this.encryptionMethod = prepareForAssignment(this.encryptionMethod, newEncryptionMethod);
121     }
122 
123     /** {@inheritDoc} */
124     public KeyInfo getKeyInfo() {
125         return this.keyInfo;
126     }
127 
128     /** {@inheritDoc} */
129     public void setKeyInfo(KeyInfo newKeyInfo) {
130         this.keyInfo = prepareForAssignment(this.keyInfo, newKeyInfo);
131     }
132 
133     /** {@inheritDoc} */
134     public CipherData getCipherData() {
135         return this.cipherData;
136     }
137 
138     /** {@inheritDoc} */
139     public void setCipherData(CipherData newCipherData) {
140         this.cipherData = prepareForAssignment(this.cipherData, newCipherData);
141     }
142 
143     /** {@inheritDoc} */
144     public EncryptionProperties getEncryptionProperties() {
145         return this.encryptionProperties;
146     }
147 
148     /** {@inheritDoc} */
149     public void setEncryptionProperties(EncryptionProperties newEncryptionProperties) {
150         this.encryptionProperties = prepareForAssignment(this.encryptionProperties, newEncryptionProperties);
151     }
152 
153     /** {@inheritDoc} */
154     public List<XMLObject> getOrderedChildren() {
155         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
156         
157         if (encryptionMethod != null) {
158             children.add(encryptionMethod);
159         }
160         if (keyInfo != null) {
161             children.add(keyInfo);
162         }
163         if (cipherData != null) {
164             children.add(cipherData);
165         }
166         if (encryptionProperties!= null) {
167             children.add(encryptionProperties);
168         }
169         
170         if (children.size() == 0) {
171            return null;
172         }
173         
174         return Collections.unmodifiableList(children);
175     }
176 
177 }