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