KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > webapp > xmlhttp > Response


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.webapp.xmlhttp;
35
36 /**
37  * The <code>Response</code> class represents a (pseudo-)response ready to be
38  * send to the client. </p>
39  * <p/>
40  * Please note that this <code>Response</code> does not represent an HTTP
41  * Response message! </p>
42  */

43 public class Response
44         implements Comparable JavaDoc {
45     private String JavaDoc iceFacesId;
46     private String JavaDoc viewNumber;
47     private long sequenceNumber;
48     private String JavaDoc entityBody;
49
50     /**
51      * Constructs an "empty" <code>Response</code> object. That is a Response
52      * without an Entity-Body. </p>
53      *
54      * @param iceFacesId the new ICEfaces ID.
55      * @param viewNumber the new view number.
56      * @param sequenceNumber the new sequence number.
57      * @throws IllegalArgumentException if the specified
58      * <code>iceFacesId</code> is either
59      * <code>null</code> or empty.
60      * @throws IllegalArgumentException if the specified
61      * <code>sequenceNumber</code> is lesser
62      * than or equal to <code>0</code>.
63      * @throws IllegalArgumentException if the specified <code>viewNumber</code>
64      * is either <code>null</code> or empty.
65      * @see #Response(String,String,long,String)
66      * @see #getICEfacesID()
67      * @see #getViewNumber()
68      * @see #getSequenceNumber()
69      * @see #getEntityBody()
70      */

71     public Response(String JavaDoc iceFacesId, String JavaDoc viewNumber, long sequenceNumber)
72             throws IllegalArgumentException JavaDoc {
73         this(iceFacesId, viewNumber, sequenceNumber, "");
74     }
75
76     /**
77      * Constructs a <code>Response</code> object with the specified
78      * <code>entityBody</code>. </p>
79      *
80      * @param iceFacesId the new ICEfaces ID.
81      * @param viewNumber the new view number.
82      * @param sequenceNumber the new sequence number.
83      * @param entityBody the new Entity-Body.
84      * @throws IllegalArgumentException if the specified <code>iceFacesId</code>
85      * is either <code>null</code> or empty.
86      * @throws IllegalArgumentException if the specified
87      * <code>sequenceNumber</code> is lesser
88      * than or equal to <code>0</code>.
89      * @throws IllegalArgumentException if the specified <code>viewNumber</code>
90      * is either <code>null</code> or empty.
91      * @see #Response(String,String,long)
92      * @see #getICEfacesID()
93      * @see #getViewNumber()
94      * @see #getSequenceNumber()
95      * @see #getEntityBody()
96      */

97     public Response(
98             String JavaDoc iceFacesId, String JavaDoc viewNumber, long sequenceNumber,
99             String JavaDoc entityBody)
100             throws IllegalArgumentException JavaDoc {
101         if (iceFacesId == null) {
102             throw new IllegalArgumentException JavaDoc("iceFacesId is null");
103         }
104         if (iceFacesId.trim().length() == 0) {
105             throw new IllegalArgumentException JavaDoc("iceFacesId is empty");
106         }
107         if (viewNumber == null) {
108             throw new IllegalArgumentException JavaDoc("viewNumber is null");
109         }
110         if (viewNumber.trim().length() == 0) {
111             throw new IllegalArgumentException JavaDoc("viewNumber is empty");
112         }
113         if (sequenceNumber <= 0) {
114             throw new IllegalArgumentException JavaDoc("sequenceNumber <= 0");
115         }
116         this.iceFacesId = iceFacesId;
117         this.viewNumber = viewNumber;
118         this.sequenceNumber = sequenceNumber;
119         this.entityBody = entityBody != null ? entityBody : "";
120     }
121
122     public int compareTo(Object JavaDoc object)
123             throws ClassCastException JavaDoc {
124         if (!(object instanceof Response)) {
125             throw new ClassCastException JavaDoc("object is not a Response");
126         }
127         Response _response = (Response) object;
128         int _result;
129         if ((_result = iceFacesId.compareTo(_response.iceFacesId)) != 0) {
130             return _result;
131         }
132         if ((_result = viewNumber.compareTo(_response.viewNumber)) != 0) {
133             return _result;
134         }
135         if (sequenceNumber < _response.sequenceNumber) {
136             return -1;
137         } else if (sequenceNumber > _response.sequenceNumber) {
138             return 1;
139         }
140         return 0;
141     }
142
143     /**
144      * Gets the Entity-Body of this <code>Response</code>. </p>
145      *
146      * @return the Entity-Body.
147      */

148     public String JavaDoc getEntityBody() {
149         return entityBody;
150     }
151
152     /**
153      * Gets the ICEfaces ID of this <code>Response</code>. </p>
154      *
155      * @return the ICEfaces ID.
156      */

157     public String JavaDoc getICEfacesID() {
158         return iceFacesId;
159     }
160
161     /**
162      * Gets the sequence number of this <code>Response</code>. </p>
163      *
164      * @return the sequence number.
165      */

166     public long getSequenceNumber() {
167         return sequenceNumber;
168     }
169
170     /**
171      * Gets the view number of this <code>Response</code>. </p>
172      *
173      * @return the view number.
174      */

175     public String JavaDoc getViewNumber() {
176         return viewNumber;
177     }
178
179     /**
180      * Checks to see if this <code>Response</code> is an empty response. That
181      * is, if the Entity-Body is empty. </p>
182      *
183      * @return <code>true</code> if this <code>Response</code> is empty.
184      */

185     public boolean isEmpty() {
186         return entityBody.trim().length() == 0;
187     }
188 }
189
Popular Tags