001 package biweekly.property;
002
003 import java.util.List;
004
005 import biweekly.Warning;
006 import biweekly.component.ICalComponent;
007
008 /*
009 Copyright (c) 2013, Michael Angstadt
010 All rights reserved.
011
012 Redistribution and use in source and binary forms, with or without
013 modification, are permitted provided that the following conditions are met:
014
015 1. Redistributions of source code must retain the above copyright notice, this
016 list of conditions and the following disclaimer.
017 2. Redistributions in binary form must reproduce the above copyright notice,
018 this list of conditions and the following disclaimer in the documentation
019 and/or other materials provided with the distribution.
020
021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
025 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
026 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
027 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
028 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
029 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 */
032
033 /**
034 * <p>
035 * Represents a response to a scheduling request, describing whether the request
036 * was successfully processed or not.
037 * </p>
038 * <p>
039 * Each property instance has a status code. The following status code families
040 * are defined:
041 * <ul>
042 * <li><b>1.x</b> - The request has been received, but is still being processed.
043 * </li>
044 * <li><b>2.x</b> - The request was processed successfully.</li>
045 * <li><b>3.x</b> - There is a client-side problem with the request (such as
046 * some incorrect syntax).</li>
047 * <li><b>4.x</b> - A server-side error occurred.</li>
048 * </ul>
049 * </p>
050 * <p>
051 * <b>Examples:</b>
052 *
053 * <pre class="brush:java">
054 * RequestStatus requestStatus = new RequestStatus("2.0");
055 * requestStatus.setDescription("Success");
056 * </pre>
057 *
058 * </p>
059 * @author Michael Angstadt
060 * @rfc 5545 p.141-3
061 */
062 public class RequestStatus extends ICalProperty {
063 private String statusCode, description, exceptionText;
064
065 /**
066 * Creates a request status property.
067 * @param statusCode the status code (e.g. "1.1.3")
068 */
069 public RequestStatus(String statusCode) {
070 setStatusCode(statusCode);
071 }
072
073 /**
074 * Gets the status code. The following status code families are defined:
075 * <ul>
076 * <li><b>1.x</b> - The request has been received, but is still being
077 * processed.</li>
078 * <li><b>2.x</b> - The request was processed successfully.</li>
079 * <li><b>3.x</b> - There is a client-side problem with the request (such as
080 * some incorrect syntax).</li>
081 * <li><b>4.x</b> - A server-side error occurred.</li>
082 * </ul>
083 * @return the status code (e.g. "1.1.3")
084 */
085 public String getStatusCode() {
086 return statusCode;
087 }
088
089 /**
090 * Sets a status code. The following status code families are defined:
091 * <ul>
092 * <li><b>1.x</b> - The request has been received, but is still being
093 * processed.</li>
094 * <li><b>2.x</b> - The request was processed successfully.</li>
095 * <li><b>3.x</b> - There is a client-side problem with the request (such as
096 * some incorrect syntax).</li>
097 * <li><b>4.x</b> - A server-side error occurred.</li>
098 * </ul>
099 * @param statusCode the status code (e.g. "1.1.3")
100 */
101 public void setStatusCode(String statusCode) {
102 this.statusCode = statusCode;
103 }
104
105 /**
106 * Gets the human-readable description of the status.
107 * @return the description (e.g. "Success") or null if not set
108 */
109 public String getDescription() {
110 return description;
111 }
112
113 /**
114 * Sets a human-readable description of the status.
115 * @param description the description (e.g. "Success") or null to remove
116 */
117 public void setDescription(String description) {
118 this.description = description;
119 }
120
121 /**
122 * Gets any additional data related to the response.
123 * @return the additional data or null if not set
124 */
125 public String getExceptionText() {
126 return exceptionText;
127 }
128
129 /**
130 * Sets any additional data related to the response.
131 * @param exceptionText the additional data or null to remove
132 */
133 public void setExceptionText(String exceptionText) {
134 this.exceptionText = exceptionText;
135 }
136
137 @Override
138 public String getLanguage() {
139 return super.getLanguage();
140 }
141
142 @Override
143 public void setLanguage(String language) {
144 super.setLanguage(language);
145 }
146
147 @Override
148 protected void validate(List<ICalComponent> components, List<Warning> warnings) {
149 if (statusCode == null) {
150 warnings.add(Warning.validate(36));
151 }
152 }
153 }