View Javadoc

1   /*
2    * Copyright 2008 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.schema.impl;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.joda.time.DateTime;
23  import org.joda.time.chrono.ISOChronology;
24  import org.joda.time.format.DateTimeFormatter;
25  import org.joda.time.format.ISODateTimeFormat;
26  import org.opensaml.xml.XMLObject;
27  import org.opensaml.xml.schema.XSDateTime;
28  import org.opensaml.xml.validation.AbstractValidatingXMLObject;
29  
30  
31  /**
32   * Concrete implementation of {@link org.opensaml.xml.schema.XSDateTime}.
33   */
34  public class XSDateTimeImpl extends AbstractValidatingXMLObject implements XSDateTime {
35      
36      /** Value of this dateTime element. */
37      private DateTime value;
38      
39      /** The date time formatter to use. */
40      private DateTimeFormatter formatter;
41      
42      /**
43       * Constructor.
44       * 
45       * @param namespaceURI the namespace the element is in
46       * @param elementLocalName the local name of the XML element this Object represents
47       * @param namespacePrefix the prefix for the given namespace
48       */
49      protected XSDateTimeImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
50          super(namespaceURI, elementLocalName, namespacePrefix);
51          formatter = ISODateTimeFormat.dateTime().withChronology(ISOChronology.getInstanceUTC());
52      }
53      
54      /** {@inheritDoc} */
55      public DateTime getValue() {
56          return value;
57      }
58  
59      /** {@inheritDoc} */
60      public void setValue(DateTime newValue) {
61          value = prepareForAssignment(value, newValue);
62      }
63  
64      /** {@inheritDoc} */
65      public List<XMLObject> getOrderedChildren() {
66          return Collections.emptyList();
67      }
68  
69      /** {@inheritDoc} */
70      public DateTimeFormatter getDateTimeFormatter() {
71          return formatter;
72      }
73  
74      /** {@inheritDoc} */
75      public void setDateTimeFormatter(DateTimeFormatter newFormatter) {
76          if (newFormatter == null) {
77              throw new IllegalArgumentException("The specified DateTimeFormatter may not be null");
78          }
79          formatter = newFormatter;
80      }
81  
82  }