xref: /trunk/main/bridges/test/testclient.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.IBridge;
30 import com.sun.star.connection.XConnector;
31 import com.sun.star.connection.XConnection;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.bridge.XInstanceProvider;
34 
35 import test.XCallMe;
36 import test.XTestFactory;
37 
38 
39 class MyInstanceProvider implements XInstanceProvider
40 {
41     public Object getInstance( String sName )
42         {
43             System.out.println( "getInstance called" );
44             return new MyTestFactory();
45         }
46 
47 }
48 
49 
50 class MyTestFactory implements XTestFactory
51 {
52     public XCallMe createCallMe(  ) throws com.sun.star.uno.RuntimeException
53         {
54             return new MyCallMe();
55         }
56 
57     public test.XInterfaceTest createInterfaceTest(  ) throws com.sun.star.uno.RuntimeException
58         {
59             return null;
60         }
61 
62 }
63 class MyCallMe implements XCallMe
64 {
65     public String getsAttribute() throws com.sun.star.uno.RuntimeException
66         {
67             return "";
68         }
69     public void setsAttribute( String _sattribute ) throws com.sun.star.uno.RuntimeException
70         {
71         }
72 
73     // Methods
74     public void call( /*IN*/String s, /*IN*/int nToDo ) throws test.TestBridgeException, com.sun.star.uno.RuntimeException
75         {
76 
77         }
78     public void callOneway( /*IN*/String s, /*IN*/int nToDo ) throws com.sun.star.uno.RuntimeException
79         {
80             System.out.println( "entering callOneway" );
81 //              this.wait( 5 );
82             try {
83                 Thread.currentThread().sleep( 4000 );
84             }
85             catch ( java.lang.Exception e )
86             {
87                 System.out.println( e );
88             }
89             System.out.println( "leaving callOneway" );
90         }
91     public void callAgain( /*IN*/XCallMe callAgain, /*IN*/int nToCall ) throws com.sun.star.uno.RuntimeException
92         {
93 
94         }
95     public test.TestTypes transport( /*IN*/test.TestTypes types ) throws com.sun.star.uno.RuntimeException
96         {
97             return new test.TestTypes();
98         }
99 
100 }
101 
102 public class testclient
103 {
104     static void main( String[] args )
105         {
106             try {
107 
108                 com.sun.star.comp.servicemanager.ServiceManager smgr =
109                     new com.sun.star.comp.servicemanager.ServiceManager();
110                 smgr.addFactories( new String[] { "com.sun.star.comp.connections.Connector" });
111 
112                 Object  x  = smgr.createInstance("com.sun.star.connection.Connector");
113                 if( x == null )
114                 {
115                     System.out.println( "couldn't create connector\n" );
116                     return;
117                 }
118 
119 
120                 XConnector xConnector =
121                     UnoRuntime.queryInterface( XConnector.class , x );
122 
123                 XConnection xConnection = xConnector.connect(args[0]);
124 
125                 if( null != xConnection )
126                 {
127                     System.out.println( "after connect" );
128                     String rootOid = "OfficeDaemon.Factory";
129                     com.sun.star.uno.IBridge bridge = (IBridge ) UnoRuntime.getBridgeByName(
130                         "java",
131                         null,
132                         "remote",
133                         null,
134                         new Object[]{"iiop", xConnection, new MyInstanceProvider()});
135 
136                     System.out.println( "after building bridge" );
137 //                  Object rInitialObject = m_bridge.mapInterfaceFrom(rootOid, XInterface.class);
138 //                  XTestFactory rFactory =
139 //                      UnoRuntime.queryInterface(XTestFactory.class,rInitialObject );
140 
141 //                  XCallMe callMerFactory->
142                     Thread.currentThread().sleep( 100000 );
143                 }
144             }
145             catch( com.sun.star.uno.Exception e)
146             {
147                 System.out.println( "Exception thrown" );
148             }
149             catch( java.lang.Exception e)
150             {
151                 System.out.println( "java.lang.Exception thrown" );
152             }
153 
154             System.out.println( "exiting" );
155         }
156 }
157