KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > orb > rmi > RMITestImpl


1 package org.jacorb.test.orb.rmi;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2003 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.jacorb.test.orb.rmi.Boo;
24 import org.jacorb.test.orb.rmi.Foo;
25 import org.jacorb.test.orb.rmi.NegativeArgumentException;
26
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 public class RMITestImpl
30         extends PortableRemoteObject JavaDoc
31         implements RMITestInterface
32 {
33
34     public RMITestImpl()
35         throws java.rmi.RemoteException JavaDoc
36     {
37         super();
38     }
39     
40     public String JavaDoc getString()
41         throws java.rmi.RemoteException JavaDoc
42     {
43             return RMITestUtil.STRING;
44     }
45
46     public String JavaDoc testPrimitiveTypes(boolean flag, char c, byte b,
47                                      short s, int i, long l, float f, double d)
48         throws java.rmi.RemoteException JavaDoc
49     {
50         return RMITestUtil.primitiveTypesToString(flag, c, b, s, i, l, f, d);
51     }
52
53     public String JavaDoc testString(String JavaDoc s)
54         throws java.rmi.RemoteException JavaDoc
55     {
56         return RMITestUtil.echo(s);
57     }
58
59     public RMITestInterface testRMITestInterface(String JavaDoc s, RMITestInterface t)
60         throws java.rmi.RemoteException JavaDoc
61     {
62         return t;
63     }
64
65     public java.rmi.Remote JavaDoc testRemote(String JavaDoc s, java.rmi.Remote JavaDoc t)
66         throws java.rmi.RemoteException JavaDoc
67     {
68         return t;
69     }
70
71     public Foo testSerializable(Foo foo)
72         throws java.rmi.RemoteException JavaDoc
73     {
74         return RMITestUtil.echoFoo(foo);
75     }
76
77     public int[] testIntArray(int[] a)
78         throws java.rmi.RemoteException JavaDoc
79     {
80         for (int i = 0; i < a.length; i++)
81         {
82             a[i]++;
83         }
84         return a;
85     }
86
87     public Foo[] testValueArray(Foo[] a)
88         throws java.rmi.RemoteException JavaDoc
89     {
90         for (int i = 0; i < a.length; i++)
91         {
92             a[i] = RMITestUtil.echoFoo(a[i]);
93         }
94         return a;
95     }
96
97     public String JavaDoc testException(int i)
98         throws NegativeArgumentException, java.rmi.RemoteException JavaDoc
99     {
100         if (i >= 0)
101             return "#" + i;
102         else
103             throw new NegativeArgumentException(i);
104     }
105
106     public Object JavaDoc fooValueToObject(Foo foo)
107         throws java.rmi.RemoteException JavaDoc
108     {
109         return RMITestUtil.echoFoo(foo);
110     }
111
112     public Object JavaDoc booValueToObject(Boo boo)
113         throws java.rmi.RemoteException JavaDoc
114     {
115         return RMITestUtil.echoBoo(boo);
116     }
117
118     public java.util.Vector JavaDoc valueArrayToVector(Foo[] a)
119         throws java.rmi.RemoteException JavaDoc
120     {
121         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
122
123         for (int i = 0; i < a.length; i++)
124         {
125             v.add(RMITestUtil.echoFoo(a[i]));
126         }
127         return v;
128     }
129
130     public Foo[] vectorToValueArray(java.util.Vector JavaDoc v)
131         throws java.rmi.RemoteException JavaDoc
132     {
133         Foo a[] = new Foo[v.size()];
134
135         for (int i = 0; i < a.length; i++)
136         {
137             a[i] = RMITestUtil.echoFoo((Foo)v.elementAt(i));
138         }
139         return a;
140     }
141
142     public Object JavaDoc getException()
143         throws java.rmi.RemoteException JavaDoc
144     {
145         Object JavaDoc obj = null;
146         try
147         {
148             NegativeArgumentException e = new NegativeArgumentException(-7777);
149             throw e;
150         }
151         catch (NegativeArgumentException e)
152         {
153             obj = e;
154         }
155         return obj;
156     }
157
158     public Object JavaDoc getZooValue()
159         throws java.rmi.RemoteException JavaDoc
160     {
161         return new Zoo("outer_zoo",
162                        "returned by getZooValue",
163                        new Zoo("inner_zoo", "inner"));
164     }
165
166     public Object JavaDoc[] testReferenceSharingWithinArray(Object JavaDoc[] a)
167         throws java.rmi.RemoteException JavaDoc
168     {
169         int n = a.length;
170         Object JavaDoc[] b = new Object JavaDoc[2 * n];
171         for (int i = 0; i < n; i++)
172             b[i + n] = b[i] = a[i];
173         return b;
174     }
175
176     public java.util.Collection JavaDoc testReferenceSharingWithinCollection(
177             java.util.Collection JavaDoc cin) throws java.rmi.RemoteException JavaDoc
178     {
179         java.util.Collection JavaDoc cout = new java.util.ArrayList JavaDoc(cin);
180         java.util.Iterator JavaDoc i = cin.iterator();
181         while (i.hasNext())
182         {
183             cout.add(i.next());
184         }
185         return cout;
186     }
187
188     public java.util.Vector JavaDoc getVectorWithObjectArrayAsElement()
189             throws java.rmi.RemoteException JavaDoc
190     {
191         java.util.Vector JavaDoc vector = new java.util.Vector JavaDoc();
192         Object JavaDoc[] innerArray = new Object JavaDoc[3];
193         innerArray[0] = new Integer JavaDoc(1);
194         innerArray[1] = new Integer JavaDoc(2);
195         innerArray[2] = "Third Element";
196         vector.add(innerArray);
197         return vector;
198     }
199     
200     public java.util.Vector JavaDoc getVectorWithVectorAsElement()
201             throws java.rmi.RemoteException JavaDoc
202     {
203         java.util.Vector JavaDoc vector = new java.util.Vector JavaDoc();
204         java.util.Vector JavaDoc innerVector = new java.util.Vector JavaDoc();
205         innerVector.add(new Integer JavaDoc(1));
206         innerVector.add(new Integer JavaDoc(2));
207         innerVector.add("Third Element");
208         vector.add(innerVector);
209         return vector;
210     }
211     
212     public java.util.Vector JavaDoc getVectorWithHashtableAsElement()
213             throws java.rmi.RemoteException JavaDoc
214     {
215         java.util.Vector JavaDoc vector = new java.util.Vector JavaDoc();
216         java.util.Hashtable JavaDoc innerHash = new java.util.Hashtable JavaDoc();
217         innerHash.put(new Integer JavaDoc(0), new Integer JavaDoc(1));
218         innerHash.put(new Integer JavaDoc(1), new Integer JavaDoc(2));
219         innerHash.put(new Integer JavaDoc(2), "Third Element");
220         vector.add(innerHash);
221         return vector;
222     }
223     
224 }
225
Popular Tags