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.actionlist; 017 018 import java.io.Serializable; 019 import java.util.Collection; 020 021 import javax.xml.bind.annotation.XmlAccessType; 022 import javax.xml.bind.annotation.XmlAccessorType; 023 import javax.xml.bind.annotation.XmlAnyElement; 024 import javax.xml.bind.annotation.XmlElement; 025 import javax.xml.bind.annotation.XmlRootElement; 026 import javax.xml.bind.annotation.XmlType; 027 028 import org.apache.commons.lang.StringUtils; 029 import org.kuali.rice.core.api.CoreConstants; 030 import org.kuali.rice.core.api.mo.ModelBuilder; 031 import org.kuali.rice.kew.api.repository.type.KewAttributeDefinitionContract; 032 import org.w3c.dom.Element; 033 034 /** 035 * Represents the display params of the inline action list view. This dictates 036 * how the inline frame will look height-wise. 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040 @XmlRootElement(name = DisplayParameters.Constants.ROOT_ELEMENT_NAME) 041 @XmlAccessorType(XmlAccessType.NONE) 042 @XmlType(name = DisplayParameters.Constants.TYPE_NAME, propOrder = { 043 DisplayParameters.Elements.FRAME_HEIGHT, 044 CoreConstants.CommonElements.FUTURE_ELEMENTS 045 }) 046 public final class DisplayParameters implements Serializable, DisplayParametersContract { 047 048 private static final long serialVersionUID = 8859107918934290768L; 049 050 @XmlElement(name = Elements.FRAME_HEIGHT, required = true) 051 private final Integer frameHeight; 052 053 @SuppressWarnings("unused") 054 @XmlAnyElement 055 private final Collection<Element> _futureElements = null; 056 057 /** 058 * Private constructor used only by JAXB. 059 * 060 */ 061 private DisplayParameters(){ 062 this.frameHeight = null; 063 } 064 065 /** 066 * Constructs a DisplayParameters from the given builder. This constructor is private and should only 067 * ever be invoked from the builder. 068 * 069 * @param builder the Builder from which to construct the DisplayParameters 070 */ 071 private DisplayParameters(Builder builder){ 072 this.frameHeight = builder.getFrameHeight(); 073 } 074 075 @Override 076 public Integer getFrameHeight() { 077 return this.frameHeight; 078 } 079 080 /** 081 * A builder which can be used to construct {@link DisplayParameters} instances. Enforces the constraints of the {@link DocumentContentContract}. 082 */ 083 public final static class Builder implements Serializable, ModelBuilder, DisplayParametersContract { 084 085 private static final long serialVersionUID = 2709781019428490297L; 086 087 private Integer frameHeight; 088 089 /** 090 * Private constructor for creating a builder with all of it's required attributes. 091 */ 092 private Builder(Integer frameHeight){ 093 setFrameHeight(frameHeight); 094 } 095 096 public static Builder create(Integer frameHeight){ 097 return new Builder(frameHeight); 098 } 099 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 }