| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.core.api.parameter; |
| 18 | |
|
| 19 | |
import java.io.Serializable; |
| 20 | |
import java.util.Collection; |
| 21 | |
|
| 22 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 24 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 25 | |
import javax.xml.bind.annotation.XmlElement; |
| 26 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 27 | |
import javax.xml.bind.annotation.XmlType; |
| 28 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
| 29 | |
|
| 30 | |
import org.apache.commons.lang.StringUtils; |
| 31 | |
import org.kuali.rice.core.api.CoreConstants; |
| 32 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
| 33 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 34 | |
import org.w3c.dom.Element; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 1 | @XmlRootElement(name = Parameter.Constants.ROOT_ELEMENT_NAME) |
| 44 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 45 | |
@XmlType(name = Parameter.Constants.TYPE_NAME, propOrder = { |
| 46 | |
Parameter.Elements.APPLICATION_ID, |
| 47 | |
Parameter.Elements.NAMESPACE_CODE, |
| 48 | |
Parameter.Elements.COMPONENT_CODE, |
| 49 | |
Parameter.Elements.NAME, |
| 50 | |
Parameter.Elements.VALUE, |
| 51 | |
Parameter.Elements.DESCRIPTION, |
| 52 | |
Parameter.Elements.PARAMETER_TYPE, |
| 53 | |
Parameter.Elements.EVALUATION_OPERATOR, |
| 54 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 55 | |
CoreConstants.CommonElements.OBJECT_ID, |
| 56 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 57 | |
}) |
| 58 | 3 | public final class Parameter extends AbstractDataTransferObject implements ParameterContract { |
| 59 | |
|
| 60 | |
private static final long serialVersionUID = 6097498602725305353L; |
| 61 | |
|
| 62 | |
@XmlElement(name = Elements.APPLICATION_ID, required = true) |
| 63 | |
private final String applicationId; |
| 64 | |
|
| 65 | |
@XmlElement(name = Elements.NAMESPACE_CODE, required = true) |
| 66 | |
private final String namespaceCode; |
| 67 | |
|
| 68 | |
@XmlElement(name = Elements.COMPONENT_CODE, required = true) |
| 69 | |
private final String componentCode; |
| 70 | |
|
| 71 | |
@XmlElement(name = Elements.NAME, required = true) |
| 72 | |
private final String name; |
| 73 | |
|
| 74 | |
@XmlElement(name = Elements.VALUE, nillable = true, required = false) |
| 75 | |
private final String value; |
| 76 | |
|
| 77 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
| 78 | |
private final String description; |
| 79 | |
|
| 80 | |
@XmlElement(name = Elements.PARAMETER_TYPE, required = true) |
| 81 | |
private final ParameterType parameterType; |
| 82 | |
|
| 83 | |
@XmlJavaTypeAdapter(EvaluationOperator.Adapter.class) |
| 84 | |
@XmlElement(name = Elements.EVALUATION_OPERATOR, required = false) |
| 85 | |
private final String evaluationOperator; |
| 86 | |
|
| 87 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 88 | |
private final Long versionNumber; |
| 89 | |
|
| 90 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
| 91 | |
private final String objectId; |
| 92 | |
|
| 93 | 5 | @SuppressWarnings("unused") |
| 94 | |
@XmlAnyElement |
| 95 | |
private final Collection<Element> _futureElements = null; |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | 2 | private Parameter() { |
| 101 | 2 | this.applicationId = null; |
| 102 | 2 | this.namespaceCode = null; |
| 103 | 2 | this.componentCode = null; |
| 104 | 2 | this.name = null; |
| 105 | 2 | this.value = null; |
| 106 | 2 | this.description = null; |
| 107 | 2 | this.parameterType = null; |
| 108 | 2 | this.evaluationOperator = null; |
| 109 | 2 | this.versionNumber = null; |
| 110 | 2 | this.objectId = null; |
| 111 | 2 | } |
| 112 | |
|
| 113 | 3 | private Parameter(Builder builder) { |
| 114 | 3 | applicationId = builder.getApplicationId(); |
| 115 | 3 | namespaceCode = builder.getNamespaceCode(); |
| 116 | 3 | componentCode = builder.getComponentCode(); |
| 117 | 3 | name = builder.getName(); |
| 118 | 3 | value = builder.getValue(); |
| 119 | 3 | description = builder.getDescription(); |
| 120 | 3 | parameterType = builder.parameterType.build(); |
| 121 | 3 | EvaluationOperator evaluationOperatorEnum = builder.getEvaluationOperator(); |
| 122 | 3 | evaluationOperator = evaluationOperatorEnum == null ? null : evaluationOperatorEnum.getCode(); |
| 123 | 3 | versionNumber = builder.getVersionNumber(); |
| 124 | 3 | objectId = builder.getObjectId(); |
| 125 | 3 | } |
| 126 | |
|
| 127 | |
@Override |
| 128 | |
public String getApplicationId() { |
| 129 | 1 | return applicationId; |
| 130 | |
} |
| 131 | |
|
| 132 | |
@Override |
| 133 | |
public String getNamespaceCode() { |
| 134 | 1 | return namespaceCode; |
| 135 | |
} |
| 136 | |
|
| 137 | |
@Override |
| 138 | |
public String getComponentCode() { |
| 139 | 1 | return componentCode; |
| 140 | |
} |
| 141 | |
|
| 142 | |
@Override |
| 143 | |
public String getName() { |
| 144 | 1 | return name; |
| 145 | |
} |
| 146 | |
|
| 147 | |
@Override |
| 148 | |
public String getValue() { |
| 149 | 1 | return value; |
| 150 | |
} |
| 151 | |
|
| 152 | |
@Override |
| 153 | |
public String getDescription() { |
| 154 | 1 | return description; |
| 155 | |
} |
| 156 | |
|
| 157 | |
@Override |
| 158 | |
public ParameterType getParameterType() { |
| 159 | 1 | return parameterType; |
| 160 | |
} |
| 161 | |
|
| 162 | |
@Override |
| 163 | |
public EvaluationOperator getEvaluationOperator() { |
| 164 | 1 | return EvaluationOperator.fromCode(evaluationOperator); |
| 165 | |
} |
| 166 | |
|
| 167 | |
@Override |
| 168 | |
public Long getVersionNumber() { |
| 169 | 1 | return versionNumber; |
| 170 | |
} |
| 171 | |
|
| 172 | |
@Override |
| 173 | |
public String getObjectId() { |
| 174 | 1 | return objectId; |
| 175 | |
} |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | 6 | public static final class Builder implements ParameterContract, ModelBuilder, Serializable { |
| 181 | |
|
| 182 | |
private static final long serialVersionUID = 7077484401017765844L; |
| 183 | |
|
| 184 | |
private String applicationId; |
| 185 | |
private String namespaceCode; |
| 186 | |
private String componentCode; |
| 187 | |
private String name; |
| 188 | |
private String value; |
| 189 | |
private String description; |
| 190 | |
private ParameterType.Builder parameterType; |
| 191 | |
private EvaluationOperator evaluationOperator; |
| 192 | |
private Long versionNumber; |
| 193 | |
private String objectId; |
| 194 | |
|
| 195 | 18 | private Builder(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) { |
| 196 | 18 | setApplicationId(applicationId); |
| 197 | 14 | setNamespaceCode(namespaceCode); |
| 198 | 11 | setComponentCode(componentCode); |
| 199 | 8 | setName(name); |
| 200 | 5 | setParameterType(parameterType); |
| 201 | 4 | } |
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
public static Builder create(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) { |
| 207 | 16 | return new Builder(applicationId, namespaceCode, componentCode, name, parameterType); |
| 208 | |
} |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public static Builder create(ParameterContract contract) { |
| 214 | 2 | Builder builder = new Builder(contract.getApplicationId(), contract.getNamespaceCode(), contract.getComponentCode(), contract.getName(), ParameterType.Builder.create(contract.getParameterType())); |
| 215 | 2 | builder.setValue(contract.getValue()); |
| 216 | 2 | builder.setDescription(contract.getDescription()); |
| 217 | 2 | builder.setEvaluationOperator(contract.getEvaluationOperator()); |
| 218 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
| 219 | 2 | builder.setObjectId(contract.getObjectId()); |
| 220 | 2 | return builder; |
| 221 | |
} |
| 222 | |
|
| 223 | |
public void setApplicationId(String applicationId) { |
| 224 | 18 | if (StringUtils.isBlank(applicationId)) { |
| 225 | 4 | throw new IllegalArgumentException("applicationId is blank"); |
| 226 | |
} |
| 227 | 14 | this.applicationId = applicationId; |
| 228 | 14 | } |
| 229 | |
|
| 230 | |
public void setNamespaceCode(String namespaceCode) { |
| 231 | 14 | if (StringUtils.isBlank(namespaceCode)) { |
| 232 | 3 | throw new IllegalArgumentException("namespaceCode is blank"); |
| 233 | |
} |
| 234 | 11 | this.namespaceCode = namespaceCode; |
| 235 | 11 | } |
| 236 | |
|
| 237 | |
public void setComponentCode(String componentCode) { |
| 238 | 11 | if (StringUtils.isBlank(componentCode)) { |
| 239 | 3 | throw new IllegalArgumentException("componentCode is blank"); |
| 240 | |
} |
| 241 | 8 | this.componentCode = componentCode; |
| 242 | 8 | } |
| 243 | |
|
| 244 | |
public void setName(String name) { |
| 245 | 8 | if (StringUtils.isBlank(name)) { |
| 246 | 3 | throw new IllegalArgumentException("name is blank"); |
| 247 | |
} |
| 248 | 5 | this.name = name; |
| 249 | 5 | } |
| 250 | |
|
| 251 | |
public void setParameterType(ParameterType.Builder parameterType) { |
| 252 | 5 | if (parameterType == null) { |
| 253 | 1 | throw new IllegalArgumentException("parameterType is null"); |
| 254 | |
} |
| 255 | 4 | this.parameterType = parameterType; |
| 256 | 4 | } |
| 257 | |
|
| 258 | |
public void setValue(String value) { |
| 259 | 2 | this.value = value; |
| 260 | 2 | } |
| 261 | |
|
| 262 | |
public void setDescription(String description) { |
| 263 | 2 | this.description = description; |
| 264 | 2 | } |
| 265 | |
|
| 266 | |
public void setEvaluationOperator(EvaluationOperator evaluationOperator) { |
| 267 | 2 | this.evaluationOperator = evaluationOperator; |
| 268 | 2 | } |
| 269 | |
|
| 270 | |
public void setVersionNumber(Long versionNumber) { |
| 271 | 2 | this.versionNumber = versionNumber; |
| 272 | 2 | } |
| 273 | |
|
| 274 | |
public void setObjectId(String objectId) { |
| 275 | 2 | this.objectId = objectId; |
| 276 | 2 | } |
| 277 | |
|
| 278 | |
@Override |
| 279 | |
public String getApplicationId() { |
| 280 | 3 | return applicationId; |
| 281 | |
} |
| 282 | |
|
| 283 | |
@Override |
| 284 | |
public String getNamespaceCode() { |
| 285 | 3 | return namespaceCode; |
| 286 | |
} |
| 287 | |
|
| 288 | |
@Override |
| 289 | |
public String getComponentCode() { |
| 290 | 3 | return componentCode; |
| 291 | |
} |
| 292 | |
|
| 293 | |
@Override |
| 294 | |
public String getName() { |
| 295 | 3 | return name; |
| 296 | |
} |
| 297 | |
|
| 298 | |
@Override |
| 299 | |
public String getValue() { |
| 300 | 3 | return value; |
| 301 | |
} |
| 302 | |
|
| 303 | |
@Override |
| 304 | |
public String getDescription() { |
| 305 | 3 | return description; |
| 306 | |
} |
| 307 | |
|
| 308 | |
@Override |
| 309 | |
public EvaluationOperator getEvaluationOperator() { |
| 310 | 3 | return evaluationOperator; |
| 311 | |
} |
| 312 | |
|
| 313 | |
@Override |
| 314 | |
public Parameter build() { |
| 315 | 3 | return new Parameter(this); |
| 316 | |
} |
| 317 | |
|
| 318 | |
@Override |
| 319 | |
public ParameterType.Builder getParameterType() { |
| 320 | 0 | return parameterType; |
| 321 | |
} |
| 322 | |
|
| 323 | |
@Override |
| 324 | |
public Long getVersionNumber() { |
| 325 | 3 | return versionNumber; |
| 326 | |
} |
| 327 | |
|
| 328 | |
@Override |
| 329 | |
public String getObjectId() { |
| 330 | 3 | return objectId; |
| 331 | |
} |
| 332 | |
|
| 333 | |
} |
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | 0 | static class Constants { |
| 339 | |
final static String ROOT_ELEMENT_NAME = "parameter"; |
| 340 | |
final static String TYPE_NAME = "ParameterType"; |
| 341 | |
} |
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | 0 | static class Elements { |
| 348 | |
final static String APPLICATION_ID = "applicationId"; |
| 349 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
| 350 | |
final static String COMPONENT_CODE = "componentCode"; |
| 351 | |
final static String NAME = "name"; |
| 352 | |
final static String VALUE = "value"; |
| 353 | |
final static String DESCRIPTION = "description"; |
| 354 | |
final static String PARAMETER_TYPE = "parameterType"; |
| 355 | |
final static String EVALUATION_OPERATOR = "evaluationOperator"; |
| 356 | |
} |
| 357 | |
|
| 358 | |
} |