xref: /aoo41x/main/bridges/test/testclient.java (revision 620ba73a)
1*620ba73aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*620ba73aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*620ba73aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*620ba73aSAndrew Rist  * distributed with this work for additional information
6*620ba73aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*620ba73aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*620ba73aSAndrew Rist  * "License"); you may not use this file except in compliance
9*620ba73aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*620ba73aSAndrew Rist  *
11*620ba73aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*620ba73aSAndrew Rist  *
13*620ba73aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*620ba73aSAndrew Rist  * software distributed under the License is distributed on an
15*620ba73aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*620ba73aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*620ba73aSAndrew Rist  * specific language governing permissions and limitations
18*620ba73aSAndrew Rist  * under the License.
19*620ba73aSAndrew Rist  *
20*620ba73aSAndrew Rist  *************************************************************/
21*620ba73aSAndrew Rist 
22*620ba73aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
25cdf0e10cSrcweir import com.sun.star.uno.IBridge;
26cdf0e10cSrcweir import com.sun.star.connection.XConnector;
27cdf0e10cSrcweir import com.sun.star.connection.XConnection;
28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
29cdf0e10cSrcweir import com.sun.star.bridge.XInstanceProvider;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import test.XCallMe;
32cdf0e10cSrcweir import test.XTestFactory;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir class MyInstanceProvider implements XInstanceProvider
36cdf0e10cSrcweir {
getInstance( String sName )37cdf0e10cSrcweir 	public Object getInstance( String sName )
38cdf0e10cSrcweir 		{
39cdf0e10cSrcweir 			System.out.println( "getInstance called" );
40cdf0e10cSrcweir 			return new MyTestFactory();
41cdf0e10cSrcweir 		}
42cdf0e10cSrcweir 
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir class MyTestFactory implements XTestFactory
47cdf0e10cSrcweir {
createCallMe( )48cdf0e10cSrcweir 	public XCallMe createCallMe(  ) throws com.sun.star.uno.RuntimeException
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 			return new MyCallMe();
51cdf0e10cSrcweir 		}
52cdf0e10cSrcweir 
createInterfaceTest( )53cdf0e10cSrcweir     public test.XInterfaceTest createInterfaceTest(  ) throws com.sun.star.uno.RuntimeException
54cdf0e10cSrcweir 		{
55cdf0e10cSrcweir 			return null;
56cdf0e10cSrcweir 		}
57cdf0e10cSrcweir 
58cdf0e10cSrcweir }
59cdf0e10cSrcweir class MyCallMe implements XCallMe
60cdf0e10cSrcweir {
getsAttribute()61cdf0e10cSrcweir     public String getsAttribute() throws com.sun.star.uno.RuntimeException
62cdf0e10cSrcweir 		{
63cdf0e10cSrcweir 			return "";
64cdf0e10cSrcweir 		}
setsAttribute( String _sattribute )65cdf0e10cSrcweir     public void setsAttribute( String _sattribute ) throws com.sun.star.uno.RuntimeException
66cdf0e10cSrcweir 		{
67cdf0e10cSrcweir 		}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // Methods
call( String s, int nToDo )70cdf0e10cSrcweir     public void call( /*IN*/String s, /*IN*/int nToDo ) throws test.TestBridgeException, com.sun.star.uno.RuntimeException
71cdf0e10cSrcweir 		{
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		}
callOneway( String s, int nToDo )74cdf0e10cSrcweir     public void callOneway( /*IN*/String s, /*IN*/int nToDo ) throws com.sun.star.uno.RuntimeException
75cdf0e10cSrcweir 		{
76cdf0e10cSrcweir 			System.out.println( "entering callOneway" );
77cdf0e10cSrcweir //  			this.wait( 5 );
78cdf0e10cSrcweir 			try {
79cdf0e10cSrcweir 				Thread.currentThread().sleep( 4000 );
80cdf0e10cSrcweir 			}
81cdf0e10cSrcweir 			catch ( java.lang.Exception e )
82cdf0e10cSrcweir 			{
83cdf0e10cSrcweir 				System.out.println( e );
84cdf0e10cSrcweir 			}
85cdf0e10cSrcweir 			System.out.println( "leaving callOneway" );
86cdf0e10cSrcweir 		}
callAgain( XCallMe callAgain, int nToCall )87cdf0e10cSrcweir     public void callAgain( /*IN*/XCallMe callAgain, /*IN*/int nToCall ) throws com.sun.star.uno.RuntimeException
88cdf0e10cSrcweir 		{
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		}
transport( test.TestTypes types )91cdf0e10cSrcweir     public test.TestTypes transport( /*IN*/test.TestTypes types ) throws com.sun.star.uno.RuntimeException
92cdf0e10cSrcweir 		{
93cdf0e10cSrcweir 			return new test.TestTypes();
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir public class testclient
99cdf0e10cSrcweir {
main( String[] args )100cdf0e10cSrcweir 	static void main( String[] args )
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			try {
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 				com.sun.star.comp.servicemanager.ServiceManager smgr =
105cdf0e10cSrcweir 					new com.sun.star.comp.servicemanager.ServiceManager();
106cdf0e10cSrcweir 				smgr.addFactories( new String[] { "com.sun.star.comp.connections.Connector" });
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 				Object  x  = smgr.createInstance("com.sun.star.connection.Connector");
109cdf0e10cSrcweir 				if( x == null )
110cdf0e10cSrcweir 				{
111cdf0e10cSrcweir 					System.out.println( "couldn't create connector\n" );
112cdf0e10cSrcweir 					return;
113cdf0e10cSrcweir 				}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 				XConnector xConnector =
117cdf0e10cSrcweir 					UnoRuntime.queryInterface( XConnector.class , x );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 				XConnection xConnection = xConnector.connect(args[0]);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 				if( null != xConnection )
122cdf0e10cSrcweir 				{
123cdf0e10cSrcweir 					System.out.println( "after connect" );
124cdf0e10cSrcweir 					String rootOid = "OfficeDaemon.Factory";
125cdf0e10cSrcweir 					com.sun.star.uno.IBridge bridge = (IBridge ) UnoRuntime.getBridgeByName(
126cdf0e10cSrcweir 						"java",
127cdf0e10cSrcweir 						null,
128cdf0e10cSrcweir 						"remote",
129cdf0e10cSrcweir 						null,
130cdf0e10cSrcweir 						new Object[]{"iiop", xConnection, new MyInstanceProvider()});
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 					System.out.println( "after building bridge" );
133cdf0e10cSrcweir //  				Object rInitialObject = m_bridge.mapInterfaceFrom(rootOid, XInterface.class);
134cdf0e10cSrcweir //  				XTestFactory rFactory =
135cdf0e10cSrcweir //  					UnoRuntime.queryInterface(XTestFactory.class,rInitialObject );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //  				XCallMe callMerFactory->
138cdf0e10cSrcweir 					Thread.currentThread().sleep( 100000 );
139cdf0e10cSrcweir 				}
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 			catch( com.sun.star.uno.Exception e)
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				System.out.println( "Exception thrown" );
144cdf0e10cSrcweir 			}
145cdf0e10cSrcweir 			catch( java.lang.Exception e)
146cdf0e10cSrcweir 			{
147cdf0e10cSrcweir 				System.out.println( "java.lang.Exception thrown" );
148cdf0e10cSrcweir 			}
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 			System.out.println( "exiting" );
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir }
153