View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.api.notification;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlElementWrapper;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  
30  import org.apache.commons.collections.CollectionUtils;
31  import org.kuali.rice.core.api.CoreConstants;
32  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33  import org.kuali.rice.core.api.mo.ModelBuilder;
34  import org.w3c.dom.Element;
35  
36  @XmlRootElement(name = NotificationProducer.Constants.ROOT_ELEMENT_NAME)
37  @XmlAccessorType(XmlAccessType.NONE)
38  @XmlType(name = NotificationProducer.Constants.TYPE_NAME, propOrder = {
39          NotificationProducer.Elements.NAME,
40          NotificationProducer.Elements.DESCRIPTION,
41          NotificationProducer.Elements.CONTACT_INFO,
42          NotificationProducer.Elements.ID,
43          NotificationProducer.Elements.CHANNEL_IDS,
44          CoreConstants.CommonElements.VERSION_NUMBER,
45          CoreConstants.CommonElements.OBJECT_ID,
46          CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class NotificationProducer
49          extends AbstractDataTransferObject
50          implements NotificationProducerContract
51  {
52  
53      @XmlElement(name = Elements.NAME, required = false)
54      private final String name;
55      @XmlElement(name = Elements.DESCRIPTION, required = false)
56      private final String description;
57      @XmlElement(name = Elements.CONTACT_INFO, required = false)
58      private final String contactInfo;
59      @XmlElement(name = Elements.ID, required = false)
60      private final Long id;
61      @XmlElementWrapper(name = Elements.CHANNEL_IDS, required = false)
62      @XmlElement(name = Elements.CHANNEL_ID, required = false)
63      private final List<Long> channelIds;
64      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
65      private final Long versionNumber;
66      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
67      private final String objectId;
68      @SuppressWarnings("unused")
69      @XmlAnyElement
70      private final Collection<Element> _futureElements = null;
71  
72      /**
73       * Private constructor used only by JAXB.
74       *
75       */
76      private NotificationProducer() {
77          this.name = null;
78          this.description = null;
79          this.contactInfo = null;
80          this.id = null;
81          this.versionNumber = null;
82          this.objectId = null;
83          this.channelIds = null;
84      }
85  
86      private NotificationProducer(Builder builder) {
87          this.name = builder.getName();
88          this.description = builder.getDescription();
89          this.contactInfo = builder.getContactInfo();
90          this.id = builder.getId();
91          this.versionNumber = builder.getVersionNumber();
92          this.objectId = builder.getObjectId();
93          this.channelIds = builder.getChannelIds();
94      }
95  
96      @Override
97      public String getName() {
98          return this.name;
99      }
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 }