001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.api.document.attribute;
017
018import org.joda.time.DateTime;
019import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.XmlRootElement;
025import javax.xml.bind.annotation.XmlType;
026import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027
028/**
029 * A document attribute which contains date/time data.  Construct instances of {@code DocumentAttributeDateTime} using
030 * it's builder or the {@link DocumentAttributeFactory}.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034@XmlRootElement(name = DocumentAttributeDateTime.Constants.ROOT_ELEMENT_NAME)
035@XmlAccessorType(XmlAccessType.NONE)
036@XmlType(name = DocumentAttributeDateTime.Constants.TYPE_NAME, propOrder = {
037    DocumentAttributeDateTime.Elements.VALUE
038})
039public final class DocumentAttributeDateTime extends DocumentAttribute {
040
041    @XmlElement(name = Elements.VALUE, required = false)
042    @XmlJavaTypeAdapter(DateTimeAdapter.class)
043    private final DateTime value;
044
045    @SuppressWarnings("unused")
046    private DocumentAttributeDateTime() {
047        this.value = null;
048    }
049
050    private DocumentAttributeDateTime(Builder builder) {
051        super(builder.getName());
052        this.value = builder.getValue();
053    }
054
055    @Override
056    public DateTime getValue() {
057        return value;
058    }
059
060    @Override
061    public DocumentAttributeDataType getDataType() {
062        return DocumentAttributeDataType.DATE_TIME;
063    }
064
065    /**
066     * A builder implementation which allows for construction of a {@code DocumentAttributeDateTime}.
067     */
068    public static final class Builder extends AbstractBuilder<DateTime> {
069
070        private Builder(String name) {
071            super(name);
072        }
073
074        /**
075         * Create a builder for the document attribute using the given attribute name.
076         *
077         * @param name the name of the document attribute which should be built by this builder, should never be a
078         * null or blank value
079         * @return a builder instance initialized with the given attribute name
080         */
081        public static Builder create(String name) {
082            return new Builder(name);
083        }
084
085        @Override
086        public DocumentAttributeDataType getDataType() {
087            return DocumentAttributeDataType.DATE_TIME;
088        }
089
090        @Override
091        public DocumentAttributeDateTime build() {
092            return new DocumentAttributeDateTime(this);
093        }
094        
095    }
096
097    /**
098     * Defines some internal constants used on this class.
099     */
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}