Branch libreoffice-5-0-4
[LibreOffice.git] / bridges / test / testclient.java
blob06e5efb49f58c6df910cf19e7ebe572c5c354691
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package test;
21 import com.sun.star.uno.UnoRuntime;
22 import com.sun.star.connection.XConnector;
23 import com.sun.star.connection.XConnection;
24 import com.sun.star.bridge.XInstanceProvider;
26 class MyInstanceProvider implements XInstanceProvider
28 public Object getInstance( String sName )
30 System.out.println( "getInstance called" );
31 return new MyTestFactory();
37 class MyTestFactory implements XTestFactory
39 public XCallMe createCallMe( ) throws com.sun.star.uno.RuntimeException
41 return new MyCallMe();
44 public test.XInterfaceTest createInterfaceTest( ) throws com.sun.star.uno.RuntimeException
46 return null;
50 class MyCallMe implements XCallMe
52 public String getsAttribute() throws com.sun.star.uno.RuntimeException
54 return "";
57 // Methods
58 public void call( /*IN*/String s, /*IN*/int nToDo ) throws com.sun.star.uno.RuntimeException
62 public void callOneway( /*IN*/String s, /*IN*/int nToDo ) throws com.sun.star.uno.RuntimeException
64 System.out.println( "entering callOneway" );
65 try {
66 Thread.sleep( 4000 );
68 catch ( java.lang.Exception e )
70 System.out.println( e );
72 System.out.println( "leaving callOneway" );
74 public void callAgain( /*IN*/XCallMe callAgain, /*IN*/int nToCall ) throws com.sun.star.uno.RuntimeException
78 public test.TestTypes transport( /*IN*/test.TestTypes types ) throws com.sun.star.uno.RuntimeException
80 return new test.TestTypes();
85 public class testclient
87 static void main( String[] args )
89 try {
91 com.sun.star.comp.servicemanager.ServiceManager smgr =
92 new com.sun.star.comp.servicemanager.ServiceManager();
93 smgr.insert( "com.sun.star.comp.connections.Connector" );
95 Object x = smgr.createInstance("com.sun.star.connection.Connector");
96 if( x == null )
98 System.out.println( "couldn't create connector\n" );
99 return;
103 XConnector xConnector =
104 UnoRuntime.queryInterface( XConnector.class , x );
106 XConnection xConnection = xConnector.connect(args[0]);
108 if( null != xConnection )
110 System.out.println( "after connect" );
111 UnoRuntime.getBridgeByName(
112 "java",
113 null,
114 "remote",
115 null,
116 new Object[]{"iiop", xConnection, new MyInstanceProvider()});
118 System.out.println( "after building bridge" );
120 Thread.sleep( 100000 );
123 catch( com.sun.star.uno.Exception e)
125 System.out.println( "Exception thrown" );
127 catch( java.lang.Exception e)
129 System.out.println( "java.lang.Exception thrown" );
132 System.out.println( "exiting" );