View Javadoc

1   /**
2    * Copyright 2005-2012 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 java.io.Serializable;
19  import java.util.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.rice.core.api.CoreConstants;
30  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31  import org.kuali.rice.core.api.mo.ModelBuilder;
32  import org.kuali.rice.kew.api.action.ActionItem.Elements;
33  import org.kuali.rice.kew.api.actionlist.DisplayParameters;
34  import org.w3c.dom.Element;
35  
36  @XmlRootElement(name = ActionItemCustomization.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = ActionItemCustomization.Constants.TYPE_NAME, propOrder = {
39          ActionItemCustomization.Elements.ID,
40          ActionItemCustomization.Elements.ACTION_SET,
41          ActionItemCustomization.Elements.DISPLAY_PARAMETERS,
42          CoreConstants.CommonElements.FUTURE_ELEMENTS
43  })
44  public class ActionItemCustomization extends AbstractDataTransferObject implements ActionItemCustomizationContract {
45  
46      @XmlElement(name = Elements.ID, required = false)
47      private final String id;
48      @XmlElement(name = Elements.ACTION_SET, required = true)
49      private final ActionSet actionSet;
50      @XmlElement(name = Elements.DISPLAY_PARAMETERS, required = true)
51      private final DisplayParameters displayParameters;
52      @SuppressWarnings("unused")
53      @XmlAnyElement
54      private final Collection<Element> _futureElements = null;
55      
56      /**
57       * Private constructor used only by JAXB.
58       * 
59       */
60      private ActionItemCustomization() {
61          this.id = null;
62          this.actionSet = null;
63          this.displayParameters = null;
64      }
65      
66      private ActionItemCustomization(Builder builder) {
67          this.id = builder.getId();
68          this.actionSet = builder.getActionSet();
69          this.displayParameters = builder.getDisplayParameters();
70      }
71  
72      @Override
73      public String getId() {
74          return this.id;
75      }
76      
77      @Override
78      public ActionSet getActionSet() {
79          return this.actionSet;
80      }
81  
82      @Override
83      public DisplayParameters getDisplayParameters() {
84          return this.displayParameters;
85      }
86      
87      /**
88       * A builder which can be used to construct {@link ActionItemCustomization} instances.  
89       * Enforces the constraints of the {@link ActionItemCustomizationContract}. 
90       */
91      public final static class Builder
92          implements Serializable, ModelBuilder, ActionItemCustomizationContract
93      {
94          
95          private String id;        
96          private ActionSet actionSet;        
97          private DisplayParameters displayParameters;
98          
99          private Builder(ActionSet actionSet, DisplayParameters displayParameters) {
100             setActionSet(actionSet);
101             setDisplayParameters(displayParameters);
102         }
103         
104         public static Builder create(ActionSet actionSet, DisplayParameters displayParameters) {
105             return new Builder(actionSet, displayParameters);
106         }
107         
108         public static Builder create(ActionItemCustomizationContract contract) {
109             if (contract == null) {
110                 throw new IllegalArgumentException("contract is null");
111             }
112             Builder builder = create(contract.getActionSet(), contract.getDisplayParameters());
113             builder.setId(contract.getId());
114             return builder;
115         }
116                     
117         @Override
118         public ActionItemCustomization build() {
119             return new ActionItemCustomization(this);
120         }
121 
122         @Override
123         public ActionSet getActionSet() {
124             return this.actionSet;
125         }
126 
127         public DisplayParameters getDisplayParameters() {
128             return this.displayParameters;
129         }
130 
131         public String getId() {
132             return this.id;
133         }
134         
135         public void setId(String id) {
136             if (StringUtils.isWhitespace(id)) {
137                 throw new IllegalArgumentException("id is blank");
138             }
139             this.id = id;
140         }
141         
142         public void setActionSet(ActionSet actionSet) {
143             if (actionSet == null) {
144                 throw new IllegalArgumentException("actionSet is null");
145             }
146             this.actionSet = actionSet;
147         }
148         
149         public void setDisplayParameters(DisplayParameters displayParameters) {
150             if (displayParameters == null) {
151                 throw new IllegalArgumentException("displayParameters is null");
152             }
153             this.displayParameters = displayParameters;
154         }
155     }    
156     
157     /**
158      * Defines some internal constants used on this class.
159      * 
160      */
161     static class Constants {
162         final static String ROOT_ELEMENT_NAME = "actionItemCustomization";
163         final static String TYPE_NAME = "ActionItemCustomizationType";
164     }
165 
166     /**
167       * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
168       * 
169       */
170     static class Elements {
171         final static String ID = "id";
172         final static String ACTION_SET = "actionSet";
173         final static String DISPLAY_PARAMETERS = "displayParameters";
174     }
175 }