| 1 | |
package org.kuali.rice.krms.api.repository.type; |
| 2 | |
|
| 3 | |
import java.io.Serializable; |
| 4 | |
import java.util.ArrayList; |
| 5 | |
import java.util.Collection; |
| 6 | |
import java.util.Collections; |
| 7 | |
import java.util.List; |
| 8 | |
|
| 9 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 10 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 11 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 12 | |
import javax.xml.bind.annotation.XmlElement; |
| 13 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 14 | |
import javax.xml.bind.annotation.XmlType; |
| 15 | |
|
| 16 | |
import org.apache.commons.lang.StringUtils; |
| 17 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 18 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 19 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 20 | |
import org.kuali.rice.core.api.CoreConstants; |
| 21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 22 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
@XmlRootElement(name = KrmsTypeDefinition.Constants.ROOT_ELEMENT_NAME) |
| 32 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 33 | |
@XmlType(name = KrmsTypeDefinition.Constants.TYPE_NAME, propOrder = { |
| 34 | |
KrmsTypeDefinition.Elements.ID, |
| 35 | |
KrmsTypeDefinition.Elements.NAME, |
| 36 | |
KrmsTypeDefinition.Elements.NAMESPACE, |
| 37 | |
KrmsTypeDefinition.Elements.SERVICENAME, |
| 38 | |
KrmsTypeDefinition.Elements.ACTIVE, |
| 39 | |
KrmsTypeDefinition.Elements.ATTRIBUTES, |
| 40 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 41 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 42 | |
}) |
| 43 | 8 | public final class KrmsTypeDefinition implements KrmsTypeDefinitionContract, ModelObjectComplete{ |
| 44 | |
private static final long serialVersionUID = -8314397393380856301L; |
| 45 | |
|
| 46 | |
@XmlElement(name = Elements.ID, required=true) |
| 47 | |
private String id; |
| 48 | |
@XmlElement(name = Elements.NAME, required=true) |
| 49 | |
private String name; |
| 50 | |
@XmlElement(name = Elements.NAMESPACE, required=true) |
| 51 | |
private String namespace; |
| 52 | |
@XmlElement(name = Elements.SERVICENAME, required=false) |
| 53 | |
private String serviceName; |
| 54 | |
@XmlElement(name = Elements.ACTIVE, required=false) |
| 55 | |
private boolean active; |
| 56 | |
@XmlElement(name = Elements.ATTRIBUTE, required=false) |
| 57 | |
private List<KrmsTypeAttribute> attributes; |
| 58 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 59 | |
private final Long versionNumber; |
| 60 | |
|
| 61 | 14 | @SuppressWarnings("unused") |
| 62 | |
@XmlAnyElement |
| 63 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 6 | private KrmsTypeDefinition() { |
| 69 | 6 | this.id = null; |
| 70 | 6 | this.name = null; |
| 71 | 6 | this.namespace = null; |
| 72 | 6 | this.serviceName = null; |
| 73 | 6 | this.active = false; |
| 74 | 6 | this.attributes = null; |
| 75 | 6 | this.versionNumber = null; |
| 76 | 6 | } |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 8 | private KrmsTypeDefinition(Builder builder) { |
| 85 | 8 | this.id = builder.getId(); |
| 86 | 8 | this.name = builder.getName(); |
| 87 | 8 | this.namespace = builder.getNamespace(); |
| 88 | 8 | this.serviceName = builder.getServiceName(); |
| 89 | 8 | this.active = builder.isActive(); |
| 90 | 8 | List<KrmsTypeAttribute> attrList = new ArrayList<KrmsTypeAttribute>(); |
| 91 | 8 | if (builder.attributes != null){ |
| 92 | 5 | for (KrmsTypeAttribute.Builder b : builder.attributes){ |
| 93 | 4 | attrList.add(b.build()); |
| 94 | |
} |
| 95 | |
} |
| 96 | 8 | this.attributes = Collections.unmodifiableList(attrList); |
| 97 | 8 | this.versionNumber = builder.getVersionNumber(); |
| 98 | 8 | } |
| 99 | |
|
| 100 | |
@Override |
| 101 | |
public String getId() { |
| 102 | 2 | return this.id; |
| 103 | |
} |
| 104 | |
|
| 105 | |
@Override |
| 106 | |
public String getName() { |
| 107 | 2 | return this.name; |
| 108 | |
} |
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public String getNamespace() { |
| 112 | 2 | return this.namespace; |
| 113 | |
} |
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public String getServiceName() { |
| 117 | 0 | return this.serviceName; |
| 118 | |
} |
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public boolean isActive() { |
| 122 | 2 | return this.active; |
| 123 | |
} |
| 124 | |
|
| 125 | |
@Override |
| 126 | |
public List<KrmsTypeAttribute> getAttributes() { |
| 127 | 1 | return this.attributes; |
| 128 | |
} |
| 129 | |
|
| 130 | |
@Override |
| 131 | |
public Long getVersionNumber() { |
| 132 | 0 | return versionNumber; |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | 21 | public static class Builder implements KrmsTypeDefinitionContract, ModelBuilder, Serializable { |
| 139 | |
private static final long serialVersionUID = -3469525730879441547L; |
| 140 | |
|
| 141 | |
private String id; |
| 142 | |
private String name; |
| 143 | |
private String namespace; |
| 144 | 12 | private String serviceName = ""; |
| 145 | |
private boolean active; |
| 146 | |
private List<KrmsTypeAttribute.Builder> attributes; |
| 147 | |
private Long versionNumber; |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | 12 | private Builder(String id, String name, String namespace) { |
| 153 | 12 | setId(id); |
| 154 | 10 | setName(name); |
| 155 | 10 | setNamespace(namespace); |
| 156 | 10 | setActive(true); |
| 157 | 10 | } |
| 158 | |
|
| 159 | |
public Builder serviceName(String serviceName){ |
| 160 | 3 | this.serviceName = serviceName; |
| 161 | 3 | return this; |
| 162 | |
} |
| 163 | |
|
| 164 | |
public Builder attributes(List<KrmsTypeAttribute.Builder> attributes){ |
| 165 | 2 | setAttributes(attributes); |
| 166 | 2 | return this; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
public static Builder create(String id, String name, String namespace) { |
| 179 | 9 | return new Builder(id, name, namespace); |
| 180 | |
} |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public static Builder create(KrmsTypeDefinitionContract contract) { |
| 189 | 3 | if (contract == null) { |
| 190 | 0 | throw new IllegalArgumentException("contract is null"); |
| 191 | |
} |
| 192 | 3 | Builder builder = new Builder(contract.getId(), contract.getName(), contract.getNamespace()); |
| 193 | 3 | builder.setNamespace(contract.getNamespace()); |
| 194 | 3 | builder.setActive(contract.isActive()); |
| 195 | 3 | builder.setServiceName(contract.getServiceName()); |
| 196 | 3 | List <KrmsTypeAttribute.Builder> attrBuilderList = new ArrayList<KrmsTypeAttribute.Builder>(); |
| 197 | 3 | if (contract.getAttributes() != null) { |
| 198 | 0 | for(KrmsTypeAttributeContract attr : contract.getAttributes()){ |
| 199 | 0 | KrmsTypeAttribute.Builder myBuilder = |
| 200 | |
KrmsTypeAttribute.Builder.create(attr); |
| 201 | 0 | attrBuilderList.add(myBuilder); |
| 202 | 0 | } |
| 203 | |
} |
| 204 | 3 | builder.setAttributes(attrBuilderList); |
| 205 | 3 | builder.setVersionNumber(contract.getVersionNumber()); |
| 206 | 3 | return builder; |
| 207 | |
} |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
public void setId(String id) { |
| 216 | 12 | if (id != null && StringUtils.isBlank(id)) { |
| 217 | 2 | throw new IllegalArgumentException("id is blank"); |
| 218 | |
} |
| 219 | 10 | this.id = id; |
| 220 | 10 | } |
| 221 | |
|
| 222 | |
public void setName(String name) { |
| 223 | 10 | if (StringUtils.isBlank(name)) { |
| 224 | 0 | throw new IllegalArgumentException("name is blank"); |
| 225 | |
} |
| 226 | 10 | this.name = name; |
| 227 | 10 | } |
| 228 | |
|
| 229 | |
public void setNamespace(String namespace) { |
| 230 | 13 | if (StringUtils.isBlank(namespace)) { |
| 231 | 0 | throw new IllegalArgumentException("namespace is blank"); |
| 232 | |
} |
| 233 | 13 | this.namespace = namespace; |
| 234 | 13 | } |
| 235 | |
|
| 236 | |
public void setServiceName(String serviceName) { |
| 237 | 3 | this.serviceName = serviceName; |
| 238 | 3 | } |
| 239 | |
|
| 240 | |
public void setAttributes(List<KrmsTypeAttribute.Builder> attributes){ |
| 241 | 5 | if (attributes == null || attributes.isEmpty()){ |
| 242 | 3 | this.attributes = Collections.unmodifiableList(new ArrayList<KrmsTypeAttribute.Builder>()); |
| 243 | 3 | return; |
| 244 | |
} |
| 245 | 2 | this.attributes = Collections.unmodifiableList(attributes); |
| 246 | 2 | } |
| 247 | |
|
| 248 | |
public void setActive(boolean active) { |
| 249 | 13 | this.active = active; |
| 250 | 13 | } |
| 251 | |
|
| 252 | |
public void setVersionNumber(Long versionNumber){ |
| 253 | 3 | this.versionNumber = versionNumber; |
| 254 | 3 | } |
| 255 | |
|
| 256 | |
@Override |
| 257 | |
public String getId() { |
| 258 | 10 | return id; |
| 259 | |
} |
| 260 | |
|
| 261 | |
@Override |
| 262 | |
public String getName() { |
| 263 | 10 | return name; |
| 264 | |
} |
| 265 | |
|
| 266 | |
@Override |
| 267 | |
public String getNamespace() { |
| 268 | 12 | return namespace; |
| 269 | |
} |
| 270 | |
|
| 271 | |
@Override |
| 272 | |
public String getServiceName() { |
| 273 | 10 | return serviceName; |
| 274 | |
} |
| 275 | |
|
| 276 | |
@Override |
| 277 | |
public List<KrmsTypeAttribute.Builder> getAttributes(){ |
| 278 | 2 | return attributes; |
| 279 | |
} |
| 280 | |
|
| 281 | |
@Override |
| 282 | |
public boolean isActive() { |
| 283 | 10 | return active; |
| 284 | |
} |
| 285 | |
|
| 286 | |
@Override |
| 287 | |
public Long getVersionNumber() { |
| 288 | 10 | return versionNumber; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
@Override |
| 297 | |
public KrmsTypeDefinition build() { |
| 298 | 8 | return new KrmsTypeDefinition(this); |
| 299 | |
} |
| 300 | |
|
| 301 | |
} |
| 302 | |
@Override |
| 303 | |
public int hashCode() { |
| 304 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 305 | |
} |
| 306 | |
|
| 307 | |
@Override |
| 308 | |
public boolean equals(Object obj) { |
| 309 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
| 310 | |
} |
| 311 | |
|
| 312 | |
@Override |
| 313 | |
public String toString() { |
| 314 | 0 | return ToStringBuilder.reflectionToString(this); |
| 315 | |
} |
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | 0 | static class Constants { |
| 321 | |
final static String ROOT_ELEMENT_NAME = "KRMSType"; |
| 322 | |
final static String TYPE_NAME = "KRMSTypeType"; |
| 323 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
| 324 | |
} |
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | 0 | public static class Elements { |
| 331 | |
final static String ID = "id"; |
| 332 | |
final static String NAME = "name"; |
| 333 | |
final static String NAMESPACE = "namespace"; |
| 334 | |
final static String SERVICENAME = "serviceName"; |
| 335 | |
final static String ACTIVE = "active"; |
| 336 | |
final static String ATTRIBUTE = "attribute"; |
| 337 | |
final static String ATTRIBUTES = "attributes"; |
| 338 | |
} |
| 339 | |
} |