001/**
002 * Copyright 2005-2014 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.reference;
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;
022
023import javax.xml.bind.Element;
024import javax.xml.bind.annotation.XmlAccessType;
025import javax.xml.bind.annotation.XmlAccessorType;
026import javax.xml.bind.annotation.XmlAnyElement;
027import javax.xml.bind.annotation.XmlElement;
028import javax.xml.bind.annotation.XmlRootElement;
029import javax.xml.bind.annotation.XmlType;
030import java.io.Serializable;
031import java.util.Collection;
032
033/**
034 * Generated using JVM arguments -DNOT_BLANK=krmsObjectId,krmsDiscriminatorType,referenceObjectId,referenceDiscriminatorType 
035 * Concrete model object implementation, immutable. 
036 * Instances can be (un)marshalled to and from XML.
037 * 
038 * @see ReferenceObjectBindingContract
039 * 
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 * 
042 */
043@XmlRootElement(name = ReferenceObjectBinding.Constants.ROOT_ELEMENT_NAME)
044@XmlAccessorType(XmlAccessType.NONE)
045@XmlType(name = ReferenceObjectBinding.Constants.TYPE_NAME, propOrder = {
046    ReferenceObjectBinding.Elements.COLLECTION_NAME,
047    ReferenceObjectBinding.Elements.KRMS_DISCRIMINATOR_TYPE,
048    ReferenceObjectBinding.Elements.KRMS_OBJECT_ID,
049    ReferenceObjectBinding.Elements.NAMESPACE,
050    ReferenceObjectBinding.Elements.REFERENCE_DISCRIMINATOR_TYPE,
051    ReferenceObjectBinding.Elements.REFERENCE_OBJECT_ID,
052    ReferenceObjectBinding.Elements.ID,
053    ReferenceObjectBinding.Elements.ACTIVE,
054    CoreConstants.CommonElements.VERSION_NUMBER,
055    CoreConstants.CommonElements.FUTURE_ELEMENTS
056})
057public final class ReferenceObjectBinding
058    extends AbstractDataTransferObject
059    implements ReferenceObjectBindingContract
060{
061
062    @XmlElement(name = Elements.COLLECTION_NAME, required = false)
063    private final String collectionName;
064    @XmlElement(name = Elements.KRMS_DISCRIMINATOR_TYPE, required = false)
065    private final String krmsDiscriminatorType;
066    @XmlElement(name = Elements.KRMS_OBJECT_ID, required = false)
067    private final String krmsObjectId;
068    @XmlElement(name = Elements.NAMESPACE, required = false)
069    private final String namespace;
070    @XmlElement(name = Elements.REFERENCE_DISCRIMINATOR_TYPE, required = false)
071    private final String referenceDiscriminatorType;
072    @XmlElement(name = Elements.REFERENCE_OBJECT_ID, required = false)
073    private final String referenceObjectId;
074    @XmlElement(name = Elements.ID, required = false)
075    private final String id;
076    @XmlElement(name = Elements.ACTIVE, required = false)
077    private final boolean active;
078    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
079    private final Long versionNumber;
080    @SuppressWarnings("unused")
081    @XmlAnyElement
082    private final Collection<Element> _futureElements = null;
083
084    /**
085     * Private constructor used only by JAXB. This constructor should never be called.
086     * It is only present for use during JAXB unmarshalling.
087     * 
088     */
089    private ReferenceObjectBinding() {
090        this.collectionName = null;
091        this.krmsDiscriminatorType = null;
092        this.krmsObjectId = null;
093        this.namespace = null;
094        this.referenceDiscriminatorType = null;
095        this.referenceObjectId = null;
096        this.id = null;
097        this.active = false;
098        this.versionNumber = null;
099    }
100
101    /**
102     * Constructs an object from the given builder.  This constructor is private and should only ever be invoked from the builder.
103     * 
104     * @param builder the Builder from which to construct the object.
105     * 
106     */
107    private ReferenceObjectBinding(Builder builder) {
108        this.collectionName = builder.getCollectionName();
109        this.krmsDiscriminatorType = builder.getKrmsDiscriminatorType();
110        this.krmsObjectId = builder.getKrmsObjectId();
111        this.namespace = builder.getNamespace();
112        this.referenceDiscriminatorType = builder.getReferenceDiscriminatorType();
113        this.referenceObjectId = builder.getReferenceObjectId();
114        this.id = builder.getId();
115        this.active = builder.isActive();
116        this.versionNumber = builder.getVersionNumber();
117    }
118
119    @Override
120    public String getCollectionName() {
121        return this.collectionName;
122    }
123
124    @Override
125    public String getKrmsDiscriminatorType() {
126        return this.krmsDiscriminatorType;
127    }
128
129    @Override
130    public String getKrmsObjectId() {
131        return this.krmsObjectId;
132    }
133
134    @Override
135    public String getNamespace() {
136        return this.namespace;
137    }
138
139    @Override
140    public String getReferenceDiscriminatorType() {
141        return this.referenceDiscriminatorType;
142    }
143
144    @Override
145    public String getReferenceObjectId() {
146        return this.referenceObjectId;
147    }
148
149    @Override
150    public String getId() {
151        return this.id;
152    }
153
154    @Override
155    public boolean isActive() {
156        return this.active;
157    }
158
159    @Override
160    public Long getVersionNumber() {
161        return this.versionNumber;
162    }
163
164
165    /**
166     * A builder which can be used to construct {@link ReferenceObjectBinding} instances.  Enforces the constraints of the {@link ReferenceObjectBindingContract}.
167     * 
168     */
169    public final static class Builder
170        implements Serializable, ModelBuilder, ReferenceObjectBindingContract
171    {
172
173        private String collectionName;
174        private String krmsDiscriminatorType;
175        private String krmsObjectId;
176        private String namespace;
177        private String referenceDiscriminatorType;
178        private String referenceObjectId;
179        private String id;
180        private boolean active;
181        private Long versionNumber;
182
183        private Builder(String krmsDiscriminatorType, String krmsObjectId, String namespace, String referenceDiscriminatorType, String referenceObjectId) {
184            // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
185            setKrmsDiscriminatorType(krmsDiscriminatorType);
186            setKrmsObjectId(krmsObjectId);
187            setNamespace(namespace);
188            setReferenceDiscriminatorType(referenceDiscriminatorType);
189            setReferenceObjectId(referenceObjectId);
190        }
191
192        public static Builder create(String krmsDiscriminatorType, String krmsObjectId, String namespace, String referenceDiscriminatorType, String referenceObjectId) {
193            // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
194            return new Builder(krmsDiscriminatorType, krmsObjectId, namespace, referenceDiscriminatorType, referenceObjectId);
195        }
196
197        public static Builder create(ReferenceObjectBindingContract contract) {
198            if (contract == null) {
199                throw new IllegalArgumentException("contract was null");
200            }
201            // TODO if create() is modified to accept required parameters, this will need to be modified
202            Builder builder = create(contract.getKrmsDiscriminatorType(), contract.getKrmsObjectId(), contract.getNamespace(), contract.getReferenceDiscriminatorType(), contract.getReferenceObjectId());
203            builder.setId(contract.getId());
204            builder.setActive(contract.isActive());
205            builder.setCollectionName(contract.getCollectionName());
206            builder.setVersionNumber(contract.getVersionNumber());
207            return builder;
208        }
209
210        /**
211         * Builds an instance of a ReferenceObjectBinding based on the current state of the builder.
212         * 
213         * @return the fully-constructed ReferenceObjectBinding.
214         * 
215         */
216        public ReferenceObjectBinding build() {
217            return new ReferenceObjectBinding(this);
218        }
219
220        @Override
221        public boolean isActive() {
222            return this.active;
223        }
224
225        @Override
226        public String getCollectionName() {
227            return this.collectionName;
228        }
229
230        @Override
231        public String getId() {
232            return this.id;
233        }
234
235        @Override
236        public String getKrmsDiscriminatorType() {
237            return this.krmsDiscriminatorType;
238        }
239
240        @Override
241        public String getKrmsObjectId() {
242            return this.krmsObjectId;
243        }
244
245        @Override
246        public String getNamespace() {
247            return this.namespace;
248        }
249
250        @Override
251        public String getReferenceDiscriminatorType() {
252            return this.referenceDiscriminatorType;
253        }
254
255        @Override
256        public String getReferenceObjectId() {
257            return this.referenceObjectId;
258        }
259
260        @Override
261        public Long getVersionNumber() {
262            return this.versionNumber;
263        }
264
265        /**
266         * Sets the value of active on this builder to the given value.
267         * 
268         * @param active the active value to set.
269         * 
270         */
271        public void setActive(boolean active) {
272            this.active = active;
273        }
274
275        /**
276         * Sets the value of collectionName on this builder to the given value.
277         * 
278         * @param collectionName the collectionName value to set.
279         * 
280         */
281        public void setCollectionName(String collectionName) {
282            // TODO add validation of input value if required and throw IllegalArgumentException if needed
283            this.collectionName = collectionName;
284        }
285
286        /**
287         * Sets the value of id on this builder to the given value.
288         * 
289         * @param id the id value to set., may be null, representing the Object has not been persisted, but must not be blank.
290         * @throws IllegalArgumentException if the id is blank
291         * 
292         */
293        public void setId(String id) {
294            if (id != null && org.apache.commons.lang.StringUtils.isBlank(id)) {
295                throw new IllegalArgumentException("id is blank");
296            }
297            this.id = id;
298        }
299
300        /**
301         * Sets the value of krmsDiscriminatorType on this builder to the given value.
302         * 
303         * @param krmsDiscriminatorType the krmsDiscriminatorType value to set., must not be null or blank
304         * @throws IllegalArgumentException if the krmsDiscriminatorType is null or blank
305         * 
306         */
307        public void setKrmsDiscriminatorType(String krmsDiscriminatorType) {
308            if (org.apache.commons.lang.StringUtils.isBlank(krmsDiscriminatorType)) {
309                throw new IllegalArgumentException("krmsDiscriminatorType is null or blank");
310            }
311            this.krmsDiscriminatorType = krmsDiscriminatorType;
312        }
313
314        /**
315         * Sets the value of krmsObjectId on this builder to the given value.
316         * 
317         * @param krmsObjectId the krmsObjectId value to set., must not be null or blank
318         * @throws IllegalArgumentException if the krmsObjectId is null or blank
319         * 
320         */
321        public void setKrmsObjectId(String krmsObjectId) {
322            if (org.apache.commons.lang.StringUtils.isBlank(krmsObjectId)) {
323                throw new IllegalArgumentException("krmsObjectId is null or blank");
324            }
325            this.krmsObjectId = krmsObjectId;
326        }
327
328        /**
329         * Sets the value of namespace on this builder to the given value.
330         * 
331         * @param namespace the namespace value to set., must not be null or blank
332         * @throws IllegalArgumentException if the namespace is null or blank
333         * 
334         */
335        public void setNamespace(String namespace) {
336            if (org.apache.commons.lang.StringUtils.isBlank(namespace)) {
337                throw new IllegalArgumentException("namespace is null or blank");
338            }
339            this.namespace = namespace;
340        }
341
342        /**
343         * Sets the value of referenceDiscriminatorType on this builder to the given value.
344         * 
345         * @param referenceDiscriminatorType the referenceDiscriminatorType value to set., must not be null or blank
346         * @throws IllegalArgumentException if the referenceDiscriminatorType is null or blank
347         * 
348         */
349        public void setReferenceDiscriminatorType(String referenceDiscriminatorType) {
350            if (org.apache.commons.lang.StringUtils.isBlank(referenceDiscriminatorType)) {
351                throw new IllegalArgumentException("referenceDiscriminatorType is null or blank");
352            }
353            this.referenceDiscriminatorType = referenceDiscriminatorType;
354        }
355
356        /**
357         * Sets the value of referenceObjectId on this builder to the given value.
358         * 
359         * @param referenceObjectId the referenceObjectId value to set., must not be null or blank
360         * @throws IllegalArgumentException if the referenceObjectId is null or blank
361         * 
362         */
363        public void setReferenceObjectId(String referenceObjectId) {
364            if (org.apache.commons.lang.StringUtils.isBlank(referenceObjectId)) {
365                throw new IllegalArgumentException("referenceObjectId is null or blank");
366            }
367            this.referenceObjectId = referenceObjectId;
368        }
369
370        /**
371         * Sets the value of versionNumber on this builder to the given value.
372         * 
373         * @param versionNumber the versionNumber value to set.
374         * 
375         */
376        public void setVersionNumber(Long versionNumber) {
377            this.versionNumber = versionNumber;
378        }
379
380    }
381
382
383    /**
384     * Defines some internal constants used on this class.
385     * 
386     */
387    static class Constants {
388
389        final static String ROOT_ELEMENT_NAME = "referenceObjectBinding";
390        final static String TYPE_NAME = "ReferenceObjectBindingType";
391
392    }
393
394
395    /**
396     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
397     * 
398     */
399    static class Elements {
400
401        final static String COLLECTION_NAME = "collectionName";
402        final static String KRMS_DISCRIMINATOR_TYPE = "krmsDiscriminatorType";
403        final static String KRMS_OBJECT_ID = "krmsObjectId";
404        final static String NAMESPACE = "namespace";
405        final static String REFERENCE_DISCRIMINATOR_TYPE = "referenceDiscriminatorType";
406        final static String REFERENCE_OBJECT_ID = "referenceObjectId";
407        final static String ID = "id";
408        final static String ACTIVE = "active";
409
410    }
411
412    public static class Cache {
413        public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + ReferenceObjectBinding.Constants.TYPE_NAME;
414    }
415
416}