View Javadoc
1   /**
2    * Copyright 2005-2014 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.action;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
21  import org.kuali.rice.core.api.mo.ModelBuilder;
22  import org.kuali.rice.kew.api.actionlist.DisplayParameters;
23  import org.w3c.dom.Element;
24  
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyElement;
28  import javax.xml.bind.annotation.XmlElement;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  import java.io.Serializable;
32  import java.util.Collection;
33  
34  @XmlRootElement(name = ActionItemCustomization.Constants.ROOT_ELEMENT_NAME)
35  @XmlAccessorType(XmlAccessType.NONE)
36  @XmlType(name = ActionItemCustomization.Constants.TYPE_NAME, propOrder = {
37          ActionItemCustomization.Elements.ACTION_ITEM_ID,
38          ActionItemCustomization.Elements.ACTION_SET,
39          ActionItemCustomization.Elements.DISPLAY_PARAMETERS,
40          CoreConstants.CommonElements.FUTURE_ELEMENTS
41  })
42  public class ActionItemCustomization extends AbstractDataTransferObject implements ActionItemCustomizationContract {
43  
44      @XmlElement(name = Elements.ACTION_ITEM_ID, required = false)
45      private final String actionItemId;
46      @XmlElement(name = Elements.ACTION_SET, required = true)
47      private final ActionSet actionSet;
48      @XmlElement(name = Elements.DISPLAY_PARAMETERS, required = true)
49      private final DisplayParameters displayParameters;
50      @SuppressWarnings("unused")
51      @XmlAnyElement
52      private final Collection<Element> _futureElements = null;
53      
54      /**
55       * Private constructor used only by JAXB.
56       * 
57       */
58      private ActionItemCustomization() {
59          this.actionItemId = null;
60          this.actionSet = null;
61          this.displayParameters = null;
62      }
63      
64      private ActionItemCustomization(Builder builder) {
65          this.actionItemId = builder.getActionItemId();
66          this.actionSet = builder.getActionSet();
67          this.displayParameters = builder.getDisplayParameters();
68      }
69  
70      @Override
71      public String getActionItemId() {
72          return this.actionItemId;
73      }
74      
75      @Override
76      public ActionSet getActionSet() {
77          return this.actionSet;
78      }
79  
80      @Override
81      public DisplayParameters getDisplayParameters() {
82          return this.displayParameters;
83      }
84      
85      /**
86       * A builder which can be used to construct {@link ActionItemCustomization} instances.  
87       * Enforces the constraints of the {@link ActionItemCustomizationContract}. 
88       */
89      public final static class Builder
90          implements Serializable, ModelBuilder, ActionItemCustomizationContract
91      {
92          
93          private String actionItemId;
94          private ActionSet actionSet;        
95          private DisplayParameters displayParameters;
96          
97          private Builder(String actionItemId, ActionSet actionSet, DisplayParameters displayParameters) {
98              setActionItemId(actionItemId);
99              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 }