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.Timestamp;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.util.AttributeMap;
31  import org.opensaml.xml.util.IndexedXMLObjectChildrenList;
32  
33  /**
34   * Concrete implementation of {@link org.opensaml.ws.wssecurity.Timestamp}.
35   * 
36   */
37  public class TimestampImpl extends AbstractWSSecurityObject implements Timestamp {
38  
39      /** wsu:Timestamp/@wsu:Id attribute. */
40      private String id;
41  
42      /** wsu:Timestamp/wsu:Created element. */
43      private Created created;
44  
45      /** wsu:Timestamp/wsu:Expires element. */
46      private Expires expires;
47      
48      /** Wildcard attributes. */
49      private AttributeMap unknownAttributes;
50      
51      /** Wildcard child elements. */
52      private IndexedXMLObjectChildrenList<XMLObject> unknownChildren;
53  
54      /**
55       * Constructor.
56       * 
57       * @param namespaceURI namespace of the element
58       * @param elementLocalName name of the element
59       * @param namespacePrefix namespace prefix of the element
60       */
61      public TimestampImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
62          super(namespaceURI, elementLocalName, namespacePrefix);
63          unknownAttributes = new AttributeMap(this);
64          unknownChildren = new IndexedXMLObjectChildrenList<XMLObject>(this);
65      }
66  
67      /** {@inheritDoc} */
68      public Created getCreated() {
69          return created;
70      }
71  
72      /** {@inheritDoc} */
73      public Expires getExpires() {
74          return expires;
75      }
76  
77      /** {@inheritDoc} */
78      public void setCreated(Created newCreated) {
79          created = prepareForAssignment(created, newCreated);
80      }
81  
82      /** {@inheritDoc} */
83      public void setExpires(Expires newExpires) {
84          expires = prepareForAssignment(expires, newExpires);
85      }
86   
87      /** {@inheritDoc} */
88      public String getWSUId() {
89          return id;
90      }
91  
92      /** {@inheritDoc} */
93      public void setWSUId(String newId) {
94          String oldId = id;
95          id = prepareForAssignment(id, newId);
96          registerOwnID(oldId, id);
97      }
98  
99      /** {@inheritDoc} */
100     public AttributeMap getUnknownAttributes() {
101         return unknownAttributes;
102     }
103 
104     /** {@inheritDoc} */
105     public List<XMLObject> getUnknownXMLObjects() {
106         return unknownChildren;
107     }
108 
109     /** {@inheritDoc} */
110     public List<XMLObject> getUnknownXMLObjects(QName typeOrName) {
111         return (List<XMLObject>) unknownChildren.subList(typeOrName);
112     }
113     
114     /** {@inheritDoc} */
115     public List<XMLObject> getOrderedChildren() {
116         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
117         if (created != null) {
118             children.add(created);
119         }
120         if (expires != null) {
121             children.add(expires);
122         }
123         if (!getUnknownXMLObjects().isEmpty()) {
124             children.addAll(getUnknownXMLObjects());
125         }
126 
127         return Collections.unmodifiableList(children);
128     }
129 
130 }