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