View Javadoc
1   /**
2    * Copyright 2005-2015 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.Collection;
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAnyElement;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  import org.kuali.rice.core.api.CoreConstants;
27  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
28  import org.kuali.rice.core.api.mo.ModelBuilder;
29  import org.w3c.dom.Element;
30  
31  @XmlRootElement(name = NotificationSender.Constants.ROOT_ELEMENT_NAME)
32  @XmlAccessorType(XmlAccessType.NONE)
33  @XmlType(name = NotificationSender.Constants.TYPE_NAME, propOrder = {
34          NotificationSender.Elements.NOTIFICATION_ID,
35          NotificationSender.Elements.SENDER_NAME,
36          NotificationSender.Elements.ID,
37          CoreConstants.CommonElements.VERSION_NUMBER,
38          CoreConstants.CommonElements.OBJECT_ID,
39          CoreConstants.CommonElements.FUTURE_ELEMENTS
40  })
41  public final class NotificationSender
42          extends AbstractDataTransferObject
43          implements NotificationSenderContract
44  {
45  
46      @XmlElement(name = Elements.NOTIFICATION_ID, required = false)
47      private final Long notificationId;
48      @XmlElement(name = Elements.SENDER_NAME, required = false)
49      private final String senderName;
50      @XmlElement(name = Elements.ID, required = false)
51      private final Long id;
52      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
53      private final Long versionNumber;
54      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
55      private final String objectId;
56      @SuppressWarnings("unused")
57      @XmlAnyElement
58      private final Collection<Element> _futureElements = null;
59  
60      /**
61       * Private constructor used only by JAXB.
62       *
63       */
64      private NotificationSender() {
65          this.notificationId = null;
66          this.senderName = null;
67          this.id = null;
68          this.versionNumber = null;
69          this.objectId = null;
70      }
71  
72      private NotificationSender(Builder builder) {
73          this.notificationId = builder.getNotificationId();
74          this.senderName = builder.getSenderName();
75          this.id = builder.getId();
76          this.versionNumber = builder.getVersionNumber();
77          this.objectId = builder.getObjectId();
78      }
79  
80      @Override
81      public Long getNotificationId() {
82          return this.notificationId;
83      }
84  
85      @Override
86      public String getSenderName() {
87          return this.senderName;
88      }
89  
90      @Override
91      public Long getId() {
92          return this.id;
93      }
94  
95      @Override
96      public Long getVersionNumber() {
97          return this.versionNumber;
98      }
99  
100     @Override
101     public String getObjectId() {
102         return this.objectId;
103     }
104 
105 
106     /**
107      * A builder which can be used to construct {@link NotificationSender} instances.  Enforces the constraints of the {@link NotificationSenderContract}.
108      *
109      */
110     public final static class Builder
111             implements Serializable, ModelBuilder, NotificationSenderContract
112     {
113 
114         private Long notificationId;
115         private String senderName;
116         private Long id;
117         private Long versionNumber;
118         private String objectId;
119 
120         private Builder() {
121         }
122 
123         public static Builder create() {
124             return new Builder();
125         }
126 
127         public static Builder create(NotificationSenderContract contract) {
128             if (contract == null) {
129                 throw new IllegalArgumentException("contract was null");
130             }
131             Builder builder = create();
132             builder.setNotificationId(contract.getNotificationId());
133             builder.setSenderName(contract.getSenderName());
134             builder.setId(contract.getId());
135             builder.setVersionNumber(contract.getVersionNumber());
136             builder.setObjectId(contract.getObjectId());
137             return builder;
138         }
139 
140         public NotificationSender build() {
141             return new NotificationSender(this);
142         }
143 
144         @Override
145         public Long getNotificationId() {
146             return this.notificationId;
147         }
148 
149         @Override
150         public String getSenderName() {
151             return this.senderName;
152         }
153 
154         @Override
155         public Long getId() {
156             return this.id;
157         }
158 
159         @Override
160         public Long getVersionNumber() {
161             return this.versionNumber;
162         }
163 
164         @Override
165         public String getObjectId() {
166             return this.objectId;
167         }
168 
169         public void setNotificationId(Long notificationId) {
170             this.notificationId = notificationId;
171         }
172 
173         public void setSenderName(String senderName) {
174             this.senderName = senderName;
175         }
176 
177         public void setId(Long id) {
178             this.id = id;
179         }
180 
181         public void setVersionNumber(Long versionNumber) {
182             this.versionNumber = versionNumber;
183         }
184 
185         public void setObjectId(String objectId) {
186             this.objectId = objectId;
187         }
188 
189     }
190 
191 
192     /**
193      * Defines some internal constants used on this class.
194      *
195      */
196     static class Constants {
197 
198         final static String ROOT_ELEMENT_NAME = "notificationSender";
199         final static String TYPE_NAME = "NotificationSenderType";
200 
201     }
202 
203 
204     /**
205      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
206      *
207      */
208     static class Elements {
209 
210         final static String NOTIFICATION_ID = "notificationId";
211         final static String SENDER_NAME = "senderName";
212         final static String ID = "id";
213 
214     }
215 
216 }