001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.webapp.xmlhttp;
035:
036: /**
037: * The <code>Response</code> class represents a (pseudo-)response ready to be
038: * send to the client. </p>
039: * <p/>
040: * Please note that this <code>Response</code> does not represent an HTTP
041: * Response message! </p>
042: */
043: public class Response implements Comparable {
044: private String iceFacesId;
045: private String viewNumber;
046: private long sequenceNumber;
047: private String entityBody;
048:
049: /**
050: * Constructs an "empty" <code>Response</code> object. That is a Response
051: * without an Entity-Body. </p>
052: *
053: * @param iceFacesId the new ICEfaces ID.
054: * @param viewNumber the new view number.
055: * @param sequenceNumber the new sequence number.
056: * @throws IllegalArgumentException if the specified
057: * <code>iceFacesId</code> is either
058: * <code>null</code> or empty.
059: * @throws IllegalArgumentException if the specified
060: * <code>sequenceNumber</code> is lesser
061: * than or equal to <code>0</code>.
062: * @throws IllegalArgumentException if the specified <code>viewNumber</code>
063: * is either <code>null</code> or empty.
064: * @see #Response(String,String,long,String)
065: * @see #getICEfacesID()
066: * @see #getViewNumber()
067: * @see #getSequenceNumber()
068: * @see #getEntityBody()
069: */
070: public Response(String iceFacesId, String viewNumber,
071: long sequenceNumber) throws IllegalArgumentException {
072: this (iceFacesId, viewNumber, sequenceNumber, "");
073: }
074:
075: /**
076: * Constructs a <code>Response</code> object with the specified
077: * <code>entityBody</code>. </p>
078: *
079: * @param iceFacesId the new ICEfaces ID.
080: * @param viewNumber the new view number.
081: * @param sequenceNumber the new sequence number.
082: * @param entityBody the new Entity-Body.
083: * @throws IllegalArgumentException if the specified <code>iceFacesId</code>
084: * is either <code>null</code> or empty.
085: * @throws IllegalArgumentException if the specified
086: * <code>sequenceNumber</code> is lesser
087: * than or equal to <code>0</code>.
088: * @throws IllegalArgumentException if the specified <code>viewNumber</code>
089: * is either <code>null</code> or empty.
090: * @see #Response(String,String,long)
091: * @see #getICEfacesID()
092: * @see #getViewNumber()
093: * @see #getSequenceNumber()
094: * @see #getEntityBody()
095: */
096: public Response(String iceFacesId, String viewNumber,
097: long sequenceNumber, String entityBody)
098: throws IllegalArgumentException {
099: if (iceFacesId == null) {
100: throw new IllegalArgumentException("iceFacesId is null");
101: }
102: if (iceFacesId.trim().length() == 0) {
103: throw new IllegalArgumentException("iceFacesId is empty");
104: }
105: if (viewNumber == null) {
106: throw new IllegalArgumentException("viewNumber is null");
107: }
108: if (viewNumber.trim().length() == 0) {
109: throw new IllegalArgumentException("viewNumber is empty");
110: }
111: if (sequenceNumber <= 0) {
112: throw new IllegalArgumentException("sequenceNumber <= 0");
113: }
114: this .iceFacesId = iceFacesId;
115: this .viewNumber = viewNumber;
116: this .sequenceNumber = sequenceNumber;
117: this .entityBody = entityBody != null ? entityBody : "";
118: }
119:
120: public int compareTo(Object object) throws ClassCastException {
121: if (!(object instanceof Response)) {
122: throw new ClassCastException("object is not a Response");
123: }
124: Response _response = (Response) object;
125: int _result;
126: if ((_result = iceFacesId.compareTo(_response.iceFacesId)) != 0) {
127: return _result;
128: }
129: if ((_result = viewNumber.compareTo(_response.viewNumber)) != 0) {
130: return _result;
131: }
132: if (sequenceNumber < _response.sequenceNumber) {
133: return -1;
134: } else if (sequenceNumber > _response.sequenceNumber) {
135: return 1;
136: }
137: return 0;
138: }
139:
140: /**
141: * Gets the Entity-Body of this <code>Response</code>. </p>
142: *
143: * @return the Entity-Body.
144: */
145: public String getEntityBody() {
146: return entityBody;
147: }
148:
149: /**
150: * Gets the ICEfaces ID of this <code>Response</code>. </p>
151: *
152: * @return the ICEfaces ID.
153: */
154: public String getICEfacesID() {
155: return iceFacesId;
156: }
157:
158: /**
159: * Gets the sequence number of this <code>Response</code>. </p>
160: *
161: * @return the sequence number.
162: */
163: public long getSequenceNumber() {
164: return sequenceNumber;
165: }
166:
167: /**
168: * Gets the view number of this <code>Response</code>. </p>
169: *
170: * @return the view number.
171: */
172: public String getViewNumber() {
173: return viewNumber;
174: }
175:
176: /**
177: * Checks to see if this <code>Response</code> is an empty response. That
178: * is, if the Entity-Body is empty. </p>
179: *
180: * @return <code>true</code> if this <code>Response</code> is empty.
181: */
182: public boolean isEmpty() {
183: return entityBody.trim().length() == 0;
184: }
185: }
|