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