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.extension; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.core.api.CoreConstants; 020 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 021 import org.kuali.rice.core.api.mo.ModelBuilder; 022 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; 023 import org.w3c.dom.Element; 024 025 import javax.xml.bind.annotation.XmlAccessType; 026 import javax.xml.bind.annotation.XmlAccessorType; 027 import javax.xml.bind.annotation.XmlAnyElement; 028 import javax.xml.bind.annotation.XmlElement; 029 import javax.xml.bind.annotation.XmlRootElement; 030 import javax.xml.bind.annotation.XmlType; 031 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 032 import java.io.Serializable; 033 import java.util.Collection; 034 import java.util.Collections; 035 import java.util.HashMap; 036 import java.util.Map; 037 038 /** 039 * Immutable implementation of the {@link ExtensionDefinitionContract}. Defines an extension to some component of 040 * Kuali Enterprise Workflow. 041 * 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 */ 044 @XmlRootElement(name = ExtensionDefinition.Constants.ROOT_ELEMENT_NAME) 045 @XmlAccessorType(XmlAccessType.NONE) 046 @XmlType(name = ExtensionDefinition.Constants.TYPE_NAME, propOrder = { 047 ExtensionDefinition.Elements.ID, 048 ExtensionDefinition.Elements.NAME, 049 ExtensionDefinition.Elements.APPLICATION_ID, 050 ExtensionDefinition.Elements.LABEL, 051 ExtensionDefinition.Elements.DESCRIPTION, 052 ExtensionDefinition.Elements.TYPE, 053 ExtensionDefinition.Elements.RESOURCE_DESCRIPTOR, 054 ExtensionDefinition.Elements.CONFIGURATION, 055 CoreConstants.CommonElements.VERSION_NUMBER, 056 CoreConstants.CommonElements.FUTURE_ELEMENTS 057 }) 058 public final class ExtensionDefinition extends AbstractDataTransferObject implements ExtensionDefinitionContract { 059 060 private static final long serialVersionUID = 6234968409006917945L; 061 062 @XmlElement(name = Elements.ID, required = false) 063 private final String id; 064 065 @XmlElement(name = Elements.NAME, required = true) 066 private final String name; 067 068 @XmlElement(name = Elements.APPLICATION_ID, required = false) 069 private final String applicationId; 070 071 @XmlElement(name = Elements.LABEL, required = false) 072 private final String label; 073 074 @XmlElement(name = Elements.DESCRIPTION, required = false) 075 private final String description; 076 077 @XmlElement(name = Elements.TYPE, required = true) 078 private final String type; 079 080 @XmlElement(name = Elements.RESOURCE_DESCRIPTOR, required = true) 081 private final String resourceDescriptor; 082 083 @XmlElement(name = Elements.CONFIGURATION, required = false) 084 @XmlJavaTypeAdapter(MapStringStringAdapter.class) 085 private final Map<String, String> configuration; 086 087 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 088 private final Long versionNumber; 089 090 @SuppressWarnings("unused") 091 @XmlAnyElement 092 private final Collection<Element> _futureElements = null; 093 094 /** 095 * Private constructor used only by JAXB. 096 */ 097 @SuppressWarnings("unused") 098 private ExtensionDefinition() { 099 this.id = null; 100 this.name = null; 101 this.applicationId = null; 102 this.label = null; 103 this.description = null; 104 this.type = null; 105 this.resourceDescriptor = null; 106 this.configuration = null; 107 this.versionNumber = null; 108 } 109 110 private ExtensionDefinition(Builder builder) { 111 this.id = builder.getId(); 112 this.name = builder.getName(); 113 this.applicationId = builder.getApplicationId(); 114 this.label = builder.getLabel(); 115 this.description = builder.getDescription(); 116 this.type = builder.getType(); 117 this.resourceDescriptor = builder.getResourceDescriptor(); 118 if (builder.getConfiguration() == null) { 119 this.configuration = Collections.emptyMap(); 120 } else { 121 this.configuration = Collections.unmodifiableMap(new HashMap<String, String>(builder.getConfiguration())); 122 } 123 this.versionNumber = builder.getVersionNumber(); 124 } 125 126 @Override 127 public String getId() { 128 return this.id; 129 } 130 131 @Override 132 public String getName() { 133 return this.name; 134 } 135 136 @Override 137 public String getApplicationId() { 138 return this.applicationId; 139 } 140 141 @Override 142 public String getLabel() { 143 return this.label; 144 } 145 146 @Override 147 public String getDescription() { 148 return this.description; 149 } 150 151 @Override 152 public String getType() { 153 return this.type; 154 } 155 156 @Override 157 public String getResourceDescriptor() { 158 return this.resourceDescriptor; 159 } 160 161 @Override 162 public Map<String, String> getConfiguration() { 163 return this.configuration; 164 } 165 166 @Override 167 public Long getVersionNumber() { 168 return this.versionNumber; 169 } 170 171 /** 172 * A builder which can be used to construct {@link ExtensionDefinition} instances. Enforces the constraints of the 173 * {@link ExtensionDefinitionContract}. 174 */ 175 public final static class Builder implements Serializable, ModelBuilder, ExtensionDefinitionContract { 176 177 private String id; 178 private String name; 179 private String applicationId; 180 private String label; 181 private String description; 182 private String type; 183 private String resourceDescriptor; 184 private Map<String, String> configuration; 185 private Long versionNumber; 186 187 private Builder(String name, String type, String resourceDescriptor) { 188 setName(name); 189 setType(type); 190 setResourceDescriptor(resourceDescriptor); 191 setConfiguration(new HashMap<String, String>()); 192 } 193 194 public static Builder create(String name, String type, String resourceDescriptor) { 195 return new Builder(name, type, resourceDescriptor); 196 } 197 198 public static Builder create(ExtensionDefinitionContract contract) { 199 if (contract == null) { 200 throw new IllegalArgumentException("contract was null"); 201 } 202 Builder builder = create(contract.getName(), contract.getType(), contract.getResourceDescriptor()); 203 builder.setId(contract.getId()); 204 builder.setApplicationId(contract.getApplicationId()); 205 builder.setLabel(contract.getLabel()); 206 builder.setDescription(contract.getDescription()); 207 builder.setConfiguration(contract.getConfiguration()); 208 builder.setVersionNumber(contract.getVersionNumber()); 209 return builder; 210 } 211 212 public ExtensionDefinition build() { 213 return new ExtensionDefinition(this); 214 } 215 216 @Override 217 public String getId() { 218 return this.id; 219 } 220 221 @Override 222 public String getName() { 223 return this.name; 224 } 225 226 @Override 227 public String getApplicationId() { 228 return this.applicationId; 229 } 230 231 @Override 232 public String getLabel() { 233 return this.label; 234 } 235 236 @Override 237 public String getDescription() { 238 return this.description; 239 } 240 241 @Override 242 public String getType() { 243 return this.type; 244 } 245 246 @Override 247 public String getResourceDescriptor() { 248 return this.resourceDescriptor; 249 } 250 251 @Override 252 public Map<String, String> getConfiguration() { 253 return this.configuration; 254 } 255 256 @Override 257 public Long getVersionNumber() { 258 return this.versionNumber; 259 } 260 261 public void setId(String id) { 262 this.id = id; 263 } 264 265 public void setName(String name) { 266 if (StringUtils.isBlank(name)) { 267 throw new IllegalArgumentException("name was null or blank"); 268 } 269 this.name = name; 270 } 271 272 public void setApplicationId(String applicationId) { 273 this.applicationId = applicationId; 274 } 275 276 public void setLabel(String label) { 277 this.label = label; 278 } 279 280 public void setDescription(String description) { 281 this.description = description; 282 } 283 284 public void setType(String type) { 285 if (StringUtils.isBlank(type)) { 286 throw new IllegalArgumentException("type was null or blank"); 287 } 288 289 this.type = type; 290 } 291 292 public void setResourceDescriptor(String resourceDescriptor) { 293 if (StringUtils.isBlank(resourceDescriptor)) { 294 throw new IllegalArgumentException("descriptor was null or blank"); 295 } 296 this.resourceDescriptor = resourceDescriptor; 297 } 298 299 public void setConfiguration(Map<String, String> configuration) { 300 this.configuration = configuration; 301 } 302 303 public void setVersionNumber(Long versionNumber) { 304 this.versionNumber = versionNumber; 305 } 306 307 } 308 309 /** 310 * Defines some internal constants used on this class. 311 */ 312 static class Constants { 313 final static String ROOT_ELEMENT_NAME = "extensionDefinition"; 314 final static String TYPE_NAME = "ExtensionDefinitionType"; 315 } 316 317 /** 318 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 319 */ 320 static class Elements { 321 final static String ID = "id"; 322 final static String NAME = "name"; 323 final static String APPLICATION_ID = "applicationId"; 324 final static String LABEL = "label"; 325 final static String DESCRIPTION = "description"; 326 final static String TYPE = "type"; 327 final static String RESOURCE_DESCRIPTOR = "resourceDescriptor"; 328 final static String CONFIGURATION = "configuration"; 329 } 330 331 }