001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.server.rpc;
017:
018: import com.google.gwt.user.client.rpc.CollectionsTestService;
019: import com.google.gwt.user.client.rpc.TestSetFactory;
020: import com.google.gwt.user.client.rpc.TestSetValidator;
021:
022: import java.util.ArrayList;
023: import java.util.Arrays;
024: import java.util.Date;
025: import java.util.HashMap;
026: import java.util.HashSet;
027: import java.util.List;
028: import java.util.Vector;
029:
030: /**
031: * TODO: document me.
032: */
033: public class CollectionsTestServiceImpl extends RemoteServiceServlet
034: implements CollectionsTestService {
035:
036: private static String toString(Object[] values) {
037: return Arrays.asList(values).toString();
038: }
039:
040: public ArrayList echo(ArrayList list)
041: throws CollectionsTestServiceException {
042: if (!TestSetValidator.isValid(list)) {
043: throw new CollectionsTestServiceException();
044: }
045:
046: return list;
047: }
048:
049: public boolean[] echo(boolean[] actual)
050: throws CollectionsTestServiceException {
051: boolean[] expected = TestSetFactory
052: .createPrimitiveBooleanArray();
053: if (!TestSetValidator.equals(expected, actual)) {
054: throw new CollectionsTestServiceException("expected:"
055: + expected.toString() + " actual:"
056: + actual.toString());
057: }
058:
059: return actual;
060: }
061:
062: public Boolean[] echo(Boolean[] actual)
063: throws CollectionsTestServiceException {
064: Boolean[] expected = TestSetFactory.createBooleanArray();
065: if (!TestSetValidator.equals(expected, actual)) {
066: throw new CollectionsTestServiceException("expected:"
067: + expected.toString() + " actual:"
068: + actual.toString());
069: }
070:
071: return actual;
072: }
073:
074: public byte[] echo(byte[] actual)
075: throws CollectionsTestServiceException {
076: byte[] expected = TestSetFactory.createPrimitiveByteArray();
077: if (!TestSetValidator.equals(expected, actual)) {
078: throw new CollectionsTestServiceException("expected:"
079: + expected.toString() + " actual:"
080: + actual.toString());
081: }
082:
083: return actual;
084: }
085:
086: public Byte[] echo(Byte[] actual)
087: throws CollectionsTestServiceException {
088: Byte[] expected = TestSetFactory.createByteArray();
089: if (!TestSetValidator.equals(expected, actual)) {
090: throw new CollectionsTestServiceException("expected:"
091: + expected.toString() + " actual:"
092: + actual.toString());
093: }
094:
095: return actual;
096: }
097:
098: public char[] echo(char[] actual)
099: throws CollectionsTestServiceException {
100: char[] expected = TestSetFactory.createPrimitiveCharArray();
101: if (!TestSetValidator.equals(expected, actual)) {
102: throw new CollectionsTestServiceException("expected:"
103: + expected.toString() + " actual:"
104: + actual.toString());
105: }
106:
107: return actual;
108: }
109:
110: public Character[] echo(Character[] actual)
111: throws CollectionsTestServiceException {
112: Character[] expected = TestSetFactory.createCharArray();
113: if (!TestSetValidator.equals(expected, actual)) {
114: throw new CollectionsTestServiceException("expected:"
115: + expected.toString() + " actual:"
116: + actual.toString());
117: }
118:
119: return actual;
120: }
121:
122: public Date[] echo(Date[] actual)
123: throws CollectionsTestServiceException {
124: Date[] expected = TestSetFactory.createDateArray();
125: if (!TestSetValidator.equals(expected, actual)) {
126: throw new CollectionsTestServiceException("expected:"
127: + toString(expected) + " actual:"
128: + toString(actual));
129: }
130:
131: return actual;
132: }
133:
134: public double[] echo(double[] actual)
135: throws CollectionsTestServiceException {
136: double[] expected = TestSetFactory.createPrimitiveDoubleArray();
137: if (!TestSetValidator.equals(expected, actual)) {
138: throw new CollectionsTestServiceException("expected:"
139: + expected.toString() + " actual:"
140: + actual.toString());
141: }
142:
143: return actual;
144: }
145:
146: public Double[] echo(Double[] actual)
147: throws CollectionsTestServiceException {
148: Double[] expected = TestSetFactory.createDoubleArray();
149: if (!TestSetValidator.equals(expected, actual)) {
150: throw new CollectionsTestServiceException("expected:"
151: + expected.toString() + " actual:"
152: + actual.toString());
153: }
154:
155: return actual;
156: }
157:
158: public float[] echo(float[] actual)
159: throws CollectionsTestServiceException {
160: float[] expected = TestSetFactory.createPrimitiveFloatArray();
161: if (!TestSetValidator.equals(expected, actual)) {
162: throw new CollectionsTestServiceException("expected:"
163: + expected.toString() + " actual:"
164: + actual.toString());
165: }
166:
167: return actual;
168: }
169:
170: public Float[] echo(Float[] actual)
171: throws CollectionsTestServiceException {
172: Float[] expected = TestSetFactory.createFloatArray();
173: if (!TestSetValidator.equals(expected, actual)) {
174: throw new CollectionsTestServiceException("expected:"
175: + expected.toString() + " actual:"
176: + actual.toString());
177: }
178:
179: return actual;
180: }
181:
182: public HashMap echo(HashMap actual)
183: throws CollectionsTestServiceException {
184: HashMap expected = TestSetFactory.createHashMap();
185: if (!TestSetValidator.isValid(expected, actual)) {
186: throw new CollectionsTestServiceException("expected:"
187: + expected.toString() + " actual:"
188: + actual.toString());
189: }
190:
191: return actual;
192: }
193:
194: public HashSet echo(HashSet actual)
195: throws CollectionsTestServiceException {
196: HashSet expected = TestSetFactory.createHashSet();
197: if (!TestSetValidator.isValid(expected, actual)) {
198: throw new CollectionsTestServiceException("expected:"
199: + expected.toString() + " actual:"
200: + actual.toString());
201: }
202:
203: return actual;
204: }
205:
206: public int[] echo(int[] actual)
207: throws CollectionsTestServiceException {
208: int[] expected = TestSetFactory.createPrimitiveIntegerArray();
209: if (!TestSetValidator.equals(expected, actual)) {
210: throw new CollectionsTestServiceException("expected:"
211: + expected.toString() + " actual:"
212: + actual.toString());
213: }
214:
215: return actual;
216: }
217:
218: public Integer[] echo(Integer[] actual)
219: throws CollectionsTestServiceException {
220: Integer[] expected = TestSetFactory.createIntegerArray();
221: if (!TestSetValidator.equals(expected, actual)) {
222: throw new CollectionsTestServiceException("expected:"
223: + expected.toString() + " actual:"
224: + actual.toString());
225: }
226:
227: return actual;
228: }
229:
230: public long[] echo(long[] actual)
231: throws CollectionsTestServiceException {
232: long[] expected = TestSetFactory.createPrimitiveLongArray();
233: if (!TestSetValidator.equals(expected, actual)) {
234: throw new CollectionsTestServiceException("expected:"
235: + expected.toString() + " actual:"
236: + actual.toString());
237: }
238:
239: return actual;
240: }
241:
242: public Long[] echo(Long[] actual)
243: throws CollectionsTestServiceException {
244: Long[] expected = TestSetFactory.createLongArray();
245: if (!TestSetValidator.equals(expected, actual)) {
246: throw new CollectionsTestServiceException("expected:"
247: + toString(expected) + " actual:"
248: + toString(actual));
249: }
250:
251: return actual;
252: }
253:
254: public short[] echo(short[] actual)
255: throws CollectionsTestServiceException {
256: short[] expected = TestSetFactory.createPrimitiveShortArray();
257: if (!TestSetValidator.equals(expected, actual)) {
258: throw new CollectionsTestServiceException("expected:"
259: + expected.toString() + " actual:"
260: + actual.toString());
261: }
262:
263: return actual;
264: }
265:
266: public Short[] echo(Short[] actual)
267: throws CollectionsTestServiceException {
268: Short[] expected = TestSetFactory.createShortArray();
269: if (!TestSetValidator.equals(expected, actual)) {
270: throw new CollectionsTestServiceException("expected:"
271: + expected.toString() + " actual:"
272: + actual.toString());
273: }
274:
275: return actual;
276: }
277:
278: public String[] echo(String[] actual)
279: throws CollectionsTestServiceException {
280: String[] expected = TestSetFactory.createStringArray();
281: if (!TestSetValidator.equals(expected, actual)) {
282: throw new CollectionsTestServiceException("expected:"
283: + expected.toString() + " actual:"
284: + actual.toString());
285: }
286:
287: return actual;
288: }
289:
290: public String[][] echo(String[][] value)
291: throws CollectionsTestServiceException {
292: return value;
293: }
294:
295: public Vector echo(Vector actual)
296: throws CollectionsTestServiceException {
297: Vector expected = TestSetFactory.createVector();
298: if (!TestSetValidator.isValid(expected, actual)) {
299: throw new CollectionsTestServiceException("expected:"
300: + expected.toString() + " actual:"
301: + actual.toString());
302: }
303:
304: return actual;
305: }
306:
307: /**
308: * Return the result of Arrays.asList(Object[]) to force an
309: * InvocationException on the client.
310: */
311: public List getArraysAsList(List value) {
312: Byte[] retVal = new Byte[10];
313: for (byte i = 0; i < 10; ++i) {
314: retVal[i] = (Byte) value.get(i);
315: }
316:
317: return Arrays.asList(retVal);
318: }
319: }
|