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 */
016 package org.kuali.rice.ken.api.notification;
017
018 import java.io.Serializable;
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.List;
022 import javax.xml.bind.annotation.XmlAccessType;
023 import javax.xml.bind.annotation.XmlAccessorType;
024 import javax.xml.bind.annotation.XmlAnyElement;
025 import javax.xml.bind.annotation.XmlElement;
026 import javax.xml.bind.annotation.XmlElementWrapper;
027 import javax.xml.bind.annotation.XmlRootElement;
028 import javax.xml.bind.annotation.XmlType;
029
030 import org.apache.commons.collections.CollectionUtils;
031 import org.kuali.rice.core.api.CoreConstants;
032 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
033 import org.kuali.rice.core.api.mo.ModelBuilder;
034 import org.w3c.dom.Element;
035
036 @XmlRootElement(name = NotificationProducer.Constants.ROOT_ELEMENT_NAME)
037 @XmlAccessorType(XmlAccessType.NONE)
038 @XmlType(name = NotificationProducer.Constants.TYPE_NAME, propOrder = {
039 NotificationProducer.Elements.NAME,
040 NotificationProducer.Elements.DESCRIPTION,
041 NotificationProducer.Elements.CONTACT_INFO,
042 NotificationProducer.Elements.ID,
043 NotificationProducer.Elements.CHANNEL_IDS,
044 CoreConstants.CommonElements.VERSION_NUMBER,
045 CoreConstants.CommonElements.OBJECT_ID,
046 CoreConstants.CommonElements.FUTURE_ELEMENTS
047 })
048 public final class NotificationProducer
049 extends AbstractDataTransferObject
050 implements NotificationProducerContract
051 {
052
053 @XmlElement(name = Elements.NAME, required = false)
054 private final String name;
055 @XmlElement(name = Elements.DESCRIPTION, required = false)
056 private final String description;
057 @XmlElement(name = Elements.CONTACT_INFO, required = false)
058 private final String contactInfo;
059 @XmlElement(name = Elements.ID, required = false)
060 private final Long id;
061 @XmlElementWrapper(name = Elements.CHANNEL_IDS, required = false)
062 @XmlElement(name = Elements.CHANNEL_ID, required = false)
063 private final List<Long> channelIds;
064 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
065 private final Long versionNumber;
066 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
067 private final String objectId;
068 @SuppressWarnings("unused")
069 @XmlAnyElement
070 private final Collection<Element> _futureElements = null;
071
072 /**
073 * Private constructor used only by JAXB.
074 *
075 */
076 private NotificationProducer() {
077 this.name = null;
078 this.description = null;
079 this.contactInfo = null;
080 this.id = null;
081 this.versionNumber = null;
082 this.objectId = null;
083 this.channelIds = null;
084 }
085
086 private NotificationProducer(Builder builder) {
087 this.name = builder.getName();
088 this.description = builder.getDescription();
089 this.contactInfo = builder.getContactInfo();
090 this.id = builder.getId();
091 this.versionNumber = builder.getVersionNumber();
092 this.objectId = builder.getObjectId();
093 this.channelIds = builder.getChannelIds();
094 }
095
096 @Override
097 public String getName() {
098 return this.name;
099 }
100
101 @Override
102 public String getDescription() {
103 return this.description;
104 }
105
106 @Override
107 public String getContactInfo() {
108 return this.contactInfo;
109 }
110
111 @Override
112 public Long getId() {
113 return this.id;
114 }
115
116 @Override
117 public List<Long> getChannelIds() {
118 return this.channelIds;
119 }
120
121 @Override
122 public Long getVersionNumber() {
123 return this.versionNumber;
124 }
125
126 @Override
127 public String getObjectId() {
128 return this.objectId;
129 }
130
131
132 /**
133 * A builder which can be used to construct {@link NotificationProducer} instances. Enforces the constraints of the {@link NotificationProducerContract}.
134 *
135 */
136 public final static class Builder
137 implements Serializable, ModelBuilder, NotificationProducerContract
138 {
139
140 private String name;
141 private String description;
142 private String contactInfo;
143 private Long id;
144 private List<Long> channelIds;
145 private Long versionNumber;
146 private String objectId;
147
148 private Builder() {
149 // TODO modify this constructor as needed to pass any required values and invoke the appropriate 'setter' methods
150 }
151
152 public static Builder create() {
153 // TODO modify as needed to pass any required values and add them to the signature of the 'create' method
154 return new Builder();
155 }
156
157 public static Builder create(NotificationProducerContract contract) {
158 if (contract == null) {
159 throw new IllegalArgumentException("contract was null");
160 }
161 // TODO if create() is modified to accept required parameters, this will need to be modified
162 Builder builder = create();
163 builder.setName(contract.getName());
164 builder.setDescription(contract.getDescription());
165 builder.setContactInfo(contract.getContactInfo());
166 builder.setId(contract.getId());
167 builder.setChannelIds(contract.getChannelIds());
168 builder.setVersionNumber(contract.getVersionNumber());
169 builder.setObjectId(contract.getObjectId());
170 return builder;
171 }
172
173 public NotificationProducer build() {
174 return new NotificationProducer(this);
175 }
176
177 @Override
178 public String getName() {
179 return this.name;
180 }
181
182 @Override
183 public String getDescription() {
184 return this.description;
185 }
186
187 @Override
188 public String getContactInfo() {
189 return this.contactInfo;
190 }
191
192 @Override
193 public Long getId() {
194 return this.id;
195 }
196
197 @Override
198 public List<Long> getChannelIds() {
199 return this.channelIds;
200 }
201
202 @Override
203 public Long getVersionNumber() {
204 return this.versionNumber;
205 }
206
207 @Override
208 public String getObjectId() {
209 return this.objectId;
210 }
211
212 public void setName(String name) {
213 this.name = name;
214 }
215
216 public void setDescription(String description) {
217 this.description = description;
218 }
219
220 public void setContactInfo(String contactInfo) {
221 this.contactInfo = contactInfo;
222 }
223
224 public void setId(Long id) {
225 this.id = id;
226 }
227
228 public void setChannelIds(List<Long> channelIds) {
229 this.channelIds = channelIds;
230 }
231
232 public void setVersionNumber(Long versionNumber) {
233 this.versionNumber = versionNumber;
234 }
235
236 public void setObjectId(String objectId) {
237 this.objectId = objectId;
238 }
239
240 }
241
242
243 /**
244 * Defines some internal constants used on this class.
245 *
246 */
247 static class Constants {
248
249 final static String ROOT_ELEMENT_NAME = "notificationProducer";
250 final static String TYPE_NAME = "NotificationProducerType";
251
252 }
253
254
255 /**
256 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
257 *
258 */
259 static class Elements {
260
261 final static String NAME = "name";
262 final static String DESCRIPTION = "description";
263 final static String CONTACT_INFO = "contactInfo";
264 final static String ID = "id";
265 final static String CHANNEL_IDS = "channelIds";
266 final static String CHANNEL_ID = "channelId";
267
268 }
269
270 }