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.language; 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 org.kuali.rice.krms.api.KrmsConstants; 022import org.w3c.dom.Element; 023import javax.xml.bind.annotation.XmlAccessType; 024import javax.xml.bind.annotation.XmlAccessorType; 025import javax.xml.bind.annotation.XmlAnyElement; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlRootElement; 028import javax.xml.bind.annotation.XmlType; 029import java.io.Serializable; 030import java.util.Collection; 031 032/** 033 * Generated using JVM arguments -DNOT_BLANK=name,typeId 034 * Concrete model object implementation, immutable. 035 * Instances can be (un)marshalled to and from XML. 036 * 037 * @see NaturalLanguageUsageContract 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 * 041 */ 042@XmlRootElement(name = NaturalLanguageUsage.Constants.ROOT_ELEMENT_NAME) 043@XmlAccessorType(XmlAccessType.NONE) 044@XmlType(name = NaturalLanguageUsage.Constants.TYPE_NAME, propOrder = { 045 NaturalLanguageUsage.Elements.NAME, 046 NaturalLanguageUsage.Elements.DESCRIPTION, 047 NaturalLanguageUsage.Elements.NAMESPACE, 048 NaturalLanguageUsage.Elements.ID, 049 NaturalLanguageUsage.Elements.ACTIVE, 050 CoreConstants.CommonElements.VERSION_NUMBER, 051 CoreConstants.CommonElements.FUTURE_ELEMENTS 052}) 053public final class NaturalLanguageUsage 054 extends AbstractDataTransferObject 055 implements NaturalLanguageUsageContract 056{ 057 058 @XmlElement(name = Elements.NAME, required = false) 059 private final String name; 060 @XmlElement(name = Elements.DESCRIPTION, required = false) 061 private final String description; 062 @XmlElement(name = Elements.NAMESPACE, required = false) 063 private final String namespace; 064 @XmlElement(name = Elements.ID, required = false) 065 private final String id; 066 @XmlElement(name = Elements.ACTIVE, required = false) 067 private final boolean active; 068 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 069 private final Long versionNumber; 070 @SuppressWarnings("unused") 071 @XmlAnyElement 072 private final Collection<Element> _futureElements = null; 073 074 /** 075 * Private constructor used only by JAXB. This constructor should never be called. 076 * It is only present for use during JAXB unmarshalling. 077 * 078 */ 079 private NaturalLanguageUsage() { 080 this.name = null; 081 this.description = null; 082 this.namespace = null; 083 this.id = null; 084 this.active = false; 085 this.versionNumber = null; 086 } 087 088 /** 089 * Constructs an object from the given builder. This constructor is private and should only ever be invoked from the builder. 090 * 091 * @param builder the Builder from which to construct the object. 092 * 093 */ 094 private NaturalLanguageUsage(Builder builder) { 095 this.name = builder.getName(); 096 this.description = builder.getDescription(); 097 this.namespace = builder.getNamespace(); 098 this.id = builder.getId(); 099 this.active = builder.isActive(); 100 this.versionNumber = builder.getVersionNumber(); 101 } 102 103 @Override 104 public String getName() { 105 return this.name; 106 } 107 108 @Override 109 public String getDescription() { 110 return this.description; 111 } 112 113 @Override 114 public String getNamespace() { 115 return this.namespace; 116 } 117 118 @Override 119 public String getId() { 120 return this.id; 121 } 122 123 @Override 124 public boolean isActive() { 125 return this.active; 126 } 127 128 @Override 129 public Long getVersionNumber() { 130 return this.versionNumber; 131 } 132 133 134 /** 135 * A builder which can be used to construct {@link NaturalLanguageUsage} instances. Enforces the constraints of the {@link NaturalLanguageUsageContract}. 136 * 137 */ 138 public final static class Builder 139 implements Serializable, ModelBuilder, NaturalLanguageUsageContract 140 { 141 142 private String name; 143 private String description; 144 private String namespace; 145 private String id; 146 private boolean active; 147 private Long versionNumber; 148 149 private Builder(String name, String namespace) { 150 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods 151 setName(name); 152 setNamespace(namespace); 153 } 154 155 public static Builder create(String name, String namespace) { 156 // TODO modify as needed to pass any required values and add them to the signature of the 'create' method 157 return new Builder(name, namespace); 158 } 159 160 public static Builder create(NaturalLanguageUsageContract contract) { 161 if (contract == null) { 162 throw new IllegalArgumentException("contract was null"); 163 } 164 // TODO if create() is modified to accept required parameters, this will need to be modified 165 Builder builder = create(contract.getName(), contract.getNamespace()); 166 builder.setId(contract.getId()); 167 builder.setActive(contract.isActive()); 168 builder.setDescription(contract.getDescription()); 169 builder.setVersionNumber(contract.getVersionNumber()); 170 return builder; 171 } 172 173 /** 174 * Builds an instance of a NaturalLanguageUsage based on the current state of the builder. 175 * 176 * @return the fully-constructed NaturalLanguageUsage. 177 * 178 */ 179 public NaturalLanguageUsage build() { 180 return new NaturalLanguageUsage(this); 181 } 182 183 @Override 184 public boolean isActive() { 185 return this.active; 186 } 187 188 @Override 189 public String getDescription() { 190 return this.description; 191 } 192 193 @Override 194 public String getId() { 195 return this.id; 196 } 197 198 @Override 199 public String getName() { 200 return this.name; 201 } 202 203 @Override 204 public String getNamespace() { 205 return this.namespace; 206 } 207 208 @Override 209 public Long getVersionNumber() { 210 return this.versionNumber; 211 } 212 213 /** 214 * Sets the value of active on this builder to the given value. 215 * 216 * @param active the active value to set. 217 * 218 */ 219 public void setActive(boolean active) { 220 this.active = active; 221 } 222 223 /** 224 * Sets the value of description on this builder to the given value. 225 * 226 * @param description the description value to set. 227 * 228 */ 229 public void setDescription(String description) { 230 // TODO add validation of input value if required and throw IllegalArgumentException if needed 231 this.description = description; 232 } 233 234 /** 235 * Sets the value of id on this builder to the given value. 236 * 237 * @param id the id value to set., may be null, representing the Object has not been persisted, but must not be blank. 238 * @throws IllegalArgumentException if the id is blank 239 * 240 */ 241 public void setId(String id) { 242 if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) { 243 throw new IllegalArgumentException("id is blank"); 244 } 245 this.id = id; 246 } 247 248 /** 249 * Sets the value of name on this builder to the given value. 250 * 251 * @param name the name value to set., must not be null or blank 252 * @throws IllegalArgumentException if the name is null or blank 253 * 254 */ 255 public void setName(String name) { 256 if (org.apache.commons.lang.StringUtils.isBlank(name)) { 257 throw new IllegalArgumentException("name is null or blank"); 258 } 259 this.name = name; 260 } 261 262 /** 263 * Sets the value of namespace on this builder to the given value. 264 * 265 * @param namespace the namespace value to set., must not be null or blank 266 * @throws IllegalArgumentException if the namespace is null or blank 267 * 268 */ 269 public void setNamespace(String namespace) { 270 if (org.apache.commons.lang.StringUtils.isBlank(namespace)) { 271 throw new IllegalArgumentException("namespace is null or blank"); 272 } 273 this.namespace = namespace; 274 } 275 276 /** 277 * Sets the value of versionNumber on this builder to the given value. 278 * 279 * @param versionNumber the versionNumber value to set. 280 * 281 */ 282 public void setVersionNumber(Long versionNumber) { 283 this.versionNumber = versionNumber; 284 } 285 286 } 287 288 289 /** 290 * Defines some internal constants used on this class. 291 * 292 */ 293 static class Constants { 294 295 final static String ROOT_ELEMENT_NAME = "naturalLanguageUsage"; 296 final static String TYPE_NAME = "NaturalLanguageUsageType"; 297 298 } 299 300 301 /** 302 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 303 * 304 */ 305 static class Elements { 306 307 final static String NAME = "name"; 308 final static String DESCRIPTION = "description"; 309 final static String NAMESPACE = "namespace"; 310 final static String ID = "id"; 311 final static String ACTIVE = "active"; 312 313 } 314 315 public static class Cache { 316 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + NaturalLanguageUsage.Constants.TYPE_NAME; 317 } 318 319}