xref: /aoo41x/main/ure/source/uretest/JavaClient.java (revision 87e37ca8)
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 package test.java.javaclient;
25 
26 import com.sun.star.bridge.XBridge;
27 import com.sun.star.bridge.XBridgeFactory;
28 import com.sun.star.comp.helper.Bootstrap;
29 import com.sun.star.connection.Connector;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiComponentFactory;
32 import com.sun.star.lib.uno.helper.UnoUrl;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XComponentContext;
35 import test.types.Data;
36 import test.types.XServer;
37 
38 public final class JavaClient {
main(String[] arguments)39     public static void main(String[] arguments) throws Exception {
40         XComponentContext context = Bootstrap.createInitialComponentContext(
41             null);
42         XMultiComponentFactory manager = context.getServiceManager();
43         if (manager == null) {
44             throw new NullPointerException("no service manager");
45         }
46         XBridgeFactory factory = UnoRuntime.queryInterface(
47             XBridgeFactory.class,
48             manager.createInstanceWithContext(
49                 "com.sun.star.bridge.BridgeFactory", context));
50         if (factory == null) {
51             throw new NullPointerException("no bridge factory");
52         }
53         UnoUrl url = UnoUrl.parseUnoUrl(arguments[0]);
54         XBridge bridge = factory.createBridge(
55             "", url.getProtocolAndParametersAsString(),
56             Connector.create(context).connect(
57                 url.getConnectionAndParametersAsString()),
58             null);
59         Data d = UnoRuntime.queryInterface(
60             XServer.class, bridge.getInstance(url.getRootOid())).getData();
61         UnoRuntime.queryInterface(XComponent.class, bridge).dispose();
62         if (!d.m1.equals("Hello") || d.m2 != 42) {
63             throw new RuntimeException("Data object contains bad values");
64         }
65     }
66 
JavaClient()67     private JavaClient() {}
68 }
69