1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package test.java.javaclient; 29 30 import com.sun.star.bridge.XBridge; 31 import com.sun.star.bridge.XBridgeFactory; 32 import com.sun.star.comp.helper.Bootstrap; 33 import com.sun.star.connection.Connector; 34 import com.sun.star.lang.XComponent; 35 import com.sun.star.lang.XMultiComponentFactory; 36 import com.sun.star.lib.uno.helper.UnoUrl; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XComponentContext; 39 import test.types.Data; 40 import test.types.XServer; 41 42 public final class JavaClient { 43 public static void main(String[] arguments) throws Exception { 44 XComponentContext context = Bootstrap.createInitialComponentContext( 45 null); 46 XMultiComponentFactory manager = context.getServiceManager(); 47 if (manager == null) { 48 throw new NullPointerException("no service manager"); 49 } 50 XBridgeFactory factory = UnoRuntime.queryInterface( 51 XBridgeFactory.class, 52 manager.createInstanceWithContext( 53 "com.sun.star.bridge.BridgeFactory", context)); 54 if (factory == null) { 55 throw new NullPointerException("no bridge factory"); 56 } 57 UnoUrl url = UnoUrl.parseUnoUrl(arguments[0]); 58 XBridge bridge = factory.createBridge( 59 "", url.getProtocolAndParametersAsString(), 60 Connector.create(context).connect( 61 url.getConnectionAndParametersAsString()), 62 null); 63 Data d = UnoRuntime.queryInterface( 64 XServer.class, bridge.getInstance(url.getRootOid())).getData(); 65 UnoRuntime.queryInterface(XComponent.class, bridge).dispose(); 66 if (!d.m1.equals("Hello") || d.m2 != 42) { 67 throw new RuntimeException("Data object contains bad values"); 68 } 69 } 70 71 private JavaClient() {} 72 } 73