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 javax.xml.namespace.QName;
24  
25  import org.opensaml.xml.XMLObject;
26  import org.opensaml.xml.signature.PGPData;
27  import org.opensaml.xml.signature.PGPKeyID;
28  import org.opensaml.xml.signature.PGPKeyPacket;
29  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
30  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
31  
32  /**
33   * Concrete implementation of {@link org.opensaml.xml.signature.PGPData}
34   */
35  public class PGPDataImpl extends AbstractValidatingXMLObject implements PGPData {
36      
37      /** PGPKeyID child element value */
38      private PGPKeyID pgpKeyID;
39      
40      /** PGPKeyPacket child element value */
41      private PGPKeyPacket pgpKeyPacket;
42      
43      /** List of <any> wildcard XMLObject children */
44      private final IndexedXMLObjectChildrenList xmlChildren;
45  
46      /**
47       * Constructor
48       *
49       * @param namespaceURI
50       * @param elementLocalName
51       * @param namespacePrefix
52       */
53      protected PGPDataImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
54          super(namespaceURI, elementLocalName, namespacePrefix);
55          xmlChildren = new IndexedXMLObjectChildrenList(this);
56      }
57  
58      /** {@inheritDoc} */
59      public PGPKeyID getPGPKeyID() {
60          return this.pgpKeyID;
61      }
62  
63      /** {@inheritDoc} */
64      public void setPGPKeyID(PGPKeyID newPGPKeyID) {
65          this.pgpKeyID = prepareForAssignment(this.pgpKeyID, newPGPKeyID);
66      }
67  
68      /** {@inheritDoc} */
69      public PGPKeyPacket getPGPKeyPacket() {
70          return this.pgpKeyPacket;
71      }
72  
73      /** {@inheritDoc} */
74      public void setPGPKeyPacket(PGPKeyPacket newPGPKeyPacket) {
75          this.pgpKeyPacket = prepareForAssignment(this.pgpKeyPacket, newPGPKeyPacket);
76      }
77  
78      /** {@inheritDoc} */
79      public List<XMLObject> getUnknownXMLObjects() {
80          return (List<XMLObject>) xmlChildren;
81      }
82      /** {@inheritDoc} */
83      public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
84          return (List<XMLObject>) xmlChildren.subList(typeOrName);
85      }
86  
87      /** {@inheritDoc} */
88      public List<XMLObject> getOrderedChildren() {
89          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
90          
91          if (pgpKeyID != null) {
92              children.add(pgpKeyID);
93          }
94          if (pgpKeyPacket != null) {
95              children.add(pgpKeyPacket);
96          }
97          children.addAll((List<XMLObject>) xmlChildren);
98          
99          if (children.size() == 0) {
100             return null;
101         }
102         
103         return Collections.unmodifiableList(children);
104     }
105 
106 }