001 /**
002 * Copyright 2005-2013 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 = UserChannelSubscription.Constants.ROOT_ELEMENT_NAME)
032 @XmlAccessorType(XmlAccessType.NONE)
033 @XmlType(name = UserChannelSubscription.Constants.TYPE_NAME, propOrder = {
034 UserChannelSubscription.Elements.CHANNEL,
035 UserChannelSubscription.Elements.USER_ID,
036 UserChannelSubscription.Elements.ID,
037 CoreConstants.CommonElements.VERSION_NUMBER,
038 CoreConstants.CommonElements.OBJECT_ID,
039 CoreConstants.CommonElements.FUTURE_ELEMENTS
040 })
041 public final class UserChannelSubscription
042 extends AbstractDataTransferObject
043 implements UserChannelSubscriptionContract
044 {
045
046 @XmlElement(name = Elements.CHANNEL, required = false)
047 private final NotificationChannel channel;
048 @XmlElement(name = Elements.USER_ID, required = false)
049 private final String userId;
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 UserChannelSubscription() {
065 this.channel = null;
066 this.userId = null;
067 this.id = null;
068 this.versionNumber = null;
069 this.objectId = null;
070 }
071
072 private UserChannelSubscription(Builder builder) {
073 this.channel = builder.getChannel() == null ? null : builder.getChannel().build();
074 this.userId = builder.getUserId();
075 this.id = builder.getId();
076 this.versionNumber = builder.getVersionNumber();
077 this.objectId = builder.getObjectId();
078 }
079
080 @Override
081 public NotificationChannel getChannel() {
082 return this.channel;
083 }
084
085 @Override
086 public String getUserId() {
087 return this.userId;
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 UserChannelSubscription} instances. Enforces the constraints of the {@link UserChannelSubscriptionContract}.
108 *
109 */
110 public final static class Builder
111 implements Serializable, ModelBuilder, UserChannelSubscriptionContract
112 {
113
114 private NotificationChannel.Builder channel;
115 private String userId;
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(UserChannelSubscriptionContract contract) {
128 if (contract == null) {
129 throw new IllegalArgumentException("contract was null");
130 }
131 Builder builder = create();
132 builder.setChannel(contract.getChannel() == null ? null : NotificationChannel.Builder.create(contract.getChannel()));
133 builder.setUserId(contract.getUserId());
134 builder.setId(contract.getId());
135 builder.setVersionNumber(contract.getVersionNumber());
136 builder.setObjectId(contract.getObjectId());
137 return builder;
138 }
139
140 public UserChannelSubscription build() {
141 return new UserChannelSubscription(this);
142 }
143
144 @Override
145 public NotificationChannel.Builder getChannel() {
146 return this.channel;
147 }
148
149 @Override
150 public String getUserId() {
151 return this.userId;
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 setChannel(NotificationChannel.Builder channel) {
170 this.channel = channel;
171 }
172
173 public void setUserId(String userId) {
174 this.userId = userId;
175 }
176
177 public void setId(Long id) {
178 this.id = id;
179 }
180
181 public void setVersionNumber(Long versionNumber) {
182 // TODO add validation of input value if required and throw IllegalArgumentException if needed
183 this.versionNumber = versionNumber;
184 }
185
186 public void setObjectId(String objectId) {
187 // TODO add validation of input value if required and throw IllegalArgumentException if needed
188 this.objectId = objectId;
189 }
190
191 }
192
193
194 /**
195 * Defines some internal constants used on this class.
196 *
197 */
198 static class Constants {
199
200 final static String ROOT_ELEMENT_NAME = "userChannelSubscription";
201 final static String TYPE_NAME = "UserChannelSubscriptionType";
202
203 }
204
205
206 /**
207 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
208 *
209 */
210 static class Elements {
211
212 final static String CHANNEL = "channel";
213 final static String USER_ID = "userId";
214 final static String ID = "id";
215
216 }
217
218 }