001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krms.api.repository.typerelation; 017 018import org.kuali.rice.core.api.CoreConstants; 019import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 020import org.kuali.rice.core.api.mo.ModelBuilder; 021import javax.xml.bind.Element; 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlAnyElement; 025import javax.xml.bind.annotation.XmlElement; 026import javax.xml.bind.annotation.XmlRootElement; 027import javax.xml.bind.annotation.XmlType; 028import java.io.Serializable; 029import java.util.Collection; 030 031/** 032 * Generated using JVM arguments -DENUM=RelationshipType:UNKNOWN:USAGE_ALLOWED -DNOT_BLANK=fromTypeId,toTypeId,sequenceNumber,relationshipType -DFOREIGN_KEY=fromTypeId:org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition,toTypeId:org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition 033 * Concrete model object implementation, immutable. 034 * Instances can be (un)marshalled to and from XML. 035 * 036 * @see TypeTypeRelationContract 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 * 040 */ 041@XmlRootElement(name = TypeTypeRelation.Constants.ROOT_ELEMENT_NAME) 042@XmlAccessorType(XmlAccessType.NONE) 043@XmlType(name = TypeTypeRelation.Constants.TYPE_NAME, propOrder = { 044 TypeTypeRelation.Elements.FROM_TYPE_ID, 045 TypeTypeRelation.Elements.TO_TYPE_ID, 046 TypeTypeRelation.Elements.RELATIONSHIP_TYPE, 047 TypeTypeRelation.Elements.SEQUENCE_NUMBER, 048 TypeTypeRelation.Elements.ID, 049 TypeTypeRelation.Elements.ACTIVE, 050 CoreConstants.CommonElements.VERSION_NUMBER, 051 CoreConstants.CommonElements.FUTURE_ELEMENTS 052}) 053public final class TypeTypeRelation 054 extends AbstractDataTransferObject 055 implements TypeTypeRelationContract 056{ 057 058 @XmlElement(name = Elements.FROM_TYPE_ID, required = false) 059 private final String fromTypeId; 060 @XmlElement(name = Elements.TO_TYPE_ID, required = false) 061 private final String toTypeId; 062 @XmlElement(name = Elements.RELATIONSHIP_TYPE, required = false) 063 private final RelationshipType relationshipType; 064 @XmlElement(name = Elements.SEQUENCE_NUMBER, required = false) 065 private final Integer sequenceNumber; 066 @XmlElement(name = Elements.ID, required = false) 067 private final String id; 068 @XmlElement(name = Elements.ACTIVE, required = false) 069 private final boolean active; 070 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 071 private final Long versionNumber; 072 @SuppressWarnings("unused") 073 @XmlAnyElement 074 private final Collection<Element> _futureElements = null; 075 076 /** 077 * Private constructor used only by JAXB. This constructor should never be called. 078 * It is only present for use during JAXB unmarshalling. 079 * 080 */ 081 private TypeTypeRelation() { 082 this.fromTypeId = null; 083 this.toTypeId = null; 084 this.relationshipType = null; 085 this.sequenceNumber = null; 086 this.id = null; 087 this.active = false; 088 this.versionNumber = null; 089 } 090 091 /** 092 * Constructs an object from the given builder. This constructor is private and should only ever be invoked from the builder. 093 * 094 * @param builder the Builder from which to construct the object. 095 * 096 */ 097 private TypeTypeRelation(Builder builder) { 098 this.fromTypeId = builder.getFromTypeId(); 099 this.toTypeId = builder.getToTypeId(); 100 this.relationshipType = builder.getRelationshipType(); 101 this.sequenceNumber = builder.getSequenceNumber(); 102 this.id = builder.getId(); 103 this.active = builder.isActive(); 104 this.versionNumber = builder.getVersionNumber(); 105 } 106 107 @Override 108 public String getFromTypeId() { 109 return this.fromTypeId; 110 } 111 112 @Override 113 public String getToTypeId() { 114 return this.toTypeId; 115 } 116 117 @Override 118 public RelationshipType getRelationshipType() { 119 return this.relationshipType; 120 } 121 122 @Override 123 public Integer getSequenceNumber() { 124 return this.sequenceNumber; 125 } 126 127 @Override 128 public String getId() { 129 return this.id; 130 } 131 132 @Override 133 public boolean isActive() { 134 return this.active; 135 } 136 137 @Override 138 public Long getVersionNumber() { 139 return this.versionNumber; 140 } 141 142 143 /** 144 * A builder which can be used to construct {@link TypeTypeRelation} instances. Enforces the constraints of the {@link TypeTypeRelationContract}. 145 * 146 */ 147 public final static class Builder 148 implements Serializable, ModelBuilder, TypeTypeRelationContract 149 { 150 151 private String fromTypeId; 152 private String toTypeId; 153 private RelationshipType relationshipType; 154 private Integer sequenceNumber; 155 private String id; 156 private boolean active; 157 private Long versionNumber; 158 159 private Builder(String fromTypeId, RelationshipType relationshipType, Integer sequenceNumber, String toTypeId) { 160 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods 161 setFromTypeId(fromTypeId); 162 setRelationshipType(relationshipType); 163 setSequenceNumber(sequenceNumber); 164 setToTypeId(toTypeId); 165 } 166 167 public static Builder create(String fromTypeId, RelationshipType relationshipType, Integer sequenceNumber, String toTypeId) { 168 // TODO modify as needed to pass any required values and add them to the signature of the 'create' method 169 return new Builder(fromTypeId, relationshipType, sequenceNumber, toTypeId); 170 } 171 172 public static Builder create(TypeTypeRelationContract contract) { 173 if (contract == null) { 174 throw new IllegalArgumentException("contract was null"); 175 } 176 // TODO if create() is modified to accept required parameters, this will need to be modified 177 Builder builder = create(contract.getFromTypeId(), contract.getRelationshipType(), contract.getSequenceNumber(), contract.getToTypeId()); 178 builder.setId(contract.getId()); 179 builder.setActive(contract.isActive()); 180 builder.setVersionNumber(contract.getVersionNumber()); 181 return builder; 182 } 183 184 /** 185 * Builds an instance of a TypeTypeRelation based on the current state of the builder. 186 * 187 * @return the fully-constructed TypeTypeRelation. 188 * 189 */ 190 public TypeTypeRelation build() { 191 return new TypeTypeRelation(this); 192 } 193 194 @Override 195 public boolean isActive() { 196 return this.active; 197 } 198 199 @Override 200 public String getFromTypeId() { 201 return this.fromTypeId; 202 } 203 204 @Override 205 public String getId() { 206 return this.id; 207 } 208 209 @Override 210 public RelationshipType getRelationshipType() { 211 return this.relationshipType; 212 } 213 214 @Override 215 public Integer getSequenceNumber() { 216 return this.sequenceNumber; 217 } 218 219 @Override 220 public String getToTypeId() { 221 return this.toTypeId; 222 } 223 224 @Override 225 public Long getVersionNumber() { 226 return this.versionNumber; 227 } 228 229 /** 230 * Sets the value of active on this builder to the given value. 231 * 232 * @param active the active value to set. 233 * 234 */ 235 public void setActive(boolean active) { 236 this.active = active; 237 } 238 239 /** 240 * Sets the value of fromTypeId on this builder to the given value. 241 * 242 * @param fromTypeId the fromTypeId value to set., must not be null or blank 243 * @throws IllegalArgumentException if the fromTypeId is null or blank 244 * 245 */ 246 public void setFromTypeId(String fromTypeId) { 247 if (org.apache.commons.lang.StringUtils.isBlank(fromTypeId)) { 248 throw new IllegalArgumentException("fromTypeId is null or blank"); 249 } 250 this.fromTypeId = fromTypeId; 251 } 252 253 /** 254 * Sets the value of id on this builder to the given value. 255 * 256 * @param id the id value to set., may be null, representing the Object has not been persisted, but must not be blank. 257 * @throws IllegalArgumentException if the id is blank 258 * 259 */ 260 public void setId(String id) { 261 if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) { 262 throw new IllegalArgumentException("id is blank"); 263 } 264 this.id = id; 265 } 266 267 /** 268 * Sets the value of relationshipType on this builder to the given value. 269 * 270 * @param relationshipType the relationshipType value to set., must not be null 271 * @throws IllegalArgumentException if the relationshipType is null 272 * 273 */ 274 public void setRelationshipType(RelationshipType relationshipType) { 275 if (relationshipType == null) { 276 throw new IllegalArgumentException("relationshipType is null"); 277 } 278 this.relationshipType = relationshipType; 279 } 280 281 /** 282 * Sets the value of sequenceNumber on this builder to the given value. 283 * 284 * @param sequenceNumber the sequenceNumber value to set., must not be null 285 * @throws IllegalArgumentException if the sequenceNumber is null 286 * 287 */ 288 public void setSequenceNumber(Integer sequenceNumber) { 289 if (sequenceNumber == null) { 290 throw new IllegalArgumentException("sequenceNumber is null"); 291 } 292 this.sequenceNumber = sequenceNumber; 293 } 294 295 /** 296 * Sets the value of toTypeId on this builder to the given value. 297 * 298 * @param toTypeId the toTypeId value to set., must not be null or blank 299 * @throws IllegalArgumentException if the toTypeId is null or blank 300 * 301 */ 302 public void setToTypeId(String toTypeId) { 303 if (org.apache.commons.lang.StringUtils.isBlank(toTypeId)) { 304 throw new IllegalArgumentException("toTypeId is null or blank"); 305 } 306 this.toTypeId = toTypeId; 307 } 308 309 /** 310 * Sets the value of versionNumber on this builder to the given value. 311 * 312 * @param versionNumber the versionNumber value to set. 313 * 314 */ 315 public void setVersionNumber(Long versionNumber) { 316 this.versionNumber = versionNumber; 317 } 318 319 } 320 321 322 /** 323 * Defines some internal constants used on this class. 324 * 325 */ 326 static class Constants { 327 328 final static String ROOT_ELEMENT_NAME = "typeTypeRelation"; 329 final static String TYPE_NAME = "TypeTypeRelationType"; 330 331 } 332 333 334 /** 335 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 336 * 337 */ 338 static class Elements { 339 340 final static String FROM_TYPE_ID = "fromTypeId"; 341 final static String TO_TYPE_ID = "toTypeId"; 342 final static String RELATIONSHIP_TYPE = "relationshipType"; 343 final static String SEQUENCE_NUMBER = "sequenceNumber"; 344 final static String ID = "id"; 345 final static String ACTIVE = "active"; 346 347 } 348 349}