001    /**
002     * Copyright 2005-2013 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     */
016    package org.kuali.rice.kew.api.document;
017    
018    import java.util.Collection;
019    
020    import javax.xml.bind.annotation.XmlAccessType;
021    import javax.xml.bind.annotation.XmlAccessorType;
022    import javax.xml.bind.annotation.XmlAnyElement;
023    import javax.xml.bind.annotation.XmlElement;
024    import javax.xml.bind.annotation.XmlRootElement;
025    import javax.xml.bind.annotation.XmlType;
026    
027    import org.apache.commons.lang.StringUtils;
028    import org.kuali.rice.core.api.CoreConstants;
029    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
030    import org.w3c.dom.Element;
031    
032    @XmlRootElement(name = PropertyDefinition.Constants.ROOT_ELEMENT_NAME)
033    @XmlAccessorType(XmlAccessType.NONE)
034    @XmlType(name = PropertyDefinition.Constants.TYPE_NAME, propOrder = {
035            PropertyDefinition.Elements.NAME,
036            PropertyDefinition.Elements.VALUE,
037            CoreConstants.CommonElements.FUTURE_ELEMENTS
038    })
039    public final class PropertyDefinition extends AbstractDataTransferObject {
040    
041        @XmlElement(name = Elements.NAME, required = true)
042        private final String name;
043    
044        @XmlElement(name = Elements.VALUE, required = false)
045        private final String value;
046    
047        @SuppressWarnings("unused")
048        @XmlAnyElement
049        private final Collection<Element> _futureElements = null;
050    
051        @SuppressWarnings("unused")
052        private PropertyDefinition() {
053            this.name = null;
054            this.value = null;
055        }
056    
057        public static PropertyDefinition create(String name, String value) {
058            return new PropertyDefinition(name, value);
059        }
060    
061        private PropertyDefinition(String name, String value) {
062            if (StringUtils.isBlank(name)) {
063                throw new IllegalArgumentException("name is null or blank");
064            }
065            this.name = name;
066            this.value = value;
067        }
068    
069        public String getName() {
070            return name;
071        }
072    
073        public String getValue() {
074            return value;
075        }
076    
077        /**
078         * Defines some internal constants used on this class.
079         */
080        static class Constants {
081            final static String ROOT_ELEMENT_NAME = "propertyDefinition";
082            final static String TYPE_NAME = "PropertyDefinitionType";
083        }
084    
085        /**
086         * A private class which exposes constants which define the XML element names to use when this
087         * object is marshalled to XML.
088         */
089        static class Elements {
090            final static String NAME = "name";
091            final static String VALUE = "value";
092        }
093    
094    }