1*87e37ca8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*87e37ca8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*87e37ca8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*87e37ca8SAndrew Rist * distributed with this work for additional information 6*87e37ca8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*87e37ca8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*87e37ca8SAndrew Rist * "License"); you may not use this file except in compliance 9*87e37ca8SAndrew Rist * with the License. You may obtain a copy of the License at 10*87e37ca8SAndrew Rist * 11*87e37ca8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*87e37ca8SAndrew Rist * 13*87e37ca8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*87e37ca8SAndrew Rist * software distributed under the License is distributed on an 15*87e37ca8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*87e37ca8SAndrew Rist * KIND, either express or implied. See the License for the 17*87e37ca8SAndrew Rist * specific language governing permissions and limitations 18*87e37ca8SAndrew Rist * under the License. 19*87e37ca8SAndrew Rist * 20*87e37ca8SAndrew Rist *************************************************************/ 21*87e37ca8SAndrew Rist 22*87e37ca8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package test.java.javaclient; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.bridge.XBridge; 27cdf0e10cSrcweir import com.sun.star.bridge.XBridgeFactory; 28cdf0e10cSrcweir import com.sun.star.comp.helper.Bootstrap; 29cdf0e10cSrcweir import com.sun.star.connection.Connector; 30cdf0e10cSrcweir import com.sun.star.lang.XComponent; 31cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 32cdf0e10cSrcweir import com.sun.star.lib.uno.helper.UnoUrl; 33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 34cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 35cdf0e10cSrcweir import test.types.Data; 36cdf0e10cSrcweir import test.types.XServer; 37cdf0e10cSrcweir 38cdf0e10cSrcweir public final class JavaClient { main(String[] arguments)39cdf0e10cSrcweir public static void main(String[] arguments) throws Exception { 40cdf0e10cSrcweir XComponentContext context = Bootstrap.createInitialComponentContext( 41cdf0e10cSrcweir null); 42cdf0e10cSrcweir XMultiComponentFactory manager = context.getServiceManager(); 43cdf0e10cSrcweir if (manager == null) { 44cdf0e10cSrcweir throw new NullPointerException("no service manager"); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir XBridgeFactory factory = UnoRuntime.queryInterface( 47cdf0e10cSrcweir XBridgeFactory.class, 48cdf0e10cSrcweir manager.createInstanceWithContext( 49cdf0e10cSrcweir "com.sun.star.bridge.BridgeFactory", context)); 50cdf0e10cSrcweir if (factory == null) { 51cdf0e10cSrcweir throw new NullPointerException("no bridge factory"); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir UnoUrl url = UnoUrl.parseUnoUrl(arguments[0]); 54cdf0e10cSrcweir XBridge bridge = factory.createBridge( 55cdf0e10cSrcweir "", url.getProtocolAndParametersAsString(), 56cdf0e10cSrcweir Connector.create(context).connect( 57cdf0e10cSrcweir url.getConnectionAndParametersAsString()), 58cdf0e10cSrcweir null); 59cdf0e10cSrcweir Data d = UnoRuntime.queryInterface( 60cdf0e10cSrcweir XServer.class, bridge.getInstance(url.getRootOid())).getData(); 61cdf0e10cSrcweir UnoRuntime.queryInterface(XComponent.class, bridge).dispose(); 62cdf0e10cSrcweir if (!d.m1.equals("Hello") || d.m2 != 42) { 63cdf0e10cSrcweir throw new RuntimeException("Data object contains bad values"); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir JavaClient()67cdf0e10cSrcweir private JavaClient() {} 68cdf0e10cSrcweir } 69