View Javadoc

1   /**
2    * Copyright 2005-2014 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.kuali.rice.ken.api.KenApiConstants;
30  import org.w3c.dom.Element;
31  
32  @XmlRootElement(name = NotificationResponse.Constants.ROOT_ELEMENT_NAME)
33  @XmlAccessorType(XmlAccessType.NONE)
34  @XmlType(name = NotificationResponse.Constants.TYPE_NAME, propOrder = {
35          NotificationResponse.Elements.MESSAGE,
36          NotificationResponse.Elements.STATUS,
37          NotificationResponse.Elements.NOTIFICATION_ID,
38          CoreConstants.CommonElements.FUTURE_ELEMENTS
39  })
40  public final class NotificationResponse
41          extends AbstractDataTransferObject
42          implements NotificationResponseContract
43  {
44  
45      @XmlElement(name = Elements.MESSAGE, required = false)
46      private final String message;
47      @XmlElement(name = Elements.STATUS, required = false)
48      private final String status;
49      @XmlElement(name = Elements.NOTIFICATION_ID, required = false)
50      private final Long notificationId;
51      @SuppressWarnings("unused")
52      @XmlAnyElement
53      private final Collection<Element> _futureElements = null;
54  
55      /**
56       * Private constructor used only by JAXB.
57       *
58       */
59      private NotificationResponse() {
60          this.message = null;
61          this.status = null;
62          this.notificationId = null;
63      }
64  
65      private NotificationResponse(Builder builder) {
66          this.message = builder.getMessage();
67          this.status = builder.getStatus();
68          this.notificationId = builder.getNotificationId();
69      }
70  
71      @Override
72      public String getMessage() {
73          return this.message;
74      }
75  
76      @Override
77      public String getStatus() {
78          return this.status;
79      }
80  
81      @Override
82      public Long getNotificationId() {
83          return this.notificationId;
84      }
85  
86  
87      /**
88       * A builder which can be used to construct {@link NotificationResponse} instances.  Enforces the constraints of the {@link NotificationResponseContract}.
89       *
90       */
91      public final static class Builder
92              implements Serializable, ModelBuilder, NotificationResponseContract
93      {
94  
95          private String message;
96          private String status;
97          private Long notificationId;
98  
99          private Builder() {
100             this.status = KenApiConstants.RESPONSE_STATUSES.SUCCESS;
101         }
102 
103         public static Builder create() {
104             return new Builder();
105         }
106 
107         public static Builder create(NotificationResponseContract contract) {
108             if (contract == null) {
109                 throw new IllegalArgumentException("contract was null");
110             }
111             Builder builder = create();
112             builder.setMessage(contract.getMessage());
113             builder.setStatus(contract.getStatus());
114             builder.setNotificationId(contract.getNotificationId());
115             return builder;
116         }
117 
118         public NotificationResponse build() {
119             return new NotificationResponse(this);
120         }
121 
122         @Override
123         public String getMessage() {
124             return this.message;
125         }
126 
127         @Override
128         public String getStatus() {
129             return this.status;
130         }
131 
132         @Override
133         public Long getNotificationId() {
134             return this.notificationId;
135         }
136 
137         public void setMessage(String message) {
138             // TODO add validation of input value if required and throw IllegalArgumentException if needed
139             this.message = message;
140         }
141 
142         public void setStatus(String status) {
143             // TODO add validation of input value if required and throw IllegalArgumentException if needed
144             this.status = status;
145         }
146 
147         public void setNotificationId(Long notificationId) {
148             // TODO add validation of input value if required and throw IllegalArgumentException if needed
149             this.notificationId = notificationId;
150         }
151 
152     }
153 
154 
155     /**
156      * Defines some internal constants used on this class.
157      *
158      */
159     static class Constants {
160 
161         final static String ROOT_ELEMENT_NAME = "notificationResponse";
162         final static String TYPE_NAME = "NotificationResponseType";
163 
164     }
165 
166 
167     /**
168      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
169      *
170      */
171     static class Elements {
172 
173         final static String MESSAGE = "message";
174         final static String STATUS = "status";
175         final static String NOTIFICATION_ID = "notificationId";
176 
177     }
178 
179 }