001/**
002 * Copyright 2005-2017 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.kim.api.type;
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.kim.api.common.attribute.KimAttribute;
022import org.w3c.dom.Element;
023
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 * An immutable representation of a {@link KimTypeAttributeContract}.
035 *
036 * <p>To construct an instance of a KimTypeAttribute, use the {@link KimTypeAttribute.Builder} class.<p/>
037 *
038 * @see KimTypeAttributeContract
039 */
040@XmlRootElement(name = KimTypeAttribute.Constants.ROOT_ELEMENT_NAME)
041@XmlAccessorType(XmlAccessType.NONE)
042@XmlType(name = KimTypeAttribute.Constants.TYPE_NAME, propOrder = {
043        KimTypeAttribute.Elements.ID,
044        KimTypeAttribute.Elements.SORT_CODE,
045        KimTypeAttribute.Elements.KIM_ATTRIBUTE,
046        KimTypeAttribute.Elements.KIM_TYPE_ID,
047        KimTypeAttribute.Elements.ACTIVE,
048        CoreConstants.CommonElements.VERSION_NUMBER,
049        CoreConstants.CommonElements.OBJECT_ID,
050        CoreConstants.CommonElements.FUTURE_ELEMENTS
051})
052public final class KimTypeAttribute extends AbstractDataTransferObject implements KimTypeAttributeContract {
053    private static final long serialVersionUID = 1L;
054
055    @XmlElement(name = KimTypeAttribute.Elements.ID, required = false)
056    private final String id;
057
058    @XmlElement(name = KimTypeAttribute.Elements.SORT_CODE, required = false)
059    private final String sortCode;
060
061    @XmlElement(name = KimTypeAttribute.Elements.KIM_ATTRIBUTE, required = false)
062    private final KimAttribute kimAttribute;
063
064    @XmlElement(name = KimTypeAttribute.Elements.KIM_TYPE_ID, required = false)
065    private final String kimTypeId;
066
067    @XmlElement(name = KimTypeAttribute.Elements.ACTIVE, required = false)
068    private final boolean active;
069
070    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
071    private final Long versionNumber;
072
073    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
074    private final String objectId;
075
076    @SuppressWarnings("unused")
077    @XmlAnyElement
078    private final Collection<Element> _futureElements = null;
079
080    /**
081     * This constructor should never be called except during JAXB unmarshalling.
082     */
083    private KimTypeAttribute() {
084        this.id = null;
085        this.sortCode = null;
086        this.kimAttribute = null;
087        this.kimTypeId = null;
088        this.active = false;
089        this.versionNumber = Long.valueOf(1L);
090        this.objectId = null;
091    }
092
093    private KimTypeAttribute(Builder builder) {
094        this.id = builder.getId();
095        this.sortCode = builder.getSortCode();
096
097        this.kimAttribute = builder.getKimAttribute() != null ? builder.getKimAttribute().build() : null;
098        this.kimTypeId = builder.getKimTypeId();
099        this.active = builder.isActive();
100        this.versionNumber = builder.getVersionNumber();
101        this.objectId = builder.getObjectId();
102    }
103
104    @Override
105    public String getId() {
106        return id;
107    }
108
109    @Override
110    public String getSortCode() {
111        return sortCode;
112    }
113
114    @Override
115    public KimAttribute getKimAttribute() {
116        return kimAttribute;
117    }
118
119    @Override
120    public String getKimTypeId() {
121        return kimTypeId;
122    }
123
124    @Override
125    public boolean isActive() {
126        return active;
127    }
128
129    @Override
130    public Long getVersionNumber() {
131        return versionNumber;
132    }
133
134    @Override
135    public String getObjectId() {
136        return objectId;
137    }
138
139    /**
140     * This builder constructs an KimTypeAttribute enforcing the constraints of the {@link KimTypeAttributeContract}.
141     */
142    public static final class Builder implements KimTypeAttributeContract, ModelBuilder, Serializable {
143        private String id;
144        private String sortCode;
145        private KimAttribute.Builder kimAttribute;
146        private String kimTypeId;
147        private boolean active;
148        private Long versionNumber;
149        private String objectId;
150
151        private Builder() {
152        }
153
154        /**
155         * creates a KimTypeAttribute with the required fields.
156         */
157        public static Builder create() {
158            return new Builder();
159        }
160
161        /**
162         * creates a KimTypeAttribute from an existing {@link KimTypeAttributeContract}.
163         */
164        public static Builder create(KimTypeAttributeContract contract) {
165            Builder builder = new Builder();
166            builder.setId(contract.getId());
167            builder.setSortCode(contract.getSortCode());
168            if (contract.getKimAttribute() != null) {
169                builder.setKimAttribute(KimAttribute.Builder.create(contract.getKimAttribute()));
170            }
171            builder.setKimTypeId(contract.getKimTypeId());
172            builder.setActive(contract.isActive());
173            builder.setVersionNumber(contract.getVersionNumber());
174            builder.setObjectId(contract.getObjectId());
175            return builder;
176        }
177
178        @Override
179        public String getId() {
180            return id;
181        }
182
183        public void setId(final String id) {
184            this.id = id;
185        }
186
187        @Override
188        public String getSortCode() {
189            return sortCode;
190        }
191
192        public void setSortCode(final String sortCode) {
193            this.sortCode = sortCode;
194        }
195
196        @Override
197        public KimAttribute.Builder getKimAttribute() {
198            return kimAttribute;
199        }
200
201        public void setKimAttribute(final KimAttribute.Builder kimAttribute) {
202            this.kimAttribute = kimAttribute;
203        }
204
205        @Override
206        public String getKimTypeId() {
207            return kimTypeId;
208        }
209
210        public void setKimTypeId(final String kimTypeId) {
211            this.kimTypeId = kimTypeId;
212        }
213
214        @Override
215        public boolean isActive() {
216            return active;
217        }
218
219        public void setActive(final boolean active) {
220            this.active = active;
221        }
222
223        @Override
224        public Long getVersionNumber() {
225            return versionNumber;
226        }
227
228        public void setVersionNumber(final Long versionNumber) {
229            this.versionNumber = versionNumber;
230        }
231
232        @Override
233        public String getObjectId() {
234            return objectId;
235        }
236
237        public void setObjectId(final String objectId) {
238            this.objectId = objectId;
239        }
240
241        @Override
242        public KimTypeAttribute build() {
243            return new KimTypeAttribute(this);
244        }
245    }
246
247    /**
248     * Defines some internal constants used on this class.
249     */
250    static class Constants {
251        static final String ROOT_ELEMENT_NAME = "kimTypeAttribute";
252        static final String TYPE_NAME = "KimTypeAttributeType";
253    }
254
255    /**
256     * A private class which exposes constants which define the XML element names to use
257     * when this object is marshalled to XML.
258     */
259    static class Elements {
260        static final String ID = "id";
261        static final String SORT_CODE = "sortCode";
262        static final String KIM_ATTRIBUTE = "kimAttribute";
263        static final String KIM_TYPE_ID = "kimTypeId";
264        static final String ACTIVE = "active";
265    }
266}