001/**
002 * Copyright 2005-2016 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.action;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022import org.kuali.rice.kew.api.actionlist.DisplayParameters;
023import org.w3c.dom.Element;
024
025import javax.xml.bind.annotation.XmlAccessType;
026import javax.xml.bind.annotation.XmlAccessorType;
027import javax.xml.bind.annotation.XmlAnyElement;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlRootElement;
030import javax.xml.bind.annotation.XmlType;
031import java.io.Serializable;
032import java.util.Collection;
033
034@XmlRootElement(name = ActionItemCustomization.Constants.ROOT_ELEMENT_NAME)
035@XmlAccessorType(XmlAccessType.NONE)
036@XmlType(name = ActionItemCustomization.Constants.TYPE_NAME, propOrder = {
037        ActionItemCustomization.Elements.ACTION_ITEM_ID,
038        ActionItemCustomization.Elements.ACTION_SET,
039        ActionItemCustomization.Elements.DISPLAY_PARAMETERS,
040        CoreConstants.CommonElements.FUTURE_ELEMENTS
041})
042public class ActionItemCustomization extends AbstractDataTransferObject implements ActionItemCustomizationContract {
043
044    @XmlElement(name = Elements.ACTION_ITEM_ID, required = false)
045    private final String actionItemId;
046    @XmlElement(name = Elements.ACTION_SET, required = true)
047    private final ActionSet actionSet;
048    @XmlElement(name = Elements.DISPLAY_PARAMETERS, required = true)
049    private final DisplayParameters displayParameters;
050    @SuppressWarnings("unused")
051    @XmlAnyElement
052    private final Collection<Element> _futureElements = null;
053    
054    /**
055     * Private constructor used only by JAXB.
056     * 
057     */
058    private ActionItemCustomization() {
059        this.actionItemId = null;
060        this.actionSet = null;
061        this.displayParameters = null;
062    }
063    
064    private ActionItemCustomization(Builder builder) {
065        this.actionItemId = builder.getActionItemId();
066        this.actionSet = builder.getActionSet();
067        this.displayParameters = builder.getDisplayParameters();
068    }
069
070    @Override
071    public String getActionItemId() {
072        return this.actionItemId;
073    }
074    
075    @Override
076    public ActionSet getActionSet() {
077        return this.actionSet;
078    }
079
080    @Override
081    public DisplayParameters getDisplayParameters() {
082        return this.displayParameters;
083    }
084    
085    /**
086     * A builder which can be used to construct {@link ActionItemCustomization} instances.  
087     * Enforces the constraints of the {@link ActionItemCustomizationContract}. 
088     */
089    public final static class Builder
090        implements Serializable, ModelBuilder, ActionItemCustomizationContract
091    {
092        
093        private String actionItemId;
094        private ActionSet actionSet;        
095        private DisplayParameters displayParameters;
096        
097        private Builder(String actionItemId, ActionSet actionSet, DisplayParameters displayParameters) {
098            setActionItemId(actionItemId);
099            setActionSet(actionSet);
100            setDisplayParameters(displayParameters);
101        }
102        
103        public static Builder create(String actionItemId, ActionSet actionSet, DisplayParameters displayParameters) {
104            return new Builder(actionItemId, actionSet, displayParameters);
105        }
106        
107        public static Builder create(ActionItemCustomizationContract contract) {
108            if (contract == null) {
109                throw new IllegalArgumentException("contract is null");
110            }
111            Builder builder = create(contract.getActionItemId(), contract.getActionSet(), contract.getDisplayParameters());
112            builder.setActionItemId(contract.getActionItemId());
113            return builder;
114        }
115                    
116        @Override
117        public ActionItemCustomization build() {
118            return new ActionItemCustomization(this);
119        }
120
121        @Override
122        public ActionSet getActionSet() {
123            return this.actionSet;
124        }
125
126        public DisplayParameters getDisplayParameters() {
127            return this.displayParameters;
128        }
129
130        public String getActionItemId() {
131            return this.actionItemId;
132        }
133        
134        public void setActionItemId(String actionItemId) {
135            if (StringUtils.isBlank(actionItemId)) {
136                throw new IllegalArgumentException("actionItemId is blank");
137            }
138            this.actionItemId = actionItemId;
139        }
140        
141        public void setActionSet(ActionSet actionSet) {
142            if (actionSet == null) {
143                throw new IllegalArgumentException("actionSet is null");
144            }
145            this.actionSet = actionSet;
146        }
147        
148        public void setDisplayParameters(DisplayParameters displayParameters) {
149            this.displayParameters = displayParameters;
150        }
151    }    
152    
153    /**
154     * Defines some internal constants used on this class.
155     * 
156     */
157    static class Constants {
158        final static String ROOT_ELEMENT_NAME = "actionItemCustomization";
159        final static String TYPE_NAME = "ActionItemCustomizationType";
160    }
161
162    /**
163      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
164      * 
165      */
166    static class Elements {
167        final static String ACTION_ITEM_ID = "actionItemId";
168        final static String ACTION_SET = "actionSet";
169        final static String DISPLAY_PARAMETERS = "displayParameters";
170    }
171}