KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > T1


1
2 import javax.naming.*;
3
4 import mark.*;
5 import mark.comps.*;
6
7 public class T1
8 {
9     protected String _host;
10     protected String _port;
11     protected String _ior;
12
13     public void setHost( String val )
14     {
15         _host = val;
16     }
17
18     public void setPort( String val )
19     {
20         _port = val;
21     }
22
23     public Context getInitialContext()
24         throws Exception
25     {
26         java.util.Properties p = new java.util.Properties();
27         //p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sybase.djc.client.InitialContextFactory");
28
p.put(Context.INITIAL_CONTEXT_FACTORY, "gcc.client.InitialContextFactory");
29         p.put(Context.PROVIDER_URL, _ior = "iiop://" + _host + ":" + _port );
30         p.put(Context.SECURITY_PRINCIPAL, "uid" );
31         p.put(Context.SECURITY_CREDENTIALS, "pwd" );
32         return new InitialContext(p);
33     }
34
35     public void testInterface( )
36         throws Exception
37     {
38         String name = "mark.comps.Add";
39
40         Context nc = getInitialContext();
41
42         Add a = (Add)nc.lookup( name);
43         System.out.println( "a = " + a );
44
45         System.out.println( "a.add(1,2) = " + a.add(1,2) );
46
47         // I thought you should just be able to create an AddData and send it ... aparently not.
48
//System.out.println( "a.addData( 1, 2 ) = " + a.addData( new AddDataImpl(1), new AddDataImpl(2) ).getA() );
49

50         /*
51         AddDataValueFactory advf = new AddDataDefaultFactory();
52         AddData ad1 = advf.createAD( 1 );
53         AddData ad2 = advf.createAD( 2 );
54         System.out.println( "a.addData( 1, 2 ) = " + a.addData( ad1, ad2 ).J_a() );
55         */

56     }
57
58     public static void main( String args[] )
59         throws Exception
60     {
61         int i;
62
63         T1 t1 = new T1();
64
65         t1.setHost("localhost");
66         t1.setPort("9000");
67
68         for( i=0; i<args.length; i++ )
69         {
70             if (args[i].equals("-intf"))
71             {
72                 t1.testInterface();
73             }
74             else if (args[i].equals("-host"))
75             {
76                 t1.setHost( args[++i] );
77             }
78             else if (args[i].equals("-port"))
79             {
80                 t1.setPort( args[++i] );
81             }
82             else
83             {
84                 System.out.println( "Unknown option: " + args[i] );
85             }
86         }
87     }
88
89 }
90
Popular Tags