View Javadoc

1   /**
2    * Copyright 2005-2011 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.actionlist;
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.ModelBuilder;
31  import org.kuali.rice.kew.api.repository.type.KewAttributeDefinitionContract;
32  import org.w3c.dom.Element;
33  
34  /**
35   * Represents the display params of the inline action list view.  This dictates 
36   * how the inline frame will look height-wise.
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @XmlRootElement(name = DisplayParameters.Constants.ROOT_ELEMENT_NAME)
41  @XmlAccessorType(XmlAccessType.NONE)
42  @XmlType(name = DisplayParameters.Constants.TYPE_NAME, propOrder = {
43          DisplayParameters.Elements.FRAME_HEIGHT,
44          CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public final class DisplayParameters implements Serializable, DisplayParametersContract {
47  
48  	private static final long serialVersionUID = 8859107918934290768L;
49  	
50  	@XmlElement(name = Elements.FRAME_HEIGHT, required = true)
51  	private final Integer frameHeight;
52  	
53  	@SuppressWarnings("unused")
54      @XmlAnyElement
55      private final Collection<Element> _futureElements = null;
56  	
57  	/**
58       * Private constructor used only by JAXB.
59       * 
60       */
61  	private DisplayParameters(){
62  		this.frameHeight = null;
63  	}
64  	
65  	/**
66       * Constructs a DisplayParameters from the given builder.  This constructor is private and should only
67       * ever be invoked from the builder.
68       * 
69       * @param builder the Builder from which to construct the DisplayParameters
70       */
71  	private DisplayParameters(Builder builder){
72  		this.frameHeight = builder.getFrameHeight();
73  	}
74  	
75  	@Override
76  	public Integer getFrameHeight() {
77  		return this.frameHeight;
78  	}
79  	
80      /**
81       * A builder which can be used to construct {@link DisplayParameters} instances.  Enforces the constraints of the {@link DocumentContentContract}.
82       */
83      public final static class Builder implements Serializable, ModelBuilder, DisplayParametersContract {
84  
85          private static final long serialVersionUID = 2709781019428490297L;
86  
87          private Integer frameHeight;
88          
89          /**
90           * Private constructor for creating a builder with all of it's required attributes.
91           */
92          private Builder(Integer frameHeight){
93          	setFrameHeight(frameHeight);
94          }
95      
96          public static Builder create(Integer frameHeight){
97          	return new Builder(frameHeight);
98          }
99          
100         /**
101          * Creates a builder by populating it with data from the given {@linkDisplayParametersContract}.
102          * 
103          * @param contract the contract from which to populate this builder
104          * @return an instance of the builder populated with data from the contract
105          */
106         public static Builder create(DisplayParametersContract contract){
107         	 if (contract == null) {
108                  throw new IllegalArgumentException("contract was null");
109              }
110              Builder builder = create(contract.getFrameHeight());
111              return builder;
112         }
113         
114         /**
115          * Builds an instance of a DisplayParameters based on the current state of the builder.
116          * 
117          * @return the fully-constructed CampusType
118          */
119         @Override
120         public DisplayParameters build() {
121             return new DisplayParameters(this);
122         }
123         
124         @Override
125         public Integer getFrameHeight() {
126             return this.frameHeight;
127         }
128         
129         public void setFrameHeight(Integer frameHeight){
130             if (frameHeight == null) {
131                 throw new IllegalArgumentException("frameHeight is null");
132             }
133         	this.frameHeight = frameHeight;
134         }
135     }
136     
137     /**
138      * Defines some internal constants used on this class.
139      */
140     static class Constants {
141 
142         final static String ROOT_ELEMENT_NAME = "displayParameters";
143         final static String TYPE_NAME = "DisplayParametersType";
144     }
145     /**
146      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
147      */
148     static class Elements {
149 
150         final static String FRAME_HEIGHT = "frameHeight";
151     }
152 }