1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoexe.cxx,v $
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 ************************************************************************/
35 #include <osl/diagnose.h>
36 #include <osl/mutex.hxx>
37 #include <osl/conditn.hxx>
38 #include <osl/module.h>
40 #include <rtl/process.h>
41 #include <rtl/string.h>
42 #include <rtl/strbuf.hxx>
43 #include <rtl/ustrbuf.hxx>
45 #include <uno/environment.h>
46 #include <uno/mapping.hxx>
48 #include <cppuhelper/factory.hxx>
49 #include <cppuhelper/bootstrap.hxx>
50 #include <cppuhelper/servicefactory.hxx>
51 #include <cppuhelper/shlib.hxx>
52 #include <cppuhelper/implbase1.hxx>
54 #include <com/sun/star/lang/XMain.hpp>
55 #include <com/sun/star/lang/XInitialization.hpp>
56 #include <com/sun/star/lang/XComponent.hpp>
57 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <com/sun/star/lang/XEventListener.hpp>
60 #include <com/sun/star/container/XSet.hpp>
61 #include <com/sun/star/loader/XImplementationLoader.hpp>
62 #include <com/sun/star/registry/XSimpleRegistry.hpp>
63 #include <com/sun/star/registry/XRegistryKey.hpp>
64 #include <com/sun/star/connection/XAcceptor.hpp>
65 #include <com/sun/star/connection/XConnection.hpp>
66 #include <com/sun/star/bridge/XBridgeFactory.hpp>
67 #include <com/sun/star/bridge/XBridge.hpp>
68 #include <osl/process.h>
69 #include <osl/thread.h>
70 #include <osl/file.hxx>
75 #define SEPARATOR '\\'
82 using namespace com::sun::star::uno
;
83 using namespace com::sun::star::lang
;
84 using namespace com::sun::star::loader
;
85 using namespace com::sun::star::registry
;
86 using namespace com::sun::star::connection
;
87 using namespace com::sun::star::bridge
;
88 using namespace com::sun::star::container
;
93 static sal_Bool
isFileUrl(const OUString
& fileName
)
95 if (fileName
.indexOf(OUString::createFromAscii("file://")) == 0 )
100 static OUString
convertToFileUrl(const OUString
& fileName
)
102 if ( isFileUrl(fileName
) )
107 OUString uUrlFileName
;
108 if ( fileName
.indexOf('.') == 0 || fileName
.indexOf(SEPARATOR
) < 0 )
110 OUString uWorkingDir
;
111 if (osl_getProcessWorkingDir(&uWorkingDir
.pData
) != osl_Process_E_None
) {
114 if (FileBase::getAbsoluteFileURL(uWorkingDir
, fileName
, uUrlFileName
)
121 if (FileBase::getFileURLFromSystemPath(fileName
, uUrlFileName
)
131 static sal_Bool s_quiet
= false;
133 //--------------------------------------------------------------------------------------------------
134 static inline void out( const sal_Char
* pText
)
137 fprintf( stderr
, "%s", pText
);
139 //--------------------------------------------------------------------------------------------------
140 static inline void out( const OUString
& rText
)
144 OString
aText( OUStringToOString( rText
, RTL_TEXTENCODING_ASCII_US
) );
145 fprintf( stderr
, "%s", aText
.getStr() );
149 //--------------------------------------------------------------------------------------------------
150 static const char arUsingText
[] =
152 "uno [-c ComponentImplementationName -l LocationUrl | -s ServiceName]\n"
153 " [-ro ReadOnlyRegistry1] [-ro ReadOnlyRegistry2] ... [-rw ReadWriteRegistry]\n"
154 " [-u uno:(socket[,host=HostName][,port=nnn]|pipe[,name=PipeName]);<protocol>;Name\n"
155 " [--singleaccept] [--singleinstance]]\n"
157 " [-- Argument1 Argument2 ...]\n";
159 //--------------------------------------------------------------------------------------------------
160 static sal_Bool
readOption( OUString
* pValue
, const sal_Char
* pOpt
,
161 sal_Int32
* pnIndex
, const OUString
& aArg
)
162 throw (RuntimeException
)
164 const OUString dash
= OUString(RTL_CONSTASCII_USTRINGPARAM("-"));
165 if(aArg
.indexOf(dash
) != 0)
168 OUString aOpt
= OUString::createFromAscii( pOpt
);
170 if (aArg
.getLength() < aOpt
.getLength())
173 if (aOpt
.equalsIgnoreAsciiCase( aArg
.copy(1) ))
175 // take next argument
178 rtl_getAppCommandArg(*pnIndex
, &pValue
->pData
);
179 if (*pnIndex
>= (sal_Int32
)rtl_getAppCommandArgCount() || pValue
->copy(1).equals(dash
))
181 OUStringBuffer
buf( 32 );
182 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("incomplete option \"-") );
183 buf
.appendAscii( pOpt
);
184 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" given!") );
185 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
189 #if OSL_DEBUG_LEVEL > 1
190 out( "\n> identified option -" );
193 OString tmp
= OUStringToOString(aArg
, RTL_TEXTENCODING_ASCII_US
);
200 else if (aArg
.indexOf(aOpt
) == 1)
202 *pValue
= aArg
.copy(1 + aOpt
.getLength());
203 #if OSL_DEBUG_LEVEL > 1
204 out( "\n> identified option -" );
207 OString tmp
= OUStringToOString(aArg
.copy(aOpt
.getLength()), RTL_TEXTENCODING_ASCII_US
);
216 //--------------------------------------------------------------------------------------------------
217 static sal_Bool
readOption( sal_Bool
* pbOpt
, const sal_Char
* pOpt
,
218 sal_Int32
* pnIndex
, const OUString
& aArg
)
220 const OUString
dashdash(RTL_CONSTASCII_USTRINGPARAM("--"));
221 OUString aOpt
= OUString::createFromAscii(pOpt
);
223 if(aArg
.indexOf(dashdash
) == 0 && aOpt
.equals(aArg
.copy(2)))
227 #if OSL_DEBUG_LEVEL > 1
228 out( "\n> identified option --" );
237 //##################################################################################################
238 //##################################################################################################
239 //##################################################################################################
242 //--------------------------------------------------------------------------------------------------
245 Reference
< T
> & rxOut
,
246 const Reference
< XComponentContext
> & xContext
,
247 const OUString
& rServiceName
)
250 Reference
< XMultiComponentFactory
> xMgr( xContext
->getServiceManager() );
251 Reference
< XInterface
> x( xMgr
->createInstanceWithContext( rServiceName
, xContext
) );
255 static sal_Bool s_bSet
= sal_False
;
258 MutexGuard
aGuard( Mutex::getGlobalMutex() );
261 Reference
< XSet
> xSet( xMgr
, UNO_QUERY
);
264 Reference
< XMultiServiceFactory
> xSF( xMgr
, UNO_QUERY
);
266 xSet
->insert( makeAny( loadSharedLibComponentFactory(
267 OUString( RTL_CONSTASCII_USTRINGPARAM(
268 "acceptor.uno" SAL_DLLEXTENSION
) ),
270 OUString( RTL_CONSTASCII_USTRINGPARAM(
271 "com.sun.star.comp.io.Acceptor") ),
272 xSF
, Reference
< XRegistryKey
>() ) ) );
274 xSet
->insert( makeAny( loadSharedLibComponentFactory(
275 OUString( RTL_CONSTASCII_USTRINGPARAM(
276 "connector.uno" SAL_DLLEXTENSION
) ),
278 OUString( RTL_CONSTASCII_USTRINGPARAM(
279 "com.sun.star.comp.io.Connector") ),
280 xSF
, Reference
< XRegistryKey
>() ) ) );
282 xSet
->insert( makeAny( loadSharedLibComponentFactory(
283 OUString( RTL_CONSTASCII_USTRINGPARAM(
284 "remotebridge.uno" SAL_DLLEXTENSION
) ),
286 OUString( RTL_CONSTASCII_USTRINGPARAM(
287 "com.sun.star.comp.remotebridges."
289 xSF
, Reference
< XRegistryKey
>() ) ) );
291 xSet
->insert( makeAny( loadSharedLibComponentFactory(
292 OUString( RTL_CONSTASCII_USTRINGPARAM(
293 "bridgefac.uno" SAL_DLLEXTENSION
) ),
295 OUString( RTL_CONSTASCII_USTRINGPARAM(
296 "com.sun.star.comp.remotebridges."
298 xSF
, Reference
< XRegistryKey
>() ) ) );
303 x
= xMgr
->createInstanceWithContext( rServiceName
, xContext
);
308 OUStringBuffer
buf( 64 );
309 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get service instance \"") );
310 buf
.append( rServiceName
);
311 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
312 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
315 rxOut
= Reference
< T
>::query( x
);
318 OUStringBuffer
buf( 64 );
319 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("service instance \"") );
320 buf
.append( rServiceName
);
321 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" does not support demanded interface \"") );
322 const Type
& rType
= ::getCppuType( (const Reference
< T
> *)0 );
323 buf
.append( rType
.getTypeName() );
324 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
325 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
328 //--------------------------------------------------------------------------------------------------
329 static Reference
< XSimpleRegistry
> nestRegistries(
330 const Reference
< XSimpleRegistry
> & xReadWrite
,
331 const Reference
< XSimpleRegistry
> & xReadOnly
)
334 Reference
< XSimpleRegistry
> xReg( createNestedRegistry() );
337 throw RuntimeException(
338 OUString( RTL_CONSTASCII_USTRINGPARAM("no nested registry service!" ) ),
339 Reference
< XInterface
>() );
342 Reference
< XInitialization
> xInit( xReg
, UNO_QUERY
);
344 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("nested registry does not export interface \"com.sun.star.lang.XInitialization\"!" ) ), Reference
< XInterface
>() );
346 Sequence
< Any
> aArgs( 2 );
347 aArgs
[0] <<= xReadWrite
;
348 aArgs
[1] <<= xReadOnly
;
349 xInit
->initialize( aArgs
);
353 //--------------------------------------------------------------------------------------------------
354 static Reference
< XSimpleRegistry
> openRegistry(
355 const OUString
& rURL
,
356 sal_Bool bReadOnly
, sal_Bool bCreate
)
359 Reference
< XSimpleRegistry
> xNewReg( createSimpleRegistry() );
362 throw RuntimeException(
363 OUString( RTL_CONSTASCII_USTRINGPARAM("no simple registry service!" ) ),
364 Reference
< XInterface
>() );
369 xNewReg
->open( convertToFileUrl(rURL
), bReadOnly
, bCreate
);
370 if (xNewReg
->isValid())
379 out( "\n> warning: cannot open registry \"" );
382 out( "\" for reading, ignoring!" );
384 out( "\" for reading and writing, ignoring!" );
385 return Reference
< XSimpleRegistry
>();
387 //--------------------------------------------------------------------------------------------------
388 static Reference
< XInterface
> loadComponent(
389 const Reference
< XComponentContext
> & xContext
,
390 const OUString
& rImplName
, const OUString
& rLocation
)
393 // determine loader to be used
394 sal_Int32 nDot
= rLocation
.lastIndexOf( '.' );
395 if (nDot
> 0 && nDot
< rLocation
.getLength())
397 Reference
< XImplementationLoader
> xLoader
;
399 OUString
aExt( rLocation
.copy( nDot
+1 ) );
401 if (aExt
.compareToAscii( "dll" ) == 0 ||
402 aExt
.compareToAscii( "exe" ) == 0 ||
403 aExt
.compareToAscii( "dylib" ) == 0 ||
404 aExt
.compareToAscii( "so" ) == 0)
407 xLoader
, xContext
, OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary") ) );
409 else if (aExt
.compareToAscii( "jar" ) == 0 ||
410 aExt
.compareToAscii( "class" ) == 0)
413 xLoader
, xContext
, OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.Java") ) );
417 OUStringBuffer
buf( 64 );
418 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("unknown extension of \"") );
419 buf
.append( rLocation
);
420 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"! No loader available!") );
421 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
424 Reference
< XInterface
> xInstance
;
427 Reference
< XInterface
> xFactory( xLoader
->activate(
428 rImplName
, OUString(), rLocation
, Reference
< XRegistryKey
>() ) );
431 Reference
< XSingleComponentFactory
> xCFac( xFactory
, UNO_QUERY
);
434 xInstance
= xCFac
->createInstanceWithContext( xContext
);
438 Reference
< XSingleServiceFactory
> xSFac( xFactory
, UNO_QUERY
);
441 out( "\n> warning: ignroing context for implementation \"" );
444 xInstance
= xSFac
->createInstance();
449 if (! xInstance
.is())
451 OUStringBuffer
buf( 64 );
452 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("activating component \"") );
453 buf
.append( rImplName
);
454 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" from location \"") );
455 buf
.append( rLocation
);
456 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" failed!") );
457 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
464 OUStringBuffer
buf( 64 );
465 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("location \"") );
466 buf
.append( rLocation
);
467 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" has no extension! Cannot determine loader to be used!") );
468 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
473 //##################################################################################################
474 //##################################################################################################
475 //##################################################################################################
478 //==================================================================================================
479 class OInstanceProvider
480 : public WeakImplHelper1
< XInstanceProvider
>
482 Reference
< XComponentContext
> _xContext
;
484 Mutex _aSingleInstanceMutex
;
485 Reference
< XInterface
> _xSingleInstance
;
486 sal_Bool _bSingleInstance
;
490 OUString _aServiceName
;
491 Sequence
< Any
> _aInitParams
;
493 OUString _aInstanceName
;
495 inline Reference
< XInterface
> createInstance() throw (Exception
);
498 OInstanceProvider( const Reference
< XComponentContext
> & xContext
,
499 const OUString
& rImplName
, const OUString
& rLocation
,
500 const OUString
& rServiceName
, const Sequence
< Any
> & rInitParams
,
501 sal_Bool bSingleInstance
, const OUString
& rInstanceName
)
502 : _xContext( xContext
)
503 , _bSingleInstance( bSingleInstance
)
504 , _aImplName( rImplName
)
505 , _aLocation( rLocation
)
506 , _aServiceName( rServiceName
)
507 , _aInitParams( rInitParams
)
508 , _aInstanceName( rInstanceName
)
512 virtual Reference
< XInterface
> SAL_CALL
getInstance( const OUString
& rName
)
513 throw (NoSuchElementException
, RuntimeException
);
515 //__________________________________________________________________________________________________
516 inline Reference
< XInterface
> OInstanceProvider::createInstance()
519 Reference
< XInterface
> xRet
;
520 if (_aImplName
.getLength()) // manually via loader
521 xRet
= loadComponent( _xContext
, _aImplName
, _aLocation
);
522 else // via service manager
523 unoexe::createInstance( xRet
, _xContext
, _aServiceName
);
526 Reference
< XInitialization
> xInit( xRet
, UNO_QUERY
);
528 xInit
->initialize( _aInitParams
);
532 //__________________________________________________________________________________________________
533 Reference
< XInterface
> OInstanceProvider::getInstance( const OUString
& rName
)
534 throw (NoSuchElementException
, RuntimeException
)
538 if (_aInstanceName
== rName
)
540 Reference
< XInterface
> xRet
;
542 if (_aImplName
.getLength() == 0 && _aServiceName
.getLength() == 0)
546 RTL_CONSTASCII_STRINGPARAM("uno.ComponentContext") ) );
549 else if (_bSingleInstance
)
551 if (! _xSingleInstance
.is())
553 MutexGuard
aGuard( _aSingleInstanceMutex
);
554 if (! _xSingleInstance
.is())
556 _xSingleInstance
= createInstance();
559 xRet
= _xSingleInstance
;
563 xRet
= createInstance();
569 catch (Exception
& rExc
)
571 out( "\n> error: " );
574 OUStringBuffer
buf( 64 );
575 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("no such element \"") );
577 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
578 throw NoSuchElementException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
581 //==================================================================================================
582 struct ODisposingListener
: public WeakImplHelper1
< XEventListener
>
587 virtual void SAL_CALL
disposing( const EventObject
& rEvt
)
588 throw (RuntimeException
);
590 //----------------------------------------------------------------------------------------------
591 static void waitFor( const Reference
< XComponent
> & xComp
);
593 //__________________________________________________________________________________________________
594 void ODisposingListener::disposing( const EventObject
& )
595 throw (RuntimeException
)
599 //--------------------------------------------------------------------------------------------------
600 void ODisposingListener::waitFor( const Reference
< XComponent
> & xComp
)
602 ODisposingListener
* pListener
= new ODisposingListener();
603 Reference
< XEventListener
> xListener( pListener
);
605 xComp
->addEventListener( xListener
);
606 pListener
->cDisposed
.wait();
610 //##################################################################################################
611 //##################################################################################################
612 //##################################################################################################
615 //##################################################################################################
616 } // namespace unoexe
618 using namespace unoexe
;
620 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
,)
629 Reference
< XComponentContext
> xContext
;
634 OUString aImplName
, aLocation
, aServiceName
, aUnoUrl
;
635 vector
< OUString
> aReadOnlyRegistries
;
636 Sequence
< OUString
> aParams
;
637 sal_Bool bSingleAccept
= sal_False
;
638 sal_Bool bSingleInstance
= sal_False
;
640 //#### read command line arguments #########################################################
642 bool bOldRegistryMimic
= false;
643 bool bNewRegistryMimic
= false;
644 OUString aReadWriteRegistry
;
647 sal_Int32 nCount
= (sal_Int32
)rtl_getAppCommandArgCount();
648 // read up to arguments
649 while (nPos
< nCount
)
653 rtl_getAppCommandArg(nPos
, &arg
.pData
);
655 const OUString dashdash
= OUString(RTL_CONSTASCII_USTRINGPARAM("--"));
662 if (readOption( &aImplName
, "c", &nPos
, arg
) ||
663 readOption( &aLocation
, "l", &nPos
, arg
) ||
664 readOption( &aServiceName
, "s", &nPos
, arg
) ||
665 readOption( &aUnoUrl
, "u", &nPos
, arg
) ||
666 readOption( &s_quiet
, "quiet", &nPos
, arg
) ||
667 readOption( &bSingleAccept
, "singleaccept", &nPos
, arg
) ||
668 readOption( &bSingleInstance
, "singleinstance", &nPos
, arg
))
673 if (readOption( &aRegistry
, "ro", &nPos
, arg
))
675 aReadOnlyRegistries
.push_back( aRegistry
);
676 bNewRegistryMimic
= true;
679 if (readOption( &aReadWriteRegistry
, "rw", &nPos
, arg
))
681 bNewRegistryMimic
= true;
684 if (readOption( &aRegistry
, "r", &nPos
, arg
))
686 aReadOnlyRegistries
.push_back( aRegistry
);
687 aReadWriteRegistry
= aRegistry
;
688 out( "\n> warning: DEPRECATED use of option -r, use -ro or -rw!" );
689 bOldRegistryMimic
= true;
693 // else illegal argument
694 OUStringBuffer
buf( 64 );
695 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("unexpected parameter \"") );
697 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
698 throw RuntimeException( buf
.makeStringAndClear(), Reference
< XInterface
>() );
701 if (bOldRegistryMimic
) // last one was set to be read-write
703 aReadOnlyRegistries
.pop_back();
704 if (bOldRegistryMimic
&& bNewRegistryMimic
)
706 throw RuntimeException(
707 OUString( RTL_CONSTASCII_USTRINGPARAM("mixing with DEPRECATED registry options!") ),
708 Reference
< XInterface
>() );
712 if ((aImplName
.getLength() != 0) && (aServiceName
.getLength() != 0))
713 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("give component exOR service name!" ) ), Reference
< XInterface
>() );
714 if (aImplName
.getLength() == 0 && aServiceName
.getLength() == 0)
716 if (! aUnoUrl
.endsWithIgnoreAsciiCaseAsciiL(
717 RTL_CONSTASCII_STRINGPARAM(";uno.ComponentContext") ))
718 throw RuntimeException(
719 OUString( RTL_CONSTASCII_USTRINGPARAM(
720 "expected UNO-URL with instance name "
721 "uno.ComponentContext!") ),
722 Reference
<XInterface
>() );
724 throw RuntimeException(
725 OUString( RTL_CONSTASCII_USTRINGPARAM(
726 "unexpected option --singleinstance!") ),
727 Reference
<XInterface
>() );
729 if (aImplName
.getLength() && !aLocation
.getLength())
730 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("give component location!" ) ), Reference
< XInterface
>() );
731 if (aServiceName
.getLength() && aLocation
.getLength())
732 out( "\n> warning: service name given, will ignore location!" );
734 // read component params
735 aParams
.realloc( nCount
- nPos
);
736 OUString
* pParams
= aParams
.getArray();
738 sal_Int32 nOffset
= nPos
;
739 for ( ; nPos
< nCount
; ++nPos
)
741 if (rtl_getAppCommandArg( nPos
, &pParams
[nPos
-nOffset
].pData
)
742 != osl_Process_E_None
)
748 if (aReadOnlyRegistries
.size() > 0 ||
749 aReadWriteRegistry
.getLength() > 0)
751 //#### create registry #############################################
753 Reference
< XSimpleRegistry
> xRegistry
;
755 // ReadOnly registries
756 for ( size_t nReg
= 0; nReg
< aReadOnlyRegistries
.size(); ++nReg
)
758 #if OSL_DEBUG_LEVEL > 1
759 out( "\n> trying to open ro registry: " );
760 out( OUStringToOString(
761 aReadOnlyRegistries
[ nReg
],
762 RTL_TEXTENCODING_ASCII_US
).getStr() );
764 Reference
< XSimpleRegistry
> xNewReg(
766 aReadOnlyRegistries
[ nReg
], sal_True
, sal_False
) );
768 xRegistry
= (xRegistry
.is() ? nestRegistries(
769 xNewReg
, xRegistry
) : xNewReg
);
771 if (aReadWriteRegistry
.getLength())
773 #if OSL_DEBUG_LEVEL > 1
774 out( "\n> trying to open rw registry: " );
775 out( OUStringToOString(
777 RTL_TEXTENCODING_ASCII_US
).getStr() );
779 // ReadWrite registry
780 Reference
< XSimpleRegistry
> xNewReg(
781 openRegistry( aReadWriteRegistry
, sal_False
, sal_True
) );
783 xRegistry
= (xRegistry
.is()
784 ? nestRegistries( xNewReg
, xRegistry
)
788 OSL_ASSERT( xRegistry
.is() );
789 xContext
= bootstrap_InitialComponentContext( xRegistry
);
793 xContext
= defaultBootstrap_InitialComponentContext();
796 //#### accept, instanciate, etc. ###########################################################
798 if (aUnoUrl
.getLength()) // accepting connections
800 sal_Int32 nIndex
= 0, nTokens
= 0;
801 do { aUnoUrl
.getToken( 0, ';', nIndex
); nTokens
++; } while( nIndex
!= -1 );
802 if (nTokens
!= 3 || aUnoUrl
.getLength() < 10 ||
803 !aUnoUrl
.copy( 0, 4 ).equalsIgnoreAsciiCase( OUString( RTL_CONSTASCII_USTRINGPARAM("uno:") ) ))
805 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("illegal uno url given!" ) ), Reference
< XInterface
>() );
808 OUString
aConnectDescr( aUnoUrl
.getToken( 0, ';', nIndex
).copy( 4 ) ); // uno:CONNECTDESCR;iiop;InstanceName
809 OUString
aInstanceName( aUnoUrl
.getToken( 1, ';', nIndex
) );
811 Reference
< XAcceptor
> xAcceptor
;
814 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Acceptor") ) );
817 Sequence
< Any
> aInitParams( aParams
.getLength() );
818 const OUString
* p
= aParams
.getConstArray();
819 Any
* pInitParams
= aInitParams
.getArray();
820 for ( sal_Int32 i
= aParams
.getLength(); i
--; )
822 pInitParams
[i
] = makeAny( p
[i
] );
826 Reference
< XInstanceProvider
> xInstanceProvider( new OInstanceProvider(
827 xContext
, aImplName
, aLocation
, aServiceName
, aInitParams
,
828 bSingleInstance
, aInstanceName
) );
831 OUString
aUnoUrlToken( aUnoUrl
.getToken( 1, ';', nIndex
) );
835 out( "\n> accepting " );
836 out( aConnectDescr
);
838 Reference
< XConnection
> xConnection( xAcceptor
->accept( aConnectDescr
) );
839 out( "connection established." );
841 Reference
< XBridgeFactory
> xBridgeFactory
;
843 xBridgeFactory
, xContext
,
844 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ) );
847 Reference
< XBridge
> xBridge( xBridgeFactory
->createBridge(
848 OUString(), aUnoUrlToken
,
849 xConnection
, xInstanceProvider
) );
853 Reference
< XComponent
> xComp( xBridge
, UNO_QUERY
);
855 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("bridge factory does not export interface \"com.sun.star.lang.XComponent\"!" ) ), Reference
< XInterface
>() );
856 ODisposingListener::waitFor( xComp
);
863 Reference
< XInterface
> xInstance
;
864 if (aImplName
.getLength()) // manually via loader
865 xInstance
= loadComponent( xContext
, aImplName
, aLocation
);
866 else // via service manager
867 createInstance( xInstance
, xContext
, aServiceName
);
870 Reference
< XMain
> xMain( xInstance
, UNO_QUERY
);
873 nRet
= xMain
->run( aParams
);
877 Reference
< XComponent
> xComp( xInstance
, UNO_QUERY
);
880 throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("component does not export interface interface \"com.sun.star.lang.XMain\"!" ) ), Reference
< XInterface
>() );
884 catch (Exception
& rExc
)
886 out( "\n> error: " );
888 out( "\n> dying..." );
893 Reference
< XComponent
> xComp( xContext
, UNO_QUERY
);