Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <stdio.h>
21 :
22 : #include "sal/main.h"
23 : #include <osl/diagnose.h>
24 : #include <osl/mutex.hxx>
25 : #include <osl/conditn.hxx>
26 :
27 : #include <rtl/process.h>
28 : #include <rtl/string.h>
29 : #include <rtl/strbuf.hxx>
30 : #include <rtl/ustrbuf.hxx>
31 :
32 : #include <cppuhelper/bootstrap.hxx>
33 : #include <cppuhelper/shlib.hxx>
34 : #include <cppuhelper/implbase1.hxx>
35 :
36 : #include <com/sun/star/lang/XMain.hpp>
37 : #include <com/sun/star/lang/XInitialization.hpp>
38 : #include <com/sun/star/lang/XComponent.hpp>
39 : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
40 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 : #include <com/sun/star/lang/XEventListener.hpp>
43 : #include <com/sun/star/container/XSet.hpp>
44 : #include <com/sun/star/loader/XImplementationLoader.hpp>
45 : #include <com/sun/star/registry/XRegistryKey.hpp>
46 : #include <com/sun/star/connection/Acceptor.hpp>
47 : #include <com/sun/star/connection/XConnection.hpp>
48 : #include <com/sun/star/bridge/XBridgeFactory.hpp>
49 : #include <com/sun/star/bridge/XBridge.hpp>
50 :
51 : using namespace std;
52 : using namespace osl;
53 : using namespace cppu;
54 : using namespace com::sun::star::uno;
55 : using namespace com::sun::star::lang;
56 : using namespace com::sun::star::loader;
57 : using namespace com::sun::star::registry;
58 : using namespace com::sun::star::connection;
59 : using namespace com::sun::star::bridge;
60 : using namespace com::sun::star::container;
61 :
62 : namespace unoexe
63 : {
64 :
65 : static sal_Bool s_quiet = false;
66 :
67 3 : static inline void out( const sal_Char * pText )
68 : {
69 3 : if (! s_quiet)
70 0 : fprintf( stderr, "%s", pText );
71 3 : }
72 :
73 1 : static inline void out( const OUString & rText )
74 : {
75 1 : if (! s_quiet)
76 : {
77 0 : OString aText( OUStringToOString( rText, RTL_TEXTENCODING_ASCII_US ) );
78 0 : fprintf( stderr, "%s", aText.getStr() );
79 : }
80 1 : }
81 :
82 : static const char arUsingText[] =
83 : "\nusing:\n\n"
84 : "uno [-c ComponentImplementationName -l LocationUrl | -s ServiceName]\n"
85 : " [-u uno:(socket[,host=HostName][,port=nnn]|pipe[,name=PipeName]);<protocol>;Name\n"
86 : " [--singleaccept] [--singleinstance]]\n"
87 : " [--quiet]\n"
88 : " [-- Argument1 Argument2 ...]\n";
89 :
90 15 : static sal_Bool readOption( OUString * pValue, const sal_Char * pOpt,
91 : sal_uInt32 * pnIndex, const OUString & aArg)
92 : throw (RuntimeException)
93 : {
94 15 : const OUString dash("-");
95 15 : if(aArg.indexOf(dash) != 0)
96 0 : return sal_False;
97 :
98 30 : OUString aOpt = OUString::createFromAscii( pOpt );
99 :
100 15 : if (aArg.getLength() < aOpt.getLength())
101 0 : return sal_False;
102 :
103 15 : if (aOpt.equalsIgnoreAsciiCase( aArg.copy(1) ))
104 : {
105 : // take next argument
106 2 : ++(*pnIndex);
107 :
108 2 : rtl_getAppCommandArg(*pnIndex, &pValue->pData);
109 2 : if (*pnIndex >= rtl_getAppCommandArgCount() || pValue->copy(1).equals(dash))
110 : {
111 0 : OUStringBuffer buf( 32 );
112 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("incomplete option \"-") );
113 0 : buf.appendAscii( pOpt );
114 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" given!") );
115 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
116 : }
117 : else
118 : {
119 : #if OSL_DEBUG_LEVEL > 1
120 : out( "\n> identified option -" );
121 : out( pOpt );
122 : out( " = " );
123 : OString tmp = OUStringToOString(aArg, RTL_TEXTENCODING_ASCII_US);
124 : out( tmp.getStr() );
125 : #endif
126 2 : ++(*pnIndex);
127 2 : return sal_True;
128 : }
129 : }
130 13 : else if (aArg.indexOf(aOpt) == 1)
131 : {
132 0 : *pValue = aArg.copy(1 + aOpt.getLength());
133 : #if OSL_DEBUG_LEVEL > 1
134 : out( "\n> identified option -" );
135 : out( pOpt );
136 : out( " = " );
137 : OString tmp = OUStringToOString(aArg.copy(aOpt.getLength()), RTL_TEXTENCODING_ASCII_US);
138 : out( tmp.getStr() );
139 : #endif
140 0 : ++(*pnIndex);
141 :
142 0 : return sal_True;
143 : }
144 28 : return sal_False;
145 : }
146 :
147 3 : static sal_Bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt,
148 : sal_uInt32 * pnIndex, const OUString & aArg)
149 : {
150 3 : const OUString dashdash("--");
151 6 : OUString aOpt = OUString::createFromAscii(pOpt);
152 :
153 3 : if(aArg.indexOf(dashdash) == 0 && aOpt.equals(aArg.copy(2)))
154 : {
155 2 : ++(*pnIndex);
156 2 : *pbOpt = sal_True;
157 : #if OSL_DEBUG_LEVEL > 1
158 : out( "\n> identified option --" );
159 : out( pOpt );
160 : #endif
161 2 : return sal_True;
162 : }
163 4 : return sal_False;
164 : }
165 :
166 : template< class T >
167 2 : void createInstance(
168 : Reference< T > & rxOut,
169 : const Reference< XComponentContext > & xContext,
170 : const OUString & rServiceName )
171 : throw (Exception)
172 : {
173 2 : Reference< XMultiComponentFactory > xMgr( xContext->getServiceManager() );
174 4 : Reference< XInterface > x( xMgr->createInstanceWithContext( rServiceName, xContext ) );
175 :
176 2 : if (! x.is())
177 : {
178 : static sal_Bool s_bSet = sal_False;
179 0 : if (! s_bSet)
180 : {
181 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
182 0 : if (! s_bSet)
183 : {
184 0 : Reference< XSet > xSet( xMgr, UNO_QUERY );
185 0 : if (xSet.is())
186 : {
187 0 : Reference< XMultiServiceFactory > xSF( xMgr, UNO_QUERY );
188 : // acceptor
189 0 : xSet->insert( makeAny( loadSharedLibComponentFactory(
190 : OUString( "acceptor.uno" SAL_DLLEXTENSION ),
191 : OUString(),
192 : OUString( "com.sun.star.comp.io.Acceptor" ),
193 : xSF, Reference< XRegistryKey >(),
194 0 : "acceptor_" ) ) );
195 : // connector
196 0 : xSet->insert( makeAny( loadSharedLibComponentFactory(
197 : OUString( "connector.uno" SAL_DLLEXTENSION ),
198 : OUString(),
199 : OUString( "com.sun.star.comp.io.Connector" ),
200 : xSF, Reference< XRegistryKey >(),
201 0 : "connector_" ) ) );
202 : // bridge factory
203 0 : xSet->insert( makeAny( loadSharedLibComponentFactory(
204 : OUString( "binaryurp.uno" SAL_DLLEXTENSION ),
205 : OUString(),
206 : OUString( "com.sun.star.comp.bridge.BridgeFactory" ),
207 : xSF, Reference< XRegistryKey >(),
208 0 : "binaryurp_" ) ) );
209 : }
210 0 : s_bSet = sal_True;
211 0 : }
212 : }
213 0 : x = xMgr->createInstanceWithContext( rServiceName, xContext );
214 : }
215 :
216 2 : if (! x.is())
217 : {
218 0 : OUStringBuffer buf( 64 );
219 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get service instance \"") );
220 0 : buf.append( rServiceName );
221 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
222 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
223 : }
224 :
225 2 : rxOut = Reference< T >::query( x );
226 2 : if (! rxOut.is())
227 : {
228 0 : OUStringBuffer buf( 64 );
229 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("service instance \"") );
230 0 : buf.append( rServiceName );
231 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not support demanded interface \"") );
232 0 : const Type & rType = ::getCppuType( (const Reference< T > *)0 );
233 0 : buf.append( rType.getTypeName() );
234 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
235 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
236 2 : }
237 2 : }
238 :
239 0 : static Reference< XInterface > loadComponent(
240 : const Reference< XComponentContext > & xContext,
241 : const OUString & rImplName, const OUString & rLocation )
242 : throw (Exception)
243 : {
244 : // determine loader to be used
245 0 : sal_Int32 nDot = rLocation.lastIndexOf( '.' );
246 0 : if (nDot > 0 && nDot < rLocation.getLength())
247 : {
248 0 : Reference< XImplementationLoader > xLoader;
249 :
250 0 : OUString aExt( rLocation.copy( nDot +1 ) );
251 :
252 0 : if (aExt.compareToAscii( "dll" ) == 0 ||
253 0 : aExt.compareToAscii( "exe" ) == 0 ||
254 0 : aExt.compareToAscii( "dylib" ) == 0 ||
255 0 : aExt.compareToAscii( "so" ) == 0)
256 : {
257 : createInstance(
258 0 : xLoader, xContext, OUString("com.sun.star.loader.SharedLibrary") );
259 : }
260 0 : else if (aExt.compareToAscii( "jar" ) == 0 ||
261 0 : aExt.compareToAscii( "class" ) == 0)
262 : {
263 : createInstance(
264 0 : xLoader, xContext, OUString("com.sun.star.loader.Java") );
265 : }
266 : else
267 : {
268 0 : OUStringBuffer buf( 64 );
269 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("unknown extension of \"") );
270 0 : buf.append( rLocation );
271 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"! No loader available!") );
272 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
273 : }
274 :
275 0 : Reference< XInterface > xInstance;
276 :
277 : // activate
278 0 : Reference< XInterface > xFactory( xLoader->activate(
279 0 : rImplName, OUString(), rLocation, Reference< XRegistryKey >() ) );
280 0 : if (xFactory.is())
281 : {
282 0 : Reference< XSingleComponentFactory > xCFac( xFactory, UNO_QUERY );
283 0 : if (xCFac.is())
284 : {
285 0 : xInstance = xCFac->createInstanceWithContext( xContext );
286 : }
287 : else
288 : {
289 0 : Reference< XSingleServiceFactory > xSFac( xFactory, UNO_QUERY );
290 0 : if (xSFac.is())
291 : {
292 0 : out( "\n> warning: ignroing context for implementation \"" );
293 0 : out( rImplName );
294 0 : out( "\"!" );
295 0 : xInstance = xSFac->createInstance();
296 0 : }
297 0 : }
298 : }
299 :
300 0 : if (! xInstance.is())
301 : {
302 0 : OUStringBuffer buf( 64 );
303 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("activating component \"") );
304 0 : buf.append( rImplName );
305 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" from location \"") );
306 0 : buf.append( rLocation );
307 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" failed!") );
308 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
309 : }
310 :
311 0 : return xInstance;
312 : }
313 : else
314 : {
315 0 : OUStringBuffer buf( 64 );
316 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("location \"") );
317 0 : buf.append( rLocation );
318 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" has no extension! Cannot determine loader to be used!") );
319 0 : throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() );
320 : }
321 : }
322 :
323 0 : class OInstanceProvider
324 : : public WeakImplHelper1< XInstanceProvider >
325 : {
326 : Reference< XComponentContext > _xContext;
327 :
328 : Mutex _aSingleInstanceMutex;
329 : Reference< XInterface > _xSingleInstance;
330 : sal_Bool _bSingleInstance;
331 :
332 : OUString _aImplName;
333 : OUString _aLocation;
334 : OUString _aServiceName;
335 : Sequence< Any > _aInitParams;
336 :
337 : OUString _aInstanceName;
338 :
339 : inline Reference< XInterface > createInstance() throw (Exception);
340 :
341 : public:
342 1 : OInstanceProvider( const Reference< XComponentContext > & xContext,
343 : const OUString & rImplName, const OUString & rLocation,
344 : const OUString & rServiceName, const Sequence< Any > & rInitParams,
345 : sal_Bool bSingleInstance, const OUString & rInstanceName )
346 : : _xContext( xContext )
347 : , _bSingleInstance( bSingleInstance )
348 : , _aImplName( rImplName )
349 : , _aLocation( rLocation )
350 : , _aServiceName( rServiceName )
351 : , _aInitParams( rInitParams )
352 1 : , _aInstanceName( rInstanceName )
353 1 : {}
354 :
355 : // XInstanceProvider
356 : virtual Reference< XInterface > SAL_CALL getInstance( const OUString & rName )
357 : throw (NoSuchElementException, RuntimeException);
358 : };
359 :
360 0 : inline Reference< XInterface > OInstanceProvider::createInstance()
361 : throw (Exception)
362 : {
363 0 : Reference< XInterface > xRet;
364 0 : if (!_aImplName.isEmpty()) // manually via loader
365 0 : xRet = loadComponent( _xContext, _aImplName, _aLocation );
366 : else // via service manager
367 0 : unoexe::createInstance( xRet, _xContext, _aServiceName );
368 :
369 : // opt XInit
370 0 : Reference< XInitialization > xInit( xRet, UNO_QUERY );
371 0 : if (xInit.is())
372 0 : xInit->initialize( _aInitParams );
373 :
374 0 : return xRet;
375 : }
376 :
377 1 : Reference< XInterface > OInstanceProvider::getInstance( const OUString & rName )
378 : throw (NoSuchElementException, RuntimeException)
379 : {
380 : try
381 : {
382 1 : if (_aInstanceName == rName)
383 : {
384 1 : Reference< XInterface > xRet;
385 :
386 1 : if (_aImplName.isEmpty() && _aServiceName.isEmpty())
387 : {
388 : OSL_ASSERT( rName == "uno.ComponentContext" );
389 1 : xRet = _xContext;
390 : }
391 0 : else if (_bSingleInstance)
392 : {
393 0 : if (! _xSingleInstance.is())
394 : {
395 0 : MutexGuard aGuard( _aSingleInstanceMutex );
396 0 : if (! _xSingleInstance.is())
397 : {
398 0 : _xSingleInstance = createInstance();
399 0 : }
400 : }
401 0 : xRet = _xSingleInstance;
402 : }
403 : else
404 : {
405 0 : xRet = createInstance();
406 : }
407 :
408 2 : return xRet;
409 : }
410 : }
411 0 : catch (Exception & rExc)
412 : {
413 0 : out( "\n> error: " );
414 0 : out( rExc.Message );
415 : }
416 0 : OUStringBuffer buf( 64 );
417 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("no such element \"") );
418 0 : buf.append( rName );
419 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
420 0 : throw NoSuchElementException( buf.makeStringAndClear(), Reference< XInterface >() );
421 : }
422 :
423 3 : struct ODisposingListener : public WeakImplHelper1< XEventListener >
424 : {
425 : Condition cDisposed;
426 :
427 : // XEventListener
428 : virtual void SAL_CALL disposing( const EventObject & rEvt )
429 : throw (RuntimeException);
430 :
431 : static void waitFor( const Reference< XComponent > & xComp );
432 : };
433 :
434 1 : void ODisposingListener::disposing( const EventObject & )
435 : throw (RuntimeException)
436 : {
437 1 : cDisposed.set();
438 1 : }
439 :
440 1 : void ODisposingListener::waitFor( const Reference< XComponent > & xComp )
441 : {
442 1 : ODisposingListener * pListener = new ODisposingListener();
443 1 : Reference< XEventListener > xListener( pListener );
444 :
445 1 : xComp->addEventListener( xListener );
446 1 : pListener->cDisposed.wait();
447 1 : }
448 :
449 : } // namespace unoexe
450 :
451 : using namespace unoexe;
452 :
453 4 : SAL_IMPLEMENT_MAIN()
454 : {
455 2 : sal_uInt32 nCount = rtl_getAppCommandArgCount();
456 2 : if (nCount == 0)
457 : {
458 0 : out( arUsingText );
459 0 : return 0;
460 : }
461 :
462 2 : sal_Int32 nRet = 0;
463 2 : Reference< XComponentContext > xContext;
464 :
465 :
466 : try
467 : {
468 4 : OUString aImplName, aLocation, aServiceName, aUnoUrl;
469 4 : Sequence< OUString > aParams;
470 2 : sal_Bool bSingleAccept = sal_False;
471 2 : sal_Bool bSingleInstance = sal_False;
472 :
473 : // read command line arguments
474 :
475 2 : sal_uInt32 nPos = 0;
476 : // read up to arguments
477 8 : while (nPos < nCount)
478 : {
479 5 : OUString arg;
480 :
481 5 : rtl_getAppCommandArg(nPos, &arg.pData);
482 :
483 9 : const OUString dashdash("--");
484 5 : if (dashdash == arg)
485 : {
486 1 : ++nPos;
487 1 : break;
488 : }
489 :
490 12 : if (!(readOption( &aImplName, "c", &nPos, arg) ||
491 8 : readOption( &aLocation, "l", &nPos, arg) ||
492 7 : readOption( &aServiceName, "s", &nPos, arg) ||
493 5 : readOption( &aUnoUrl, "u", &nPos, arg) ||
494 3 : readOption( &s_quiet, "quiet", &nPos, arg) ||
495 1 : readOption( &bSingleAccept, "singleaccept", &nPos, arg) ||
496 4 : readOption( &bSingleInstance, "singleinstance", &nPos, arg)))
497 : {
498 : throw RuntimeException(
499 0 : "unexpected argument \"" + arg + "\"",
500 0 : Reference< XInterface >() );
501 : }
502 4 : }
503 :
504 2 : if (!(aImplName.isEmpty() || aServiceName.isEmpty()))
505 0 : throw RuntimeException("give component exOR service name!", Reference< XInterface >() );
506 2 : if (aImplName.isEmpty() && aServiceName.isEmpty())
507 : {
508 1 : if (! aUnoUrl.endsWithIgnoreAsciiCaseAsciiL(
509 1 : RTL_CONSTASCII_STRINGPARAM(";uno.ComponentContext") ))
510 : throw RuntimeException(
511 : OUString("expected UNO-URL with instance name uno.ComponentContext!" ),
512 0 : Reference<XInterface>() );
513 1 : if (bSingleInstance)
514 : throw RuntimeException(
515 : OUString("unexpected option --singleinstance!"),
516 0 : Reference<XInterface>() );
517 : }
518 2 : if (!aImplName.isEmpty() && aLocation.isEmpty())
519 0 : throw RuntimeException("give component location!", Reference< XInterface >() );
520 2 : if (!aServiceName.isEmpty() && !aLocation.isEmpty())
521 0 : out( "\n> warning: service name given, will ignore location!" );
522 :
523 : // read component params
524 2 : aParams.realloc( nCount - nPos );
525 2 : OUString * pParams = aParams.getArray();
526 :
527 2 : sal_uInt32 nOffset = nPos;
528 3 : for ( ; nPos < nCount; ++nPos )
529 : {
530 1 : rtl_getAppCommandArg( nPos, &pParams[nPos -nOffset].pData );
531 : }
532 :
533 2 : xContext = defaultBootstrap_InitialComponentContext();
534 :
535 : // accept, instanciate, etc.
536 :
537 2 : if (!aUnoUrl.isEmpty()) // accepting connections
538 : {
539 1 : sal_Int32 nIndex = 0, nTokens = 0;
540 3 : do { aUnoUrl.getToken( 0, ';', nIndex ); nTokens++; } while( nIndex != -1 );
541 5 : if (nTokens != 3 || aUnoUrl.getLength() < 10 ||
542 5 : !aUnoUrl.copy( 0, 4 ).equalsIgnoreAsciiCase( OUString("uno:") ))
543 : {
544 0 : throw RuntimeException("illegal uno url given!", Reference< XInterface >() );
545 : }
546 1 : nIndex = 0;
547 1 : OUString aConnectDescr( aUnoUrl.getToken( 0, ';', nIndex ).copy( 4 ) ); // uno:CONNECTDESCR;iiop;InstanceName
548 2 : OUString aInstanceName( aUnoUrl.getToken( 1, ';', nIndex ) );
549 :
550 2 : Reference< XAcceptor > xAcceptor = Acceptor::create(xContext);
551 :
552 : // init params
553 2 : Sequence< Any > aInitParams( aParams.getLength() );
554 1 : const OUString * p = aParams.getConstArray();
555 1 : Any * pInitParams = aInitParams.getArray();
556 2 : for ( sal_Int32 i = aParams.getLength(); i--; )
557 : {
558 0 : pInitParams[i] = makeAny( p[i] );
559 : }
560 :
561 : // instance provider
562 : Reference< XInstanceProvider > xInstanceProvider( new OInstanceProvider(
563 : xContext, aImplName, aLocation, aServiceName, aInitParams,
564 2 : bSingleInstance, aInstanceName ) );
565 :
566 1 : nIndex = 0;
567 2 : OUString aUnoUrlToken( aUnoUrl.getToken( 1, ';', nIndex ) );
568 : for (;;)
569 : {
570 : // accepting
571 1 : out( "\n> accepting " );
572 1 : out( aConnectDescr );
573 1 : out( "..." );
574 1 : Reference< XConnection > xConnection( xAcceptor->accept( aConnectDescr ) );
575 1 : out( "connection established." );
576 :
577 1 : Reference< XBridgeFactory > xBridgeFactory;
578 : createInstance(
579 : xBridgeFactory, xContext,
580 1 : OUString("com.sun.star.bridge.BridgeFactory") );
581 :
582 : // bridge
583 1 : Reference< XBridge > xBridge( xBridgeFactory->createBridge(
584 : OUString(), aUnoUrlToken,
585 1 : xConnection, xInstanceProvider ) );
586 :
587 1 : if (bSingleAccept)
588 : {
589 1 : Reference< XComponent > xComp( xBridge, UNO_QUERY );
590 1 : if (! xComp.is())
591 0 : throw RuntimeException( OUString( "bridge factory does not export interface \"com.sun.star.lang.XComponent\"!" ), Reference< XInterface >() );
592 1 : ODisposingListener::waitFor( xComp );
593 1 : xComp->dispose();
594 : // explicitly dispose the remote bridge so that it joins
595 : // on all spawned threads before process exit (see
596 : // binaryurp/source/bridge.cxx for details)
597 1 : break;
598 : }
599 1 : }
600 : }
601 : else // no uno url
602 : {
603 1 : Reference< XInterface > xInstance;
604 1 : if (!aImplName.isEmpty()) // manually via loader
605 0 : xInstance = loadComponent( xContext, aImplName, aLocation );
606 : else // via service manager
607 1 : createInstance( xInstance, xContext, aServiceName );
608 :
609 : // execution
610 2 : Reference< XMain > xMain( xInstance, UNO_QUERY );
611 1 : if (xMain.is())
612 : {
613 1 : nRet = xMain->run( aParams );
614 : }
615 : else
616 : {
617 0 : Reference< XComponent > xComp( xInstance, UNO_QUERY );
618 0 : if (xComp.is())
619 0 : xComp->dispose();
620 0 : throw RuntimeException( OUString( "component does not export interface interface \"com.sun.star.lang.XMain\"!" ), Reference< XInterface >() );
621 1 : }
622 2 : }
623 : }
624 0 : catch (Exception & rExc)
625 : {
626 0 : out( "\n> error: " );
627 0 : out( rExc.Message );
628 0 : out( "\n> dying..." );
629 0 : nRet = 1;
630 : }
631 :
632 : // cleanup
633 4 : Reference< XComponent > xComp( xContext, UNO_QUERY );
634 2 : if (xComp.is())
635 2 : xComp->dispose();
636 :
637 : #if OSL_DEBUG_LEVEL > 1
638 : out( "\n" );
639 : #endif
640 4 : return nRet;
641 : }
642 :
643 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|