2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package com
.sun
.star
.comp
.bridge
;
20 import com
.sun
.star
.bridge
.XBridge
;
21 import com
.sun
.star
.bridge
.XBridgeFactory
;
22 import com
.sun
.star
.bridge
.XInstanceProvider
;
24 import com
.sun
.star
.uno
.XComponentContext
;
25 import com
.sun
.star
.lang
.EventObject
;
26 import com
.sun
.star
.lang
.XComponent
;
27 import com
.sun
.star
.lang
.XEventListener
;
28 import com
.sun
.star
.lang
.XMultiComponentFactory
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.container
.XSet
;
32 import com
.sun
.star
.connection
.Acceptor
;
33 import com
.sun
.star
.connection
.XAcceptor
;
34 import com
.sun
.star
.connection
.XConnection
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
38 public class TestComponentMain
41 private static class InstanceProvider
implements XInstanceProvider
{
42 private XComponentContext ctx
;
44 public InstanceProvider( XComponentContext ctx
)
49 public Object
getInstance( /*IN*/String sInstanceName
)
50 throws com
.sun
.star
.container
.NoSuchElementException
, com
.sun
.star
.uno
.RuntimeException
55 o
= ctx
.getServiceManager().createInstanceWithContext(
56 "com.sun.star.comp.bridge.TestComponent$_TestObject" , ctx
);
58 catch( com
.sun
.star
.uno
.Exception e
)
60 System
.out
.println( "error during instantiation" + e
);
66 public static void main(String args
[]) throws Exception
, com
.sun
.star
.uno
.Exception
{
67 if(args
.length
!= 2) {
68 System
.err
.println("usage : com.sun.star.comp.bridge.TestComponentMain uno:connection;protocol;objectName singleaccept");
73 String protDcp
= null;
76 boolean singleaccept
= args
[1].equals("singleaccept");
78 int index
= dcp
.indexOf(':');
79 dcp
= dcp
.substring(index
+ 1).trim();
81 index
= dcp
.indexOf(';');
82 conDcp
= dcp
.substring(0, index
).trim();
83 dcp
= dcp
.substring(index
+ 1).trim();
85 index
= dcp
.indexOf(';');
86 protDcp
= dcp
.substring(0, index
).trim();
87 dcp
= dcp
.substring(index
+ 1).trim();
89 XComponentContext ctx
= com
.sun
.star
.comp
.helper
.Bootstrap
.createInitialComponentContext( null );
90 XMultiComponentFactory smgr
= ctx
.getServiceManager();
91 XMultiServiceFactory oldsmgr
=
92 UnoRuntime
.queryInterface( XMultiServiceFactory
.class, smgr
);
94 // prepare servicemanager
95 XSet set
= UnoRuntime
.queryInterface(XSet
.class, smgr
);
96 Object o
= com
.sun
.star
.comp
.bridge
.TestComponent
.__getServiceFactory(
97 "com.sun.star.comp.bridge.TestComponent$_TestObject", oldsmgr
,null );
100 XAcceptor xAcceptor
= Acceptor
.create(ctx
);
102 // coverity[loop_top] - deliberate 'infinite' loop.
105 System
.err
.println("waiting for connect...");
107 XConnection xConnection
= xAcceptor
.accept(conDcp
);
109 XBridgeFactory xBridgeFactory
= UnoRuntime
.queryInterface(
110 XBridgeFactory
.class,
111 smgr
.createInstanceWithContext("com.sun.star.bridge.BridgeFactory",ctx
));
113 XBridge xBridge
= xBridgeFactory
.createBridge(
114 "", protDcp
, xConnection
, new InstanceProvider(ctx
));
117 Listener listener
= new Listener();
118 UnoRuntime
.queryInterface(XComponent
.class, xBridge
).
119 addEventListener(listener
);
127 private static final class Listener
implements XEventListener
{
128 public synchronized void disposing(EventObject source
) {
133 public synchronized void await() {
137 } catch (InterruptedException e
) {
138 Thread
.currentThread().interrupt();
139 throw new RuntimeException(e
);
144 private boolean done
= false;