| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krms.api.repository.function; |
| 17 | |
|
| 18 | |
import java.io.Serializable; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.Collection; |
| 21 | |
import java.util.Collections; |
| 22 | |
import java.util.List; |
| 23 | |
|
| 24 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 25 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 26 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 27 | |
import javax.xml.bind.annotation.XmlElement; |
| 28 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
| 29 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 30 | |
import javax.xml.bind.annotation.XmlType; |
| 31 | |
|
| 32 | |
import org.apache.commons.lang.StringUtils; |
| 33 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 34 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 35 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 36 | |
import org.kuali.rice.core.api.CoreConstants; |
| 37 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 38 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 39 | |
import org.kuali.rice.krms.api.repository.category.CategoryDefinition; |
| 40 | |
import org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract; |
| 41 | |
import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition; |
| 42 | |
import org.w3c.dom.Element; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
@XmlRootElement(name = FunctionDefinition.Constants.ROOT_ELEMENT_NAME) |
| 53 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 54 | |
@XmlType(name = FunctionDefinition.Constants.TYPE_NAME, propOrder = { |
| 55 | |
FunctionDefinition.Elements.ID, |
| 56 | |
FunctionDefinition.Elements.NAMESPACE, |
| 57 | |
FunctionDefinition.Elements.NAME, |
| 58 | |
FunctionParameterDefinition.Elements.DESCRIPTION, |
| 59 | |
FunctionDefinition.Elements.RETURN_TYPE, |
| 60 | |
FunctionDefinition.Elements.TYPE_ID, |
| 61 | |
FunctionDefinition.Elements.ACTIVE, |
| 62 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 63 | |
FunctionDefinition.Elements.PARAMETERS, |
| 64 | |
FunctionDefinition.Elements.CATEGORIES, |
| 65 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 66 | |
}) |
| 67 | 4 | public class FunctionDefinition implements FunctionDefinitionContract, ModelObjectComplete { |
| 68 | |
|
| 69 | |
private static final long serialVersionUID = 1391030685309770560L; |
| 70 | |
|
| 71 | |
@XmlElement(name = Elements.ID, required = false) |
| 72 | |
private final String id; |
| 73 | |
|
| 74 | |
@XmlElement(name = Elements.NAMESPACE, required = true) |
| 75 | |
private final String namespace; |
| 76 | |
|
| 77 | |
@XmlElement(name = Elements.NAME, required = true) |
| 78 | |
private final String name; |
| 79 | |
|
| 80 | |
@XmlElement(name = Elements.DESCRIPTION, required = false) |
| 81 | |
private final String description; |
| 82 | |
|
| 83 | |
@XmlElement(name = Elements.RETURN_TYPE, required = true) |
| 84 | |
private final String returnType; |
| 85 | |
|
| 86 | |
@XmlElement(name = Elements.TYPE_ID, required = true) |
| 87 | |
private final String typeId; |
| 88 | |
|
| 89 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
| 90 | |
private final boolean active; |
| 91 | |
|
| 92 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 93 | |
private final Long versionNumber; |
| 94 | |
|
| 95 | |
@XmlElementWrapper(name = Elements.PARAMETERS, required = false) |
| 96 | |
@XmlElement(name = Elements.PARAMETER, required = false) |
| 97 | |
private final List<FunctionParameterDefinition> parameters; |
| 98 | |
|
| 99 | |
@XmlElementWrapper(name = Elements.CATEGORIES, required = false) |
| 100 | |
@XmlElement(name = Elements.CATEGORY, required = false) |
| 101 | |
private final List<CategoryDefinition> categories; |
| 102 | |
|
| 103 | 6 | @SuppressWarnings("unused") |
| 104 | |
@XmlAnyElement |
| 105 | |
private final Collection<Element> _futureElements = null; |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | 2 | private FunctionDefinition() { |
| 111 | 2 | this.id = null; |
| 112 | 2 | this.namespace = null; |
| 113 | 2 | this.name = null; |
| 114 | 2 | this.description = null; |
| 115 | 2 | this.returnType = null; |
| 116 | 2 | this.typeId = null; |
| 117 | 2 | this.active = false; |
| 118 | 2 | this.versionNumber = null; |
| 119 | 2 | this.parameters = null; |
| 120 | 2 | this.categories = null; |
| 121 | 2 | } |
| 122 | |
|
| 123 | 4 | private FunctionDefinition(Builder builder) { |
| 124 | 4 | this.id = builder.getId(); |
| 125 | 4 | this.namespace = builder.getNamespace(); |
| 126 | 4 | this.name = builder.getName(); |
| 127 | 4 | this.description = builder.getDescription(); |
| 128 | 4 | this.returnType = builder.getReturnType(); |
| 129 | 4 | this.typeId = builder.getTypeId(); |
| 130 | 4 | this.active = builder.isActive(); |
| 131 | 4 | this.versionNumber = builder.getVersionNumber(); |
| 132 | 4 | this.parameters = new ArrayList<FunctionParameterDefinition>(); |
| 133 | 4 | for (FunctionParameterDefinition.Builder parameter : builder.getParameters()) { |
| 134 | 6 | this.parameters.add(parameter.build()); |
| 135 | |
} |
| 136 | 4 | this.categories = new ArrayList<CategoryDefinition>(); |
| 137 | 4 | for (CategoryDefinition.Builder category : builder.getCategories()) { |
| 138 | 6 | this.categories.add(category.build()); |
| 139 | |
} |
| 140 | 4 | } |
| 141 | |
|
| 142 | |
@Override |
| 143 | |
public String getId() { |
| 144 | 2 | return id; |
| 145 | |
} |
| 146 | |
|
| 147 | |
@Override |
| 148 | |
public String getNamespace() { |
| 149 | 2 | return namespace; |
| 150 | |
} |
| 151 | |
|
| 152 | |
@Override |
| 153 | |
public String getName() { |
| 154 | 2 | return name; |
| 155 | |
} |
| 156 | |
|
| 157 | |
@Override |
| 158 | |
public String getDescription() { |
| 159 | 2 | return description; |
| 160 | |
} |
| 161 | |
|
| 162 | |
@Override |
| 163 | |
public String getReturnType() { |
| 164 | 2 | return returnType; |
| 165 | |
} |
| 166 | |
|
| 167 | |
@Override |
| 168 | |
public String getTypeId() { |
| 169 | 2 | return typeId; |
| 170 | |
} |
| 171 | |
|
| 172 | |
@Override |
| 173 | |
public boolean isActive() { |
| 174 | 2 | return active; |
| 175 | |
} |
| 176 | |
|
| 177 | |
@Override |
| 178 | |
public Long getVersionNumber() { |
| 179 | 2 | return versionNumber; |
| 180 | |
} |
| 181 | |
|
| 182 | |
@Override |
| 183 | |
public List<FunctionParameterDefinition> getParameters() { |
| 184 | 4 | return Collections.unmodifiableList(parameters); |
| 185 | |
} |
| 186 | |
|
| 187 | |
@Override |
| 188 | |
public List<CategoryDefinition> getCategories() { |
| 189 | 2 | return Collections.unmodifiableList(categories); |
| 190 | |
} |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | 4 | public static final class Builder implements FunctionDefinitionContract, ModelBuilder, Serializable { |
| 200 | |
|
| 201 | |
private static final long serialVersionUID = -4470376239998290245L; |
| 202 | |
|
| 203 | |
private String id; |
| 204 | |
private String namespace; |
| 205 | |
private String name; |
| 206 | |
private String description; |
| 207 | |
private String returnType; |
| 208 | |
private String typeId; |
| 209 | |
private boolean active; |
| 210 | |
private Long versionNumber; |
| 211 | |
private List<FunctionParameterDefinition.Builder> parameters; |
| 212 | |
private List<CategoryDefinition.Builder> categories; |
| 213 | |
|
| 214 | 16 | private Builder(String namespace, String name, String returnType, String typeId) { |
| 215 | 16 | setNamespace(namespace); |
| 216 | 13 | setName(name); |
| 217 | 10 | setReturnType(returnType); |
| 218 | 7 | setTypeId(typeId); |
| 219 | 4 | setActive(true); |
| 220 | 4 | setParameters(new ArrayList<FunctionParameterDefinition.Builder>()); |
| 221 | 4 | setCategories(new ArrayList<CategoryDefinition.Builder>()); |
| 222 | 4 | } |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
public static Builder create(String namespace, String name, String returnType, String typeId) { |
| 240 | 16 | return new Builder(namespace, name, returnType, typeId); |
| 241 | |
} |
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
public static Builder create(FunctionDefinitionContract contract) { |
| 255 | 3 | if (contract == null) { |
| 256 | 0 | throw new IllegalArgumentException("contract was null"); |
| 257 | |
} |
| 258 | 3 | Builder builder = create(contract.getNamespace(), contract.getName(), contract.getReturnType(), contract.getTypeId()); |
| 259 | 3 | builder.setId(contract.getId()); |
| 260 | 3 | builder.setDescription(contract.getDescription()); |
| 261 | 3 | builder.setActive(contract.isActive()); |
| 262 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
| 263 | 3 | for (FunctionParameterDefinitionContract parameter : contract.getParameters()) { |
| 264 | 6 | builder.getParameters().add(FunctionParameterDefinition.Builder.create(parameter)); |
| 265 | |
} |
| 266 | 3 | for (CategoryDefinitionContract category : contract.getCategories()) { |
| 267 | 6 | builder.getCategories().add(CategoryDefinition.Builder.create(category)); |
| 268 | |
} |
| 269 | 3 | return builder; |
| 270 | |
} |
| 271 | |
|
| 272 | |
@Override |
| 273 | |
public FunctionDefinition build() { |
| 274 | 4 | return new FunctionDefinition(this); |
| 275 | |
} |
| 276 | |
|
| 277 | |
@Override |
| 278 | |
public String getId() { |
| 279 | 4 | return this.id; |
| 280 | |
} |
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
public void setId(String id) { |
| 288 | 3 | this.id = id; |
| 289 | 3 | } |
| 290 | |
|
| 291 | |
@Override |
| 292 | |
public String getNamespace() { |
| 293 | 4 | return this.namespace; |
| 294 | |
} |
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
public void setNamespace(String namespace) { |
| 305 | 16 | if (StringUtils.isBlank(namespace)) { |
| 306 | 3 | throw new IllegalArgumentException("namespace was blank"); |
| 307 | |
} |
| 308 | 13 | this.namespace = namespace; |
| 309 | 13 | } |
| 310 | |
|
| 311 | |
@Override |
| 312 | |
public String getName() { |
| 313 | 4 | return this.name; |
| 314 | |
} |
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
public void setName(String name) { |
| 325 | 13 | if (StringUtils.isBlank(name)) { |
| 326 | 3 | throw new IllegalArgumentException("name was blank"); |
| 327 | |
} |
| 328 | 10 | this.name = name; |
| 329 | 10 | } |
| 330 | |
|
| 331 | |
@Override |
| 332 | |
public String getDescription() { |
| 333 | 4 | return this.description; |
| 334 | |
} |
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
public void setDescription(String description) { |
| 342 | 3 | this.description = description; |
| 343 | 3 | } |
| 344 | |
|
| 345 | |
@Override |
| 346 | |
public String getReturnType() { |
| 347 | 4 | return this.returnType; |
| 348 | |
} |
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
public void setReturnType(String returnType) { |
| 361 | 10 | if (StringUtils.isBlank(returnType)) { |
| 362 | 3 | throw new IllegalArgumentException("returnType was blank"); |
| 363 | |
} |
| 364 | 7 | this.returnType = returnType; |
| 365 | 7 | } |
| 366 | |
|
| 367 | |
@Override |
| 368 | |
public String getTypeId() { |
| 369 | 4 | return this.typeId; |
| 370 | |
} |
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
public void setTypeId(String typeId) { |
| 382 | 7 | if (StringUtils.isBlank(typeId)) { |
| 383 | 3 | throw new IllegalArgumentException("typeId was blank"); |
| 384 | |
} |
| 385 | 4 | this.typeId = typeId; |
| 386 | 4 | } |
| 387 | |
|
| 388 | |
@Override |
| 389 | |
public boolean isActive() { |
| 390 | 4 | return this.active; |
| 391 | |
} |
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
public void setActive(boolean active) { |
| 400 | 7 | this.active = active; |
| 401 | 7 | } |
| 402 | |
|
| 403 | |
@Override |
| 404 | |
public Long getVersionNumber() { |
| 405 | 4 | return this.versionNumber; |
| 406 | |
} |
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
public void setVersionNumber(Long versionNumber) { |
| 419 | 3 | this.versionNumber = versionNumber; |
| 420 | 3 | } |
| 421 | |
|
| 422 | |
@Override |
| 423 | |
public List<FunctionParameterDefinition.Builder> getParameters() { |
| 424 | 10 | return this.parameters; |
| 425 | |
} |
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
public void setParameters(List<FunctionParameterDefinition.Builder> parameters) { |
| 438 | 4 | if (parameters == null) { |
| 439 | 0 | throw new IllegalArgumentException("parameters was null"); |
| 440 | |
} |
| 441 | 4 | this.parameters = parameters; |
| 442 | 4 | } |
| 443 | |
|
| 444 | |
@Override |
| 445 | |
public List<CategoryDefinition.Builder> getCategories() { |
| 446 | 10 | return this.categories; |
| 447 | |
} |
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
public void setCategories(List<CategoryDefinition.Builder> categories) { |
| 460 | 4 | if (categories == null) { |
| 461 | 0 | throw new IllegalArgumentException("categories was null"); |
| 462 | |
} |
| 463 | 4 | this.categories = categories; |
| 464 | 4 | } |
| 465 | |
|
| 466 | |
} |
| 467 | |
|
| 468 | |
@Override |
| 469 | |
public int hashCode() { |
| 470 | 3 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 471 | |
} |
| 472 | |
|
| 473 | |
@Override |
| 474 | |
public boolean equals(Object obj) { |
| 475 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 476 | |
} |
| 477 | |
|
| 478 | |
@Override |
| 479 | |
public String toString() { |
| 480 | 1 | return ToStringBuilder.reflectionToString(this); |
| 481 | |
} |
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | 0 | static class Constants { |
| 487 | |
final static String ROOT_ELEMENT_NAME = "function"; |
| 488 | |
final static String TYPE_NAME = "FunctionType"; |
| 489 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
| 490 | |
} |
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
|
| 495 | |
|
| 496 | 0 | static class Elements { |
| 497 | |
final static String ID = "id"; |
| 498 | |
final static String NAMESPACE = "namespace"; |
| 499 | |
final static String NAME = "name"; |
| 500 | |
final static String DESCRIPTION = "description"; |
| 501 | |
final static String RETURN_TYPE = "returnType"; |
| 502 | |
final static String TYPE_ID = "typeId"; |
| 503 | |
final static String ACTIVE = "active"; |
| 504 | |
final static String PARAMETERS = "parameters"; |
| 505 | |
final static String PARAMETER = "parameter"; |
| 506 | |
final static String CATEGORIES = "categories"; |
| 507 | |
final static String CATEGORY = "category"; |
| 508 | |
} |
| 509 | |
|
| 510 | |
} |