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