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