001/**
002 * Copyright 2005-2014 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 javax.xml.bind.annotation.XmlAccessType;
019import javax.xml.bind.annotation.XmlAccessorType;
020import javax.xml.bind.annotation.XmlElement;
021import javax.xml.bind.annotation.XmlRootElement;
022import javax.xml.bind.annotation.XmlType;
023import java.math.BigDecimal;
024
025/**
026 * A document attribute which contains decimal or "real" data.  Construct instances of {@code DocumentAttributeDecimal}
027 * using it's builder or the {@link DocumentAttributeFactory}.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031@XmlRootElement(name = DocumentAttributeDecimal.Constants.ROOT_ELEMENT_NAME)
032@XmlAccessorType(XmlAccessType.NONE)
033@XmlType(name = DocumentAttributeDecimal.Constants.TYPE_NAME, propOrder = {
034    DocumentAttributeDecimal.Elements.VALUE
035})
036public final class DocumentAttributeDecimal extends DocumentAttribute {
037
038    @XmlElement(name = Elements.VALUE, required = false)
039    private final BigDecimal value;
040
041    @SuppressWarnings("unused")
042    private DocumentAttributeDecimal() {
043        this.value = null;
044    }
045
046    private DocumentAttributeDecimal(Builder builder) {
047        super(builder.getName());
048        this.value = builder.getValue();
049    }
050
051    @Override
052    public BigDecimal getValue() {
053        return value;
054    }
055
056    @Override
057    public DocumentAttributeDataType getDataType() {
058        return DocumentAttributeDataType.DECIMAL;
059    }
060
061    /**
062     * A builder implementation which allows for construction of a {@code DocumentAttributeDecimal}.
063     */
064    public static final class Builder extends AbstractBuilder<BigDecimal> {
065
066        /**
067         * Create a builder for the document attribute using the given attribute name.
068         *
069         * @param name the name of the document attribute which should be built by this builder, should never be a
070         * null or blank value
071         * @return a builder instance initialized with the given attribute name
072         */
073        private Builder(String name) {
074            super(name);
075        }
076
077        public static Builder create(String name) {
078            return new Builder(name);
079        }
080
081        @Override
082        public DocumentAttributeDataType getDataType() {
083            return DocumentAttributeDataType.DECIMAL;
084        }
085
086        @Override
087        public DocumentAttributeDecimal build() {
088            return new DocumentAttributeDecimal(this);
089        }
090
091    }
092
093
094    /**
095     * Defines some internal constants used on this class.
096     */
097    static class Constants {
098        final static String ROOT_ELEMENT_NAME = "documentAttributeDecimal";
099        final static String TYPE_NAME = "DocumentAttributeDecimalType";
100    }
101
102    /**
103     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
104     */
105    static class Elements {
106        final static String VALUE = "value";
107    }
108
109}