001 /** 002 * Copyright 2005-2012 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.action; 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.AbstractDataTransferObject; 031 import org.kuali.rice.core.api.mo.ModelBuilder; 032 import org.kuali.rice.kew.api.action.ActionItem.Elements; 033 import org.kuali.rice.kew.api.actionlist.DisplayParameters; 034 import org.w3c.dom.Element; 035 036 @XmlRootElement(name = ActionItemCustomization.Constants.ROOT_ELEMENT_NAME) 037 @XmlAccessorType(XmlAccessType.NONE) 038 @XmlType(name = ActionItemCustomization.Constants.TYPE_NAME, propOrder = { 039 ActionItemCustomization.Elements.ID, 040 ActionItemCustomization.Elements.ACTION_SET, 041 ActionItemCustomization.Elements.DISPLAY_PARAMETERS, 042 CoreConstants.CommonElements.FUTURE_ELEMENTS 043 }) 044 public class ActionItemCustomization extends AbstractDataTransferObject implements ActionItemCustomizationContract { 045 046 @XmlElement(name = Elements.ID, required = false) 047 private final String id; 048 @XmlElement(name = Elements.ACTION_SET, required = true) 049 private final ActionSet actionSet; 050 @XmlElement(name = Elements.DISPLAY_PARAMETERS, required = true) 051 private final DisplayParameters displayParameters; 052 @SuppressWarnings("unused") 053 @XmlAnyElement 054 private final Collection<Element> _futureElements = null; 055 056 /** 057 * Private constructor used only by JAXB. 058 * 059 */ 060 private ActionItemCustomization() { 061 this.id = null; 062 this.actionSet = null; 063 this.displayParameters = null; 064 } 065 066 private ActionItemCustomization(Builder builder) { 067 this.id = builder.getId(); 068 this.actionSet = builder.getActionSet(); 069 this.displayParameters = builder.getDisplayParameters(); 070 } 071 072 @Override 073 public String getId() { 074 return this.id; 075 } 076 077 @Override 078 public ActionSet getActionSet() { 079 return this.actionSet; 080 } 081 082 @Override 083 public DisplayParameters getDisplayParameters() { 084 return this.displayParameters; 085 } 086 087 /** 088 * A builder which can be used to construct {@link ActionItemCustomization} instances. 089 * Enforces the constraints of the {@link ActionItemCustomizationContract}. 090 */ 091 public final static class Builder 092 implements Serializable, ModelBuilder, ActionItemCustomizationContract 093 { 094 095 private String id; 096 private ActionSet actionSet; 097 private DisplayParameters displayParameters; 098 099 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 }