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 org.joda.time.DateTime;
21  import org.joda.time.format.DateTimeFormat;
22  import org.joda.time.format.DateTimeFormatter;
23  import org.opensaml.ws.wssecurity.AttributedDateTime;
24  import org.opensaml.xml.util.AttributeMap;
25  
26  /**
27   * AbstractDateTimeType.
28   * 
29   */
30  public class AttributedDataTimeImpl extends AbstractWSSecurityObject implements AttributedDateTime {
31  
32      /** DateTime formatter. */
33      private DateTimeFormatter formatter;
34  
35      /** DateTime object. */
36      private DateTime dateTimeValue;
37  
38      /** String dateTime representation. */
39      private String stringValue;
40      
41      /** wsu:id attribute value. */
42      private String id;
43      
44      /** Wildcard attributes. */
45      private AttributeMap unknownAttributes;
46  
47      /**
48       * Constructor.
49       * 
50       * @param namespaceURI namespace of the element
51       * @param elementLocalName name of the element
52       * @param namespacePrefix namespace prefix of the element
53       */
54      public AttributedDataTimeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
55          super(namespaceURI, elementLocalName, namespacePrefix);
56          formatter = DateTimeFormat.forPattern(AttributedDateTime.DEFAULT_DATETIME_FORMAT);
57          unknownAttributes = new AttributeMap(this);
58      }
59  
60      /** {@inheritDoc} */
61      public DateTime getDateTime() {
62          return dateTimeValue;
63      }
64  
65      /** {@inheritDoc} */
66      public void setDateTime(DateTime newDateTime) {
67          dateTimeValue = newDateTime;
68          String formattedDateTime = formatter.print(dateTimeValue);
69          stringValue = prepareForAssignment(stringValue, formattedDateTime);
70      }
71  
72      /** {@inheritDoc} */
73      public String getValue() {
74          return stringValue;
75      }
76  
77      /** {@inheritDoc} */
78      public void setValue(String newValue) {
79          stringValue = prepareForAssignment(stringValue, newValue);
80          dateTimeValue = formatter.parseDateTime(stringValue);
81      }
82  
83      /** {@inheritDoc} */
84      public String getWSUId() {
85          return id;
86      }
87  
88      /** {@inheritDoc} */
89      public void setWSUId(String newId) {
90          String oldID = id;
91          id = prepareForAssignment(id, newId);
92          registerOwnID(oldID, id);
93      }
94  
95      /** {@inheritDoc} */
96      public AttributeMap getUnknownAttributes() {
97          return unknownAttributes;
98      }
99  
100 }