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.AgreementMethod;
27  import org.opensaml.xml.encryption.KANonce;
28  import org.opensaml.xml.encryption.OriginatorKeyInfo;
29  import org.opensaml.xml.encryption.RecipientKeyInfo;
30  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
31  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
32  
33  /**
34   * Concrete implementation of {@link org.opensaml.xml.encryption.AgreementMethod}.
35   */
36  public class AgreementMethodImpl extends AbstractValidatingXMLObject implements AgreementMethod {
37      
38      /** Algorithm attribute value. */
39      private String algorithm;
40      
41      /** KA-Nonce child element value. */
42      private KANonce kaNonce;
43      
44      /** OriginatorKeyInfo child element value. */
45      private OriginatorKeyInfo originatorKeyInfo;
46      
47      /** RecipientKeyInfo child element value. */
48      private RecipientKeyInfo recipientKeyInfo;
49      
50      /** List of wildcard <any> XMLObject children. */
51      private IndexedXMLObjectChildrenList xmlChildren;
52  
53      /**
54       * Constructor.
55       *
56       * @param namespaceURI namespace URI
57       * @param elementLocalName element local name
58       * @param namespacePrefix namespace prefix
59       */
60      protected AgreementMethodImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
61          super(namespaceURI, elementLocalName, namespacePrefix);
62          xmlChildren = new IndexedXMLObjectChildrenList(this);
63      }
64  
65      /** {@inheritDoc} */
66      public String getAlgorithm() {
67          return this.algorithm;
68      }
69  
70      /** {@inheritDoc} */
71      public void setAlgorithm(String newAlgorithm) {
72          this.algorithm = prepareForAssignment(this.algorithm, newAlgorithm);
73      }
74  
75      /** {@inheritDoc} */
76      public KANonce getKANonce() {
77          return this.kaNonce;
78      }
79  
80      /** {@inheritDoc} */
81      public void setKANonce(KANonce newKANonce) {
82          this.kaNonce = prepareForAssignment(this.kaNonce, newKANonce);
83      }
84  
85      /** {@inheritDoc} */
86      public OriginatorKeyInfo getOriginatorKeyInfo() {
87          return this.originatorKeyInfo;
88      }
89  
90      /** {@inheritDoc} */
91      public void setOriginatorKeyInfo(OriginatorKeyInfo newOriginatorKeyInfo) {
92          this.originatorKeyInfo = prepareForAssignment(this.originatorKeyInfo, newOriginatorKeyInfo);
93      }
94  
95      /** {@inheritDoc} */
96      public RecipientKeyInfo getRecipientKeyInfo() {
97          return this.recipientKeyInfo;
98      }
99  
100     /** {@inheritDoc} */
101     public void setRecipientKeyInfo(RecipientKeyInfo newRecipientKeyInfo) {
102         this.recipientKeyInfo = prepareForAssignment(this.recipientKeyInfo, newRecipientKeyInfo);
103     }
104 
105     /** {@inheritDoc} */
106     public List<XMLObject> getUnknownXMLObjects() {
107         return (List<XMLObject>) this.xmlChildren;
108     }
109     /** {@inheritDoc} */
110     public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
111         return (List<XMLObject>) this.xmlChildren.subList(typeOrName);
112     }
113 
114     /** {@inheritDoc} */
115     public List<XMLObject> getOrderedChildren() {
116         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
117         
118         if (kaNonce != null) {
119             children.add(kaNonce);
120         }
121         
122         children.addAll(xmlChildren);
123         
124         if (originatorKeyInfo != null) {
125             children.add(originatorKeyInfo);
126         }
127         if (recipientKeyInfo != null) {
128             children.add(recipientKeyInfo);
129         }
130         
131         if (children.size() == 0) {
132             return null;
133         }
134         
135         return Collections.unmodifiableList(children);
136     }
137 
138 }