KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > examples > PrimitiveClient


1 package org.sapia.ubik.rmi.examples;
2
3 import org.sapia.ubik.rmi.Consts;
4 import org.sapia.ubik.rmi.naming.remote.RemoteInitialContextFactory;
5 import org.sapia.ubik.rmi.server.Hub;
6
7 import java.util.Properties JavaDoc;
8
9 import javax.naming.InitialContext JavaDoc;
10
11
12 /**
13  * @author Yanick Duchesne
14  *
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class PrimitiveClient {
22   public static void main(String JavaDoc[] args) {
23     try {
24       Properties JavaDoc props = new Properties JavaDoc();
25
26       // ENABLES MARSHALLING
27
System.setProperty(Consts.MARSHALLING, "true");
28
29       props.setProperty(InitialContext.PROVIDER_URL, "ubik://localhost:1099");
30       props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,
31         RemoteInitialContextFactory.class.getName());
32
33       InitialContext JavaDoc ctx = new InitialContext JavaDoc(props);
34       Object JavaDoc lookedUp = ctx.lookup("PrimitiveService");
35       System.out.println(lookedUp.getClass().getName());
36
37       PrimitiveService svc = (PrimitiveService) lookedUp;
38
39       svc.getBoolean();
40       svc.getByte();
41       svc.getChar();
42       svc.getShort();
43       svc.getInt();
44       svc.getLong();
45       svc.getFloat();
46       svc.getDouble();
47
48       svc.setBoolean(true);
49       svc.setByte((byte) 0);
50       svc.setChar('c');
51       svc.setShort((short) 0);
52       svc.setInt(0);
53       svc.setLong(0);
54       svc.setFloat(0);
55       svc.setDouble(0);
56
57       byte[] b = "Hello World".getBytes();
58
59       for (int i = 0; i < b.length; i++) {
60         System.out.print(b[i]);
61       }
62
63       svc.setBytes(b);
64
65       Hub.shutdown(30000);
66     } catch (Exception JavaDoc e) {
67       e.printStackTrace();
68     }
69   }
70 }
71
Popular Tags