001 /**
002 * Copyright 2005-2012 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.Collection;
020 import javax.xml.bind.annotation.XmlAccessType;
021 import javax.xml.bind.annotation.XmlAccessorType;
022 import javax.xml.bind.annotation.XmlAnyElement;
023 import javax.xml.bind.annotation.XmlElement;
024 import javax.xml.bind.annotation.XmlRootElement;
025 import javax.xml.bind.annotation.XmlType;
026 import org.kuali.rice.core.api.CoreConstants;
027 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
028 import org.kuali.rice.core.api.mo.ModelBuilder;
029 import org.w3c.dom.Element;
030
031 @XmlRootElement(name = NotificationSender.Constants.ROOT_ELEMENT_NAME)
032 @XmlAccessorType(XmlAccessType.NONE)
033 @XmlType(name = NotificationSender.Constants.TYPE_NAME, propOrder = {
034 NotificationSender.Elements.NOTIFICATION_ID,
035 NotificationSender.Elements.SENDER_NAME,
036 NotificationSender.Elements.ID,
037 CoreConstants.CommonElements.VERSION_NUMBER,
038 CoreConstants.CommonElements.OBJECT_ID,
039 CoreConstants.CommonElements.FUTURE_ELEMENTS
040 })
041 public final class NotificationSender
042 extends AbstractDataTransferObject
043 implements NotificationSenderContract
044 {
045
046 @XmlElement(name = Elements.NOTIFICATION_ID, required = false)
047 private final Long notificationId;
048 @XmlElement(name = Elements.SENDER_NAME, required = false)
049 private final String senderName;
050 @XmlElement(name = Elements.ID, required = false)
051 private final Long id;
052 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
053 private final Long versionNumber;
054 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
055 private final String objectId;
056 @SuppressWarnings("unused")
057 @XmlAnyElement
058 private final Collection<Element> _futureElements = null;
059
060 /**
061 * Private constructor used only by JAXB.
062 *
063 */
064 private NotificationSender() {
065 this.notificationId = null;
066 this.senderName = null;
067 this.id = null;
068 this.versionNumber = null;
069 this.objectId = null;
070 }
071
072 private NotificationSender(Builder builder) {
073 this.notificationId = builder.getNotificationId();
074 this.senderName = builder.getSenderName();
075 this.id = builder.getId();
076 this.versionNumber = builder.getVersionNumber();
077 this.objectId = builder.getObjectId();
078 }
079
080 @Override
081 public Long getNotificationId() {
082 return this.notificationId;
083 }
084
085 @Override
086 public String getSenderName() {
087 return this.senderName;
088 }
089
090 @Override
091 public Long getId() {
092 return this.id;
093 }
094
095 @Override
096 public Long getVersionNumber() {
097 return this.versionNumber;
098 }
099
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 }