View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kew.api.document.attribute;
17  
18  import org.joda.time.DateTime;
19  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
27  
28  /**
29   * A document attribute which contains date/time data.  Construct instances of {@code DocumentAttributeDateTime} using
30   * it's builder or the {@link DocumentAttributeFactory}.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @XmlRootElement(name = DocumentAttributeDateTime.Constants.ROOT_ELEMENT_NAME)
35  @XmlAccessorType(XmlAccessType.NONE)
36  @XmlType(name = DocumentAttributeDateTime.Constants.TYPE_NAME, propOrder = {
37      DocumentAttributeDateTime.Elements.VALUE
38  })
39  public final class DocumentAttributeDateTime extends DocumentAttribute {
40  
41      @XmlElement(name = Elements.VALUE, required = false)
42      @XmlJavaTypeAdapter(DateTimeAdapter.class)
43      private final DateTime value;
44  
45      @SuppressWarnings("unused")
46      private DocumentAttributeDateTime() {
47          this.value = null;
48      }
49  
50      private DocumentAttributeDateTime(Builder builder) {
51          super(builder.getName());
52          this.value = builder.getValue();
53      }
54  
55      @Override
56      public DateTime getValue() {
57          return value;
58      }
59  
60      @Override
61      public DocumentAttributeDataType getDataType() {
62          return DocumentAttributeDataType.DATE_TIME;
63      }
64  
65      /**
66       * A builder implementation which allows for construction of a {@code DocumentAttributeDateTime}.
67       */
68      public static final class Builder extends AbstractBuilder<DateTime> {
69  
70          private Builder(String name) {
71              super(name);
72          }
73  
74          /**
75           * Create a builder for the document attribute using the given attribute name.
76           *
77           * @param name the name of the document attribute which should be built by this builder, should never be a
78           * null or blank value
79           * @return a builder instance initialized with the given attribute name
80           */
81          public static Builder create(String name) {
82              return new Builder(name);
83          }
84  
85          @Override
86          public DocumentAttributeDataType getDataType() {
87              return DocumentAttributeDataType.DATE_TIME;
88          }
89  
90          @Override
91          public DocumentAttributeDateTime build() {
92              return new DocumentAttributeDateTime(this);
93          }
94          
95      }
96  
97      /**
98       * Defines some internal constants used on this class.
99       */
100     static class Constants {
101         final static String ROOT_ELEMENT_NAME = "documentAttributeDateTime";
102         final static String TYPE_NAME = "DocumentAttributeDateTimeType";
103     }
104 
105     /**
106      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
107      */
108     static class Elements {
109         final static String VALUE = "value";
110     }
111 
112 }