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