1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package com.sun.star.comp.bridge; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.bridge.XBridge; 30*cdf0e10cSrcweir import com.sun.star.bridge.XBridgeFactory; 31*cdf0e10cSrcweir import com.sun.star.bridge.XInstanceProvider; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 34*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 35*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 36*cdf0e10cSrcweir import com.sun.star.lang.XEventListener; 37*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 38*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 39*cdf0e10cSrcweir import com.sun.star.container.XSet; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir import com.sun.star.connection.Acceptor; 42*cdf0e10cSrcweir import com.sun.star.connection.XAcceptor; 43*cdf0e10cSrcweir import com.sun.star.connection.XConnection; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir public class TestComponentMain 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir static class InstanceProvider implements XInstanceProvider { 51*cdf0e10cSrcweir XComponentContext ctx; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir public InstanceProvider( XComponentContext ctx ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir this.ctx = ctx; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir public Object getInstance( /*IN*/String sInstanceName ) 59*cdf0e10cSrcweir throws com.sun.star.container.NoSuchElementException, com.sun.star.uno.RuntimeException 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir Object o =null; 62*cdf0e10cSrcweir try 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir o = ctx.getServiceManager().createInstanceWithContext( 65*cdf0e10cSrcweir "com.sun.star.comp.bridge.TestComponent$_TestObject" , ctx ); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir catch( com.sun.star.uno.Exception e ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir System.out.println( "error during instantiation" + e ); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir return o; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir static public void main(String args[]) throws Exception, com.sun.star.uno.Exception { 76*cdf0e10cSrcweir if(args.length != 2) { 77*cdf0e10cSrcweir System.err.println("usage : com.sun.star.comp.bridge.TestComponentMain uno:connection;protocol;objectName singleaccept"); 78*cdf0e10cSrcweir System.exit(-1); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir String conDcp = null; 82*cdf0e10cSrcweir String protDcp = null; 83*cdf0e10cSrcweir String rootOid = null; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir String dcp = args[0]; 86*cdf0e10cSrcweir boolean singleaccept = args[1].equals("singleaccept"); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir int index = dcp.indexOf(':'); 89*cdf0e10cSrcweir String url = dcp.substring(0, index).trim(); 90*cdf0e10cSrcweir dcp = dcp.substring(index + 1).trim(); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir index = dcp.indexOf(';'); 93*cdf0e10cSrcweir conDcp = dcp.substring(0, index).trim(); 94*cdf0e10cSrcweir dcp = dcp.substring(index + 1).trim(); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir index = dcp.indexOf(';'); 97*cdf0e10cSrcweir protDcp = dcp.substring(0, index).trim(); 98*cdf0e10cSrcweir dcp = dcp.substring(index + 1).trim(); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir rootOid = dcp.trim().trim(); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir XComponentContext ctx = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null ); 103*cdf0e10cSrcweir XMultiComponentFactory smgr = ctx.getServiceManager(); 104*cdf0e10cSrcweir XMultiServiceFactory oldsmgr = 105*cdf0e10cSrcweir UnoRuntime.queryInterface( XMultiServiceFactory.class, smgr ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // prepare servicemanager 108*cdf0e10cSrcweir XSet set = UnoRuntime.queryInterface(XSet.class, smgr); 109*cdf0e10cSrcweir Object o = com.sun.star.comp.bridge.TestComponent.__getServiceFactory( 110*cdf0e10cSrcweir "com.sun.star.comp.bridge.TestComponent$_TestObject", oldsmgr,null ); 111*cdf0e10cSrcweir set.insert(o); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir XAcceptor xAcceptor = Acceptor.create(ctx); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir while( true ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir System.err.println("waiting for connect..."); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir XConnection xConnection = xAcceptor.accept(conDcp); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir XBridgeFactory xBridgeFactory = UnoRuntime.queryInterface( 122*cdf0e10cSrcweir XBridgeFactory.class, 123*cdf0e10cSrcweir smgr.createInstanceWithContext("com.sun.star.bridge.BridgeFactory",ctx)); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir XBridge xBridge = xBridgeFactory.createBridge( 126*cdf0e10cSrcweir "", protDcp, xConnection, new InstanceProvider(ctx)); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if (singleaccept) { 129*cdf0e10cSrcweir Listener listener = new Listener(); 130*cdf0e10cSrcweir UnoRuntime.queryInterface(XComponent.class, xBridge). 131*cdf0e10cSrcweir addEventListener(listener); 132*cdf0e10cSrcweir listener.await(); 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir private static final class Listener implements XEventListener { 140*cdf0e10cSrcweir public synchronized void disposing(EventObject source) { 141*cdf0e10cSrcweir done = true; 142*cdf0e10cSrcweir notifyAll(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir public synchronized void await() { 146*cdf0e10cSrcweir while (!done) { 147*cdf0e10cSrcweir try { 148*cdf0e10cSrcweir wait(); 149*cdf0e10cSrcweir } catch (InterruptedException e) { 150*cdf0e10cSrcweir Thread.currentThread().interrupt(); 151*cdf0e10cSrcweir throw new RuntimeException(e); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir private boolean done = false; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159