View Javadoc

1   /*
2    * Copyright 2008 Members of the EGEE Collaboration.
3    * Copyright 2008 University Corporation for Advanced Internet Development, Inc.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.opensaml.ws.wssecurity.impl;
19  
20  import java.util.ArrayList;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.opensaml.ws.wssecurity.Created;
27  import org.opensaml.ws.wssecurity.Expires;
28  import org.opensaml.ws.wssecurity.IdBearing;
29  import org.opensaml.ws.wssecurity.Timestamp;
30  import org.opensaml.xml.XMLObject;
31  import org.opensaml.xml.util.AttributeMap;
32  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
33  
34  /**
35   * Concrete implementation of {@link org.opensaml.ws.wssecurity.Timestamp}.
36   * 
37   */
38  public class TimestampImpl extends AbstractWSSecurityObject implements Timestamp {
39  
40      /** wsu:Timestamp/@wsu:Id attribute. */
41      private String id;
42  
43      /** wsu:Timestamp/wsu:Created element. */
44      private Created created;
45  
46      /** wsu:Timestamp/wsu:Expires element. */
47      private Expires expires;
48      
49      /** Wildcard attributes. */
50      private AttributeMap unknownAttributes;
51      
52      /** Wildcard child elements. */
53      private IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
54  
55      /**
56       * Constructor.
57       * 
58       * @param namespaceURI namespace of the element
59       * @param elementLocalName name of the element
60       * @param namespacePrefix namespace prefix of the element
61       */
62      public TimestampImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
63          super(namespaceURI, elementLocalName, namespacePrefix);
64          unknownAttributes = new AttributeMap(this);
65          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
66      }
67  
68      /** {@inheritDoc} */
69      public Created getCreated() {
70          return created;
71      }
72  
73      /** {@inheritDoc} */
74      public Expires getExpires() {
75          return expires;
76      }
77  
78      /** {@inheritDoc} */
79      public void setCreated(Created newCreated) {
80          created = prepareForAssignment(created, newCreated);
81      }
82  
83      /** {@inheritDoc} */
84      public void setExpires(Expires newExpires) {
85          expires = prepareForAssignment(expires, newExpires);
86      }
87   
88      /** {@inheritDoc} */
89      public String getWSUId() {
90          return id;
91      }
92  
93      /** {@inheritDoc} */
94      public void setWSUId(String newId) {
95          String oldId = id;
96          id = prepareForAssignment(id, newId);
97          registerOwnID(oldId, id);
98          manageQualifiedAttributeNamespace(IdBearing.WSU_ID_ATTR_NAME, id != null);
99      }
100 
101     /** {@inheritDoc} */
102     public AttributeMap getUnknownAttributes() {
103         return unknownAttributes;
104     }
105 
106     /** {@inheritDoc} */
107     public List<XMLObject> getUnknownXMLObjects() {
108         return unknownChildren;
109     }
110 
111     /** {@inheritDoc} */
112     public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
113         return (List<XMLObject>) unknownChildren.subList(typeOrName);
114     }
115     
116     /** {@inheritDoc} */
117     public List<XMLObject> getOrderedChildren() {
118         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
119         if (created != null) {
120             children.add(created);
121         }
122         if (expires != null) {
123             children.add(expires);
124         }
125         if (!getUnknownXMLObjects().isEmpty()) {
126             children.addAll(getUnknownXMLObjects());
127         }
128 
129         return Collections.unmodifiableList(children);
130     }
131 
132 }