1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*647a425cSAndrew Rist * distributed with this work for additional information
6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist * software distributed under the License is distributed on an
15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the
17*647a425cSAndrew Rist * specific language governing permissions and limitations
18*647a425cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*647a425cSAndrew Rist *************************************************************/
21*647a425cSAndrew Rist
22*647a425cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir #include <osl/mutex.hxx>
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <hash_map>
31cdf0e10cSrcweir #include <hash_set>
32cdf0e10cSrcweir #include <list>
33cdf0e10cSrcweir #include <uno/mapping.hxx>
34cdf0e10cSrcweir #include <uno/dispatcher.h>
35cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
36cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
37cdf0e10cSrcweir #include <cppuhelper/component.hxx>
38cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
39cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE1_HXX
40cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
43cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
44cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir #include <rtl/unload.h>
47cdf0e10cSrcweir #include <cppuhelper/component_context.hxx>
48cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
49cdf0e10cSrcweir #include <cppuhelper/compbase8.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
53cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
55cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
56cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
57cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
58cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
59cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
61cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
62cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
63cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
64cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp>
65cdf0e10cSrcweir #include <com/sun/star/container/XElementAccess.hpp>
66cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
67cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
68cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
69cdf0e10cSrcweir #include <com/sun/star/uno/XUnloadingPreference.hpp>
70cdf0e10cSrcweir
71cdf0e10cSrcweir #include <bootstrapservices.hxx>
72cdf0e10cSrcweir
73cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir using namespace com::sun::star;
77cdf0e10cSrcweir using namespace com::sun::star::uno;
78cdf0e10cSrcweir using namespace com::sun::star::beans;
79cdf0e10cSrcweir using namespace com::sun::star::registry;
80cdf0e10cSrcweir using namespace com::sun::star::lang;
81cdf0e10cSrcweir using namespace com::sun::star::container;
82cdf0e10cSrcweir using namespace cppu;
83cdf0e10cSrcweir using namespace osl;
84cdf0e10cSrcweir using namespace rtl;
85cdf0e10cSrcweir using namespace std;
86cdf0e10cSrcweir
87cdf0e10cSrcweir rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
88cdf0e10cSrcweir
89cdf0e10cSrcweir namespace stoc_bootstrap
90cdf0e10cSrcweir {
smgr_wrapper_getSupportedServiceNames()91cdf0e10cSrcweir Sequence< OUString > smgr_wrapper_getSupportedServiceNames()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir static Sequence < OUString > *pNames = 0;
94cdf0e10cSrcweir if( ! pNames )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
97cdf0e10cSrcweir if( !pNames )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir static Sequence< OUString > seqNames(1);
100cdf0e10cSrcweir seqNames.getArray()[0] = OUString(
101cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory") );
102cdf0e10cSrcweir pNames = &seqNames;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir return *pNames;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
smgr_wrapper_getImplementationName()108cdf0e10cSrcweir OUString smgr_wrapper_getImplementationName()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir static OUString *pImplName = 0;
111cdf0e10cSrcweir if( ! pImplName )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
114cdf0e10cSrcweir if( ! pImplName )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir static OUString implName(
117cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.OServiceManagerWrapper" ) );
118cdf0e10cSrcweir pImplName = &implName;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir }
121cdf0e10cSrcweir return *pImplName;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
smgr_getSupportedServiceNames()124cdf0e10cSrcweir Sequence< OUString > smgr_getSupportedServiceNames()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir static Sequence < OUString > *pNames = 0;
127cdf0e10cSrcweir if( ! pNames )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
130cdf0e10cSrcweir if( !pNames )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir static Sequence< OUString > seqNames(2);
133cdf0e10cSrcweir seqNames.getArray()[0] = OUString(
134cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory") );
135cdf0e10cSrcweir seqNames.getArray()[1] = OUString(
136cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.ServiceManager") );
137cdf0e10cSrcweir pNames = &seqNames;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir return *pNames;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
smgr_getImplementationName()143cdf0e10cSrcweir OUString smgr_getImplementationName()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir static OUString *pImplName = 0;
146cdf0e10cSrcweir if( ! pImplName )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
149cdf0e10cSrcweir if( ! pImplName )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir static OUString implName(
152cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.OServiceManager" ) );
153cdf0e10cSrcweir pImplName = &implName;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir return *pImplName;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
regsmgr_getSupportedServiceNames()159cdf0e10cSrcweir Sequence< OUString > regsmgr_getSupportedServiceNames()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir static Sequence < OUString > *pNames = 0;
162cdf0e10cSrcweir if( ! pNames )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
165cdf0e10cSrcweir if( !pNames )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir static Sequence< OUString > seqNames(2);
168cdf0e10cSrcweir seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory"));
169cdf0e10cSrcweir seqNames.getArray()[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.RegistryServiceManager"));
170cdf0e10cSrcweir pNames = &seqNames;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir return *pNames;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
regsmgr_getImplementationName()176cdf0e10cSrcweir OUString regsmgr_getImplementationName()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir static OUString *pImplName = 0;
179cdf0e10cSrcweir if( ! pImplName )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() );
182cdf0e10cSrcweir if( ! pImplName )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir static OUString implName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.ORegistryServiceManager" ) );
185cdf0e10cSrcweir pImplName = &implName;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir return *pImplName;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir namespace stoc_smgr
193cdf0e10cSrcweir {
smgr_getImplementationId()194cdf0e10cSrcweir static Sequence< sal_Int8 > smgr_getImplementationId()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir static OImplementationId * s_pId = 0;
197cdf0e10cSrcweir if (! s_pId)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
200cdf0e10cSrcweir if (! s_pId)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir static OImplementationId s_aId;
203cdf0e10cSrcweir s_pId = &s_aId;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir return s_pId->getImplementationId();
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir
retrieveAsciiValueList(const Reference<XSimpleRegistry> & xReg,const OUString & keyName)210cdf0e10cSrcweir static Sequence< OUString > retrieveAsciiValueList(
211cdf0e10cSrcweir const Reference< XSimpleRegistry > &xReg, const OUString &keyName )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir Reference< XEnumerationAccess > xAccess( xReg, UNO_QUERY );
214cdf0e10cSrcweir Sequence< OUString > seq;
215cdf0e10cSrcweir if( xAccess.is() )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir Reference< XEnumeration > xEnum = xAccess->createEnumeration();
218cdf0e10cSrcweir while( xEnum.is() && xEnum->hasMoreElements() )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir Reference< XSimpleRegistry > xTempReg;
221cdf0e10cSrcweir xEnum->nextElement() >>= xTempReg;
222cdf0e10cSrcweir if( xTempReg.is() )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir Sequence< OUString > seq2 = retrieveAsciiValueList( xTempReg, keyName );
225cdf0e10cSrcweir
226cdf0e10cSrcweir if( seq2.getLength() )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir sal_Int32 n1Len = seq.getLength();
229cdf0e10cSrcweir sal_Int32 n2Len = seq2.getLength();
230cdf0e10cSrcweir
231cdf0e10cSrcweir seq.realloc( n1Len + n2Len );
232cdf0e10cSrcweir const OUString *pSource = seq2.getConstArray();
233cdf0e10cSrcweir OUString *pTarget = seq.getArray();
234cdf0e10cSrcweir for( int i = 0 ; i < n2Len ; i ++ )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir pTarget[i+n1Len] = pSource[i];
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir else if( xReg.is () )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir try
245cdf0e10cSrcweir {
246cdf0e10cSrcweir Reference< XRegistryKey > rRootKey = xReg->getRootKey();
247cdf0e10cSrcweir if( rRootKey.is() )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir Reference<XRegistryKey > xKey = rRootKey->openKey(keyName);
250cdf0e10cSrcweir if( xKey.is() )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir seq = xKey->getAsciiListValue();
253cdf0e10cSrcweir }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir catch( InvalidRegistryException & )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir }
259cdf0e10cSrcweir catch (InvalidValueException &)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir return seq;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
266cdf0e10cSrcweir /*****************************************************************************
267cdf0e10cSrcweir Enumeration by ServiceName
268cdf0e10cSrcweir *****************************************************************************/
269cdf0e10cSrcweir struct hashRef_Impl
270cdf0e10cSrcweir {
operator ()stoc_smgr::hashRef_Impl271cdf0e10cSrcweir size_t operator()(const Reference<XInterface > & rName) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir // query to XInterface. The cast to XInterface* must be the same for the same object
274cdf0e10cSrcweir Reference<XInterface > x( Reference<XInterface >::query( rName ) );
275cdf0e10cSrcweir return (size_t)x.get();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir };
278cdf0e10cSrcweir
279cdf0e10cSrcweir struct equaltoRef_Impl
280cdf0e10cSrcweir {
operator ()stoc_smgr::equaltoRef_Impl281cdf0e10cSrcweir size_t operator()(const Reference<XInterface > & rName1, const Reference<XInterface > & rName2 ) const
282cdf0e10cSrcweir { return rName1 == rName2; }
283cdf0e10cSrcweir };
284cdf0e10cSrcweir
285cdf0e10cSrcweir typedef hash_set
286cdf0e10cSrcweir <
287cdf0e10cSrcweir Reference<XInterface >,
288cdf0e10cSrcweir hashRef_Impl,
289cdf0e10cSrcweir equaltoRef_Impl
290cdf0e10cSrcweir > HashSet_Ref;
291cdf0e10cSrcweir
292cdf0e10cSrcweir
293cdf0e10cSrcweir class ServiceEnumeration_Impl : public WeakImplHelper1< XEnumeration >
294cdf0e10cSrcweir {
295cdf0e10cSrcweir public:
ServiceEnumeration_Impl(const Sequence<Reference<XInterface>> & rFactories)296cdf0e10cSrcweir ServiceEnumeration_Impl( const Sequence< Reference<XInterface > > & rFactories )
297cdf0e10cSrcweir : aFactories( rFactories )
298cdf0e10cSrcweir , nIt( 0 )
299cdf0e10cSrcweir { g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); }
~ServiceEnumeration_Impl()300cdf0e10cSrcweir virtual ~ServiceEnumeration_Impl()
301cdf0e10cSrcweir { g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); }
302cdf0e10cSrcweir
303cdf0e10cSrcweir // XEnumeration
304cdf0e10cSrcweir sal_Bool SAL_CALL hasMoreElements()
305cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
306cdf0e10cSrcweir Any SAL_CALL nextElement()
307cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
308cdf0e10cSrcweir private:
309cdf0e10cSrcweir Mutex aMutex;
310cdf0e10cSrcweir Sequence< Reference<XInterface > > aFactories;
311cdf0e10cSrcweir sal_Int32 nIt;
312cdf0e10cSrcweir };
313cdf0e10cSrcweir
314cdf0e10cSrcweir // XEnumeration
hasMoreElements()315cdf0e10cSrcweir sal_Bool ServiceEnumeration_Impl::hasMoreElements() throw(::com::sun::star::uno::RuntimeException)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir MutexGuard aGuard( aMutex );
318cdf0e10cSrcweir return nIt != aFactories.getLength();
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
321cdf0e10cSrcweir // XEnumeration
nextElement()322cdf0e10cSrcweir Any ServiceEnumeration_Impl::nextElement()
323cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir MutexGuard aGuard( aMutex );
326cdf0e10cSrcweir if( nIt == aFactories.getLength() )
327cdf0e10cSrcweir throw NoSuchElementException();
328cdf0e10cSrcweir
329cdf0e10cSrcweir return Any( &aFactories.getConstArray()[nIt++], ::getCppuType( (const Reference<XInterface > *)0 ) );
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
332cdf0e10cSrcweir //==================================================================================================
333cdf0e10cSrcweir class PropertySetInfo_Impl : public WeakImplHelper1< beans::XPropertySetInfo >
334cdf0e10cSrcweir {
335cdf0e10cSrcweir Sequence< beans::Property > m_properties;
336cdf0e10cSrcweir
337cdf0e10cSrcweir public:
338cdf0e10cSrcweir inline PropertySetInfo_Impl( Sequence< beans::Property > const & properties ) SAL_THROW( () )
339cdf0e10cSrcweir : m_properties( properties )
340cdf0e10cSrcweir {}
341cdf0e10cSrcweir
342cdf0e10cSrcweir // XPropertySetInfo impl
343cdf0e10cSrcweir virtual Sequence< beans::Property > SAL_CALL getProperties()
344cdf0e10cSrcweir throw (RuntimeException);
345cdf0e10cSrcweir virtual beans::Property SAL_CALL getPropertyByName( OUString const & name )
346cdf0e10cSrcweir throw (beans::UnknownPropertyException, RuntimeException);
347cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasPropertyByName( OUString const & name )
348cdf0e10cSrcweir throw (RuntimeException);
349cdf0e10cSrcweir };
350cdf0e10cSrcweir //__________________________________________________________________________________________________
getProperties()351cdf0e10cSrcweir Sequence< beans::Property > PropertySetInfo_Impl::getProperties()
352cdf0e10cSrcweir throw (RuntimeException)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir return m_properties;
355cdf0e10cSrcweir }
356cdf0e10cSrcweir //__________________________________________________________________________________________________
getPropertyByName(OUString const & name)357cdf0e10cSrcweir beans::Property PropertySetInfo_Impl::getPropertyByName( OUString const & name )
358cdf0e10cSrcweir throw (beans::UnknownPropertyException, RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir beans::Property const * p = m_properties.getConstArray();
361cdf0e10cSrcweir for ( sal_Int32 nPos = m_properties.getLength(); nPos--; )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir if (p[ nPos ].Name.equals( name ))
364cdf0e10cSrcweir return p[ nPos ];
365cdf0e10cSrcweir }
366cdf0e10cSrcweir throw beans::UnknownPropertyException(
367cdf0e10cSrcweir OUSTR("unknown property: ") + name, Reference< XInterface >() );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir //__________________________________________________________________________________________________
hasPropertyByName(OUString const & name)370cdf0e10cSrcweir sal_Bool PropertySetInfo_Impl::hasPropertyByName( OUString const & name )
371cdf0e10cSrcweir throw (RuntimeException)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir beans::Property const * p = m_properties.getConstArray();
374cdf0e10cSrcweir for ( sal_Int32 nPos = m_properties.getLength(); nPos--; )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir if (p[ nPos ].Name.equals( name ))
377cdf0e10cSrcweir return sal_True;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir return sal_False;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir
383cdf0e10cSrcweir /*****************************************************************************
384cdf0e10cSrcweir Enumeration by implementation
385cdf0e10cSrcweir *****************************************************************************/
386cdf0e10cSrcweir class ImplementationEnumeration_Impl : public WeakImplHelper1< XEnumeration >
387cdf0e10cSrcweir {
388cdf0e10cSrcweir public:
ImplementationEnumeration_Impl(const HashSet_Ref & rImplementationMap)389cdf0e10cSrcweir ImplementationEnumeration_Impl( const HashSet_Ref & rImplementationMap )
390cdf0e10cSrcweir : aImplementationMap( rImplementationMap )
391cdf0e10cSrcweir , aIt( aImplementationMap.begin() )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
394cdf0e10cSrcweir }
395cdf0e10cSrcweir virtual ~ImplementationEnumeration_Impl();
396cdf0e10cSrcweir
397cdf0e10cSrcweir // XEnumeration
398cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasMoreElements()
399cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
400cdf0e10cSrcweir virtual Any SAL_CALL nextElement()
401cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
402cdf0e10cSrcweir
403cdf0e10cSrcweir private:
404cdf0e10cSrcweir Mutex aMutex;
405cdf0e10cSrcweir HashSet_Ref aImplementationMap;
406cdf0e10cSrcweir HashSet_Ref::iterator aIt;
407cdf0e10cSrcweir sal_Int32 nNext;
408cdf0e10cSrcweir Reference<XInterface > xNext;
409cdf0e10cSrcweir };
410cdf0e10cSrcweir
~ImplementationEnumeration_Impl()411cdf0e10cSrcweir ImplementationEnumeration_Impl::~ImplementationEnumeration_Impl()
412cdf0e10cSrcweir {
413cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
416cdf0e10cSrcweir // XEnumeration
hasMoreElements()417cdf0e10cSrcweir sal_Bool ImplementationEnumeration_Impl::hasMoreElements()
418cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir MutexGuard aGuard( aMutex );
421cdf0e10cSrcweir return aIt != aImplementationMap.end();
422cdf0e10cSrcweir }
423cdf0e10cSrcweir
424cdf0e10cSrcweir // XEnumeration
nextElement()425cdf0e10cSrcweir Any ImplementationEnumeration_Impl::nextElement()
426cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir MutexGuard aGuard( aMutex );
429cdf0e10cSrcweir if( aIt == aImplementationMap.end() )
430cdf0e10cSrcweir throw NoSuchElementException();
431cdf0e10cSrcweir
432cdf0e10cSrcweir Any ret( &(*aIt), ::getCppuType( (const Reference<XInterface > *)0 ) );
433cdf0e10cSrcweir ++aIt;
434cdf0e10cSrcweir return ret;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
437cdf0e10cSrcweir /*****************************************************************************
438cdf0e10cSrcweir Hash tables
439cdf0e10cSrcweir *****************************************************************************/
440cdf0e10cSrcweir struct equalOWString_Impl
441cdf0e10cSrcweir {
operator ()stoc_smgr::equalOWString_Impl442cdf0e10cSrcweir sal_Bool operator()(const OUString & s1, const OUString & s2) const
443cdf0e10cSrcweir { return s1 == s2; }
444cdf0e10cSrcweir };
445cdf0e10cSrcweir
446cdf0e10cSrcweir struct hashOWString_Impl
447cdf0e10cSrcweir {
operator ()stoc_smgr::hashOWString_Impl448cdf0e10cSrcweir size_t operator()(const OUString & rName) const
449cdf0e10cSrcweir { return rName.hashCode(); }
450cdf0e10cSrcweir };
451cdf0e10cSrcweir
452cdf0e10cSrcweir typedef hash_set
453cdf0e10cSrcweir <
454cdf0e10cSrcweir OUString,
455cdf0e10cSrcweir hashOWString_Impl,
456cdf0e10cSrcweir equalOWString_Impl
457cdf0e10cSrcweir > HashSet_OWString;
458cdf0e10cSrcweir
459cdf0e10cSrcweir typedef hash_multimap
460cdf0e10cSrcweir <
461cdf0e10cSrcweir OUString,
462cdf0e10cSrcweir Reference<XInterface >,
463cdf0e10cSrcweir hashOWString_Impl,
464cdf0e10cSrcweir equalOWString_Impl
465cdf0e10cSrcweir > HashMultimap_OWString_Interface;
466cdf0e10cSrcweir
467cdf0e10cSrcweir typedef hash_map
468cdf0e10cSrcweir <
469cdf0e10cSrcweir OUString,
470cdf0e10cSrcweir Reference<XInterface >,
471cdf0e10cSrcweir hashOWString_Impl,
472cdf0e10cSrcweir equalOWString_Impl
473cdf0e10cSrcweir > HashMap_OWString_Interface;
474cdf0e10cSrcweir
475cdf0e10cSrcweir /*****************************************************************************
476cdf0e10cSrcweir class OServiceManager_Listener
477cdf0e10cSrcweir *****************************************************************************/
478cdf0e10cSrcweir class OServiceManager_Listener : public WeakImplHelper1< XEventListener >
479cdf0e10cSrcweir {
480cdf0e10cSrcweir private:
481cdf0e10cSrcweir WeakReference<XSet > xSMgr;
482cdf0e10cSrcweir
483cdf0e10cSrcweir public:
OServiceManager_Listener(const Reference<XSet> & rSMgr)484cdf0e10cSrcweir OServiceManager_Listener( const Reference<XSet > & rSMgr )
485cdf0e10cSrcweir : xSMgr( rSMgr )
486cdf0e10cSrcweir {}
487cdf0e10cSrcweir
488cdf0e10cSrcweir // XEventListener
489cdf0e10cSrcweir virtual void SAL_CALL disposing(const EventObject & rEvt ) throw(::com::sun::star::uno::RuntimeException);
490cdf0e10cSrcweir };
491cdf0e10cSrcweir
disposing(const EventObject & rEvt)492cdf0e10cSrcweir void OServiceManager_Listener::disposing(const EventObject & rEvt )
493cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
494cdf0e10cSrcweir {
495cdf0e10cSrcweir Reference<XSet > x( xSMgr );
496cdf0e10cSrcweir if( x.is() )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir try
499cdf0e10cSrcweir {
500cdf0e10cSrcweir x->remove( Any( &rEvt.Source, ::getCppuType( (const Reference<XInterface > *)0 ) ) );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir catch( const IllegalArgumentException & )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir OSL_ENSURE( sal_False, "IllegalArgumentException catched" );
505cdf0e10cSrcweir }
506cdf0e10cSrcweir catch( const NoSuchElementException & )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir OSL_ENSURE( sal_False, "NoSuchElementException catched" );
509cdf0e10cSrcweir }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir }
512cdf0e10cSrcweir
513cdf0e10cSrcweir
514cdf0e10cSrcweir /*****************************************************************************
515cdf0e10cSrcweir class OServiceManager
516cdf0e10cSrcweir *****************************************************************************/
517cdf0e10cSrcweir struct OServiceManagerMutex
518cdf0e10cSrcweir {
519cdf0e10cSrcweir Mutex m_mutex;
520cdf0e10cSrcweir };
521cdf0e10cSrcweir
522cdf0e10cSrcweir extern "C" void SAL_CALL smgrUnloadingListener(void* id);
523cdf0e10cSrcweir
524cdf0e10cSrcweir typedef WeakComponentImplHelper8<
525cdf0e10cSrcweir lang::XMultiServiceFactory, lang::XMultiComponentFactory, lang::XServiceInfo,
526cdf0e10cSrcweir lang::XInitialization, lang::XUnoTunnel,
527cdf0e10cSrcweir container::XSet, container::XContentEnumerationAccess,
528cdf0e10cSrcweir beans::XPropertySet > t_OServiceManager_impl;
529cdf0e10cSrcweir
530cdf0e10cSrcweir class OServiceManager
531cdf0e10cSrcweir : public OServiceManagerMutex
532cdf0e10cSrcweir , public t_OServiceManager_impl
533cdf0e10cSrcweir {
534cdf0e10cSrcweir public:
535cdf0e10cSrcweir friend void SAL_CALL smgrUnloadingListener(void* id);
536cdf0e10cSrcweir
537cdf0e10cSrcweir OServiceManager( Reference< XComponentContext > const & xContext );
538cdf0e10cSrcweir virtual ~OServiceManager();
539cdf0e10cSrcweir
540cdf0e10cSrcweir // XUnoTunnel
541cdf0e10cSrcweir sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id )
542cdf0e10cSrcweir throw (RuntimeException);
543cdf0e10cSrcweir
544cdf0e10cSrcweir // XInitialization
545cdf0e10cSrcweir void SAL_CALL initialize( Sequence< Any > const & args )
546cdf0e10cSrcweir throw (Exception);
547cdf0e10cSrcweir
548cdf0e10cSrcweir // XServiceInfo
549cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
getImplementationName_Static()550cdf0e10cSrcweir static OUString getImplementationName_Static() throw(::com::sun::star::uno::RuntimeException)
551cdf0e10cSrcweir { return stoc_bootstrap::smgr_getImplementationName(); }
552cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(::com::sun::star::uno::RuntimeException);
553cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
554cdf0e10cSrcweir
555cdf0e10cSrcweir // XMultiComponentFactory
556cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
557cdf0e10cSrcweir OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext )
558cdf0e10cSrcweir throw (Exception, RuntimeException);
559cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
560cdf0e10cSrcweir OUString const & rServiceSpecifier,
561cdf0e10cSrcweir Sequence< Any > const & rArguments,
562cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
563cdf0e10cSrcweir throw (Exception, RuntimeException);
564cdf0e10cSrcweir // virtual Sequence< OUString > SAL_CALL getAvailableServiceNames()
565cdf0e10cSrcweir // throw (RuntimeException);
566cdf0e10cSrcweir
567cdf0e10cSrcweir // XMultiServiceFactory
568cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException);
569cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstance(const OUString &) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
570cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString &, const Sequence<Any >& Arguments) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
571cdf0e10cSrcweir
572cdf0e10cSrcweir // The same as the getAvailableServiceNames, but only uique names
573cdf0e10cSrcweir Sequence< OUString > getUniqueAvailableServiceNames(
574cdf0e10cSrcweir HashSet_OWString & aNameSet );
575cdf0e10cSrcweir
576cdf0e10cSrcweir // XElementAccess
577cdf0e10cSrcweir virtual Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException);
578cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
579cdf0e10cSrcweir
580cdf0e10cSrcweir // XEnumerationAccess
581cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException);
582cdf0e10cSrcweir
583cdf0e10cSrcweir // XSet
584cdf0e10cSrcweir virtual sal_Bool SAL_CALL has( const Any & Element ) throw(::com::sun::star::uno::RuntimeException);
585cdf0e10cSrcweir virtual void SAL_CALL insert( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
586cdf0e10cSrcweir virtual void SAL_CALL remove( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
587cdf0e10cSrcweir
588cdf0e10cSrcweir // XContentEnumerationAccess
589cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) );
590cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException);
591cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(
592cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext )
593cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
594cdf0e10cSrcweir
595cdf0e10cSrcweir // XComponent
596cdf0e10cSrcweir virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
597cdf0e10cSrcweir
598cdf0e10cSrcweir // XPropertySet
599cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo()
600cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
601cdf0e10cSrcweir void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue)
602cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
603cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName)
604cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
605cdf0e10cSrcweir void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
606cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
607cdf0e10cSrcweir void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
608cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
609cdf0e10cSrcweir void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
610cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
611cdf0e10cSrcweir void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
612cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
613cdf0e10cSrcweir
614cdf0e10cSrcweir protected:
615cdf0e10cSrcweir inline bool is_disposed() const SAL_THROW( (lang::DisposedException) );
616cdf0e10cSrcweir inline void check_undisposed() const SAL_THROW( (lang::DisposedException) );
617cdf0e10cSrcweir virtual void SAL_CALL disposing();
618cdf0e10cSrcweir
619cdf0e10cSrcweir sal_Bool haveFactoryWithThisImplementation(const OUString& aImplName);
620cdf0e10cSrcweir
621cdf0e10cSrcweir virtual Sequence< Reference< XInterface > > queryServiceFactories(
622cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext );
623cdf0e10cSrcweir
624cdf0e10cSrcweir Reference< XComponentContext > m_xContext;
625cdf0e10cSrcweir
626cdf0e10cSrcweir Reference< beans::XPropertySetInfo > m_xPropertyInfo;
627cdf0e10cSrcweir
628cdf0e10cSrcweir sal_Int32 m_nUnloadingListenerId;
629cdf0e10cSrcweir
630cdf0e10cSrcweir // Does clean up when the unloading mechanism has been set off. It is called from
631cdf0e10cSrcweir // the listener function smgrUnloadingListener.
632cdf0e10cSrcweir void onUnloadingNotify();
633cdf0e10cSrcweir // factories which have been loaded and not inserted( by XSet::insert)
634cdf0e10cSrcweir // are remembered by this set. Those factories
635cdf0e10cSrcweir // are not released on a call to onUnloadingNotify
636cdf0e10cSrcweir HashSet_Ref m_SetLoadedFactories;
637cdf0e10cSrcweir private:
638cdf0e10cSrcweir
639cdf0e10cSrcweir Reference<XEventListener > getFactoryListener();
640cdf0e10cSrcweir
641cdf0e10cSrcweir
642cdf0e10cSrcweir HashMultimap_OWString_Interface m_ServiceMap;
643cdf0e10cSrcweir HashSet_Ref m_ImplementationMap;
644cdf0e10cSrcweir HashMap_OWString_Interface m_ImplementationNameMap;
645cdf0e10cSrcweir Reference<XEventListener > xFactoryListener;
646cdf0e10cSrcweir bool m_bInDisposing;
647cdf0e10cSrcweir };
648cdf0e10cSrcweir
649cdf0e10cSrcweir
650cdf0e10cSrcweir //______________________________________________________________________________
is_disposed() const651cdf0e10cSrcweir inline bool OServiceManager::is_disposed() const
652cdf0e10cSrcweir SAL_THROW( (lang::DisposedException) )
653cdf0e10cSrcweir {
654cdf0e10cSrcweir // ought to be guarded by m_mutex:
655cdf0e10cSrcweir return (m_bInDisposing || rBHelper.bDisposed);
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
658cdf0e10cSrcweir //______________________________________________________________________________
check_undisposed() const659cdf0e10cSrcweir inline void OServiceManager::check_undisposed() const
660cdf0e10cSrcweir SAL_THROW( (lang::DisposedException) )
661cdf0e10cSrcweir {
662cdf0e10cSrcweir if (is_disposed())
663cdf0e10cSrcweir {
664cdf0e10cSrcweir throw lang::DisposedException(
665cdf0e10cSrcweir OUSTR("service manager instance has already been disposed!"),
666cdf0e10cSrcweir (OWeakObject *)this );
667cdf0e10cSrcweir }
668cdf0e10cSrcweir }
669cdf0e10cSrcweir
670cdf0e10cSrcweir //##################################################################################################
671cdf0e10cSrcweir //##################################################################################################
672cdf0e10cSrcweir //##################################################################################################
673cdf0e10cSrcweir
674cdf0e10cSrcweir class OServiceManagerWrapper : public OServiceManagerMutex, public t_OServiceManager_impl
675cdf0e10cSrcweir {
676cdf0e10cSrcweir Reference< XComponentContext > m_xContext;
677cdf0e10cSrcweir OServiceManager * m_root;
getRoot()678cdf0e10cSrcweir inline OServiceManager * getRoot() SAL_THROW( (RuntimeException) )
679cdf0e10cSrcweir {
680cdf0e10cSrcweir if (! m_root)
681cdf0e10cSrcweir {
682cdf0e10cSrcweir throw lang::DisposedException(
683cdf0e10cSrcweir OUSTR("service manager instance has already been disposed!"),
684cdf0e10cSrcweir Reference< XInterface >() );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir return m_root;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir
689cdf0e10cSrcweir protected:
690cdf0e10cSrcweir virtual void SAL_CALL disposing();
691cdf0e10cSrcweir
692cdf0e10cSrcweir public:
693cdf0e10cSrcweir OServiceManagerWrapper(
694cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
695cdf0e10cSrcweir SAL_THROW( (RuntimeException) );
696cdf0e10cSrcweir virtual ~OServiceManagerWrapper() SAL_THROW( () );
697cdf0e10cSrcweir
698cdf0e10cSrcweir // XUnoTunnel
getSomething(Sequence<sal_Int8> const & id)699cdf0e10cSrcweir sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id ) throw (RuntimeException)
700cdf0e10cSrcweir { return getRoot()->getSomething( id ); }
701cdf0e10cSrcweir
702cdf0e10cSrcweir // XInitialization
initialize(Sequence<Any> const & args)703cdf0e10cSrcweir void SAL_CALL initialize( Sequence< Any > const & args ) throw (Exception)
704cdf0e10cSrcweir { getRoot()->initialize( args ); }
705cdf0e10cSrcweir
706cdf0e10cSrcweir // XServiceInfo
getImplementationName()707cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName() throw (RuntimeException)
708cdf0e10cSrcweir { return getRoot()->getImplementationName(); }
supportsService(const OUString & ServiceName)709cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (RuntimeException)
710cdf0e10cSrcweir { return getRoot()->supportsService( ServiceName ); }
getSupportedServiceNames()711cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException)
712cdf0e10cSrcweir { return getRoot()->getSupportedServiceNames(); }
713cdf0e10cSrcweir
714cdf0e10cSrcweir // XMultiComponentFactory
createInstanceWithContext(OUString const & rServiceSpecifier,Reference<XComponentContext> const & xContext)715cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
716cdf0e10cSrcweir OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext )
717cdf0e10cSrcweir throw (Exception, RuntimeException)
718cdf0e10cSrcweir { return getRoot()->createInstanceWithContext( rServiceSpecifier, xContext ); }
createInstanceWithArgumentsAndContext(OUString const & rServiceSpecifier,Sequence<Any> const & rArguments,Reference<XComponentContext> const & xContext)719cdf0e10cSrcweir virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
720cdf0e10cSrcweir OUString const & rServiceSpecifier,
721cdf0e10cSrcweir Sequence< Any > const & rArguments,
722cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
723cdf0e10cSrcweir throw (Exception, RuntimeException)
724cdf0e10cSrcweir { return getRoot()->createInstanceWithArgumentsAndContext( rServiceSpecifier, rArguments, xContext ); }
725cdf0e10cSrcweir // virtual Sequence< OUString > SAL_CALL getAvailableServiceNames()
726cdf0e10cSrcweir // throw (RuntimeException);
727cdf0e10cSrcweir
728cdf0e10cSrcweir // XMultiServiceFactory
getAvailableServiceNames()729cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException)
730cdf0e10cSrcweir { return getRoot()->getAvailableServiceNames(); }
createInstance(const OUString & name)731cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstance(const OUString & name) throw (Exception)
732cdf0e10cSrcweir { return getRoot()->createInstanceWithContext( name, m_xContext ); }
createInstanceWithArguments(const OUString & name,const Sequence<Any> & Arguments)733cdf0e10cSrcweir virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString & name, const Sequence<Any >& Arguments) throw (Exception)
734cdf0e10cSrcweir { return getRoot()->createInstanceWithArgumentsAndContext( name, Arguments, m_xContext ); }
735cdf0e10cSrcweir
736cdf0e10cSrcweir // XElementAccess
getElementType()737cdf0e10cSrcweir virtual Type SAL_CALL getElementType() throw (RuntimeException)
738cdf0e10cSrcweir { return getRoot()->getElementType(); }
hasElements()739cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements() throw (RuntimeException)
740cdf0e10cSrcweir { return getRoot()->hasElements(); }
741cdf0e10cSrcweir
742cdf0e10cSrcweir // XEnumerationAccess
createEnumeration()743cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw (RuntimeException)
744cdf0e10cSrcweir { return getRoot()->createEnumeration(); }
745cdf0e10cSrcweir
746cdf0e10cSrcweir // XSet
has(const Any & Element)747cdf0e10cSrcweir virtual sal_Bool SAL_CALL has( const Any & Element ) throw (RuntimeException)
748cdf0e10cSrcweir { return getRoot()->has( Element ); }
insert(const Any & Element)749cdf0e10cSrcweir virtual void SAL_CALL insert( const Any & Element ) throw (lang::IllegalArgumentException, container::ElementExistException, RuntimeException)
750cdf0e10cSrcweir { getRoot()->insert( Element ); }
remove(const Any & Element)751cdf0e10cSrcweir virtual void SAL_CALL remove( const Any & Element ) throw (lang::IllegalArgumentException, container::NoSuchElementException, RuntimeException)
752cdf0e10cSrcweir { getRoot()->remove( Element ); }
753cdf0e10cSrcweir
754cdf0e10cSrcweir // XContentEnumerationAccess
755cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) );
createContentEnumeration(const OUString & aServiceName)756cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw (RuntimeException)
757cdf0e10cSrcweir { return getRoot()->createContentEnumeration( aServiceName, m_xContext ); }
758cdf0e10cSrcweir
759cdf0e10cSrcweir // XPropertySet
getPropertySetInfo()760cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException)
761cdf0e10cSrcweir { return getRoot()->getPropertySetInfo(); }
762cdf0e10cSrcweir
763cdf0e10cSrcweir void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue)
764cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException);
765cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName)
766cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException);
767cdf0e10cSrcweir
addPropertyChangeListener(const OUString & PropertyName,const Reference<XPropertyChangeListener> & aListener)768cdf0e10cSrcweir void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
769cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException)
770cdf0e10cSrcweir { getRoot()->addPropertyChangeListener( PropertyName, aListener ); }
removePropertyChangeListener(const OUString & PropertyName,const Reference<XPropertyChangeListener> & aListener)771cdf0e10cSrcweir void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener)
772cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException)
773cdf0e10cSrcweir { getRoot()->removePropertyChangeListener( PropertyName, aListener ); }
addVetoableChangeListener(const OUString & PropertyName,const Reference<XVetoableChangeListener> & aListener)774cdf0e10cSrcweir void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
775cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException)
776cdf0e10cSrcweir { getRoot()->addVetoableChangeListener( PropertyName, aListener ); }
removeVetoableChangeListener(const OUString & PropertyName,const Reference<XVetoableChangeListener> & aListener)777cdf0e10cSrcweir void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener)
778cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException)
779cdf0e10cSrcweir { getRoot()->removeVetoableChangeListener( PropertyName, aListener ); }
780cdf0e10cSrcweir };
781cdf0e10cSrcweir //__________________________________________________________________________________________________
setPropertyValue(const OUString & PropertyName,const Any & aValue)782cdf0e10cSrcweir void SAL_CALL OServiceManagerWrapper::setPropertyValue(
783cdf0e10cSrcweir const OUString& PropertyName, const Any& aValue )
784cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException,
785cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException)
786cdf0e10cSrcweir {
787cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") ))
788cdf0e10cSrcweir {
789cdf0e10cSrcweir Reference< XComponentContext > xContext;
790cdf0e10cSrcweir if (aValue >>= xContext)
791cdf0e10cSrcweir {
792cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
793cdf0e10cSrcweir m_xContext = xContext;
794cdf0e10cSrcweir }
795cdf0e10cSrcweir else
796cdf0e10cSrcweir {
797cdf0e10cSrcweir throw IllegalArgumentException(
798cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ),
799cdf0e10cSrcweir (OWeakObject *)this, 1 );
800cdf0e10cSrcweir }
801cdf0e10cSrcweir }
802cdf0e10cSrcweir else
803cdf0e10cSrcweir {
804cdf0e10cSrcweir getRoot()->setPropertyValue( PropertyName, aValue );
805cdf0e10cSrcweir }
806cdf0e10cSrcweir }
807cdf0e10cSrcweir //__________________________________________________________________________________________________
getPropertyValue(const OUString & PropertyName)808cdf0e10cSrcweir Any SAL_CALL OServiceManagerWrapper::getPropertyValue(
809cdf0e10cSrcweir const OUString& PropertyName )
810cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException)
811cdf0e10cSrcweir {
812cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") ))
813cdf0e10cSrcweir {
814cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
815cdf0e10cSrcweir if( m_xContext.is() )
816cdf0e10cSrcweir return makeAny( m_xContext );
817cdf0e10cSrcweir else
818cdf0e10cSrcweir return Any();
819cdf0e10cSrcweir }
820cdf0e10cSrcweir else
821cdf0e10cSrcweir {
822cdf0e10cSrcweir return getRoot()->getPropertyValue( PropertyName );
823cdf0e10cSrcweir }
824cdf0e10cSrcweir }
825cdf0e10cSrcweir //__________________________________________________________________________________________________
disposing()826cdf0e10cSrcweir void OServiceManagerWrapper::disposing()
827cdf0e10cSrcweir {
828cdf0e10cSrcweir m_xContext.clear();
829cdf0e10cSrcweir
830cdf0e10cSrcweir if (m_root)
831cdf0e10cSrcweir {
832cdf0e10cSrcweir // no m_root->dispose(), because every context disposes its service manager...
833cdf0e10cSrcweir m_root->release();
834cdf0e10cSrcweir m_root = 0;
835cdf0e10cSrcweir }
836cdf0e10cSrcweir }
837cdf0e10cSrcweir //__________________________________________________________________________________________________
~OServiceManagerWrapper()838cdf0e10cSrcweir OServiceManagerWrapper::~OServiceManagerWrapper() SAL_THROW( () )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir if (m_root)
841cdf0e10cSrcweir {
842cdf0e10cSrcweir m_root->release();
843cdf0e10cSrcweir m_root = 0;
844cdf0e10cSrcweir }
845cdf0e10cSrcweir
846cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
847cdf0e10cSrcweir }
848cdf0e10cSrcweir //__________________________________________________________________________________________________
OServiceManagerWrapper(Reference<XComponentContext> const & xContext)849cdf0e10cSrcweir OServiceManagerWrapper::OServiceManagerWrapper(
850cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
851cdf0e10cSrcweir SAL_THROW( (RuntimeException) )
852cdf0e10cSrcweir : t_OServiceManager_impl( m_mutex )
853cdf0e10cSrcweir , m_xContext( xContext )
854cdf0e10cSrcweir , m_root( 0 )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
857cdf0e10cSrcweir
858cdf0e10cSrcweir Reference< XUnoTunnel > xTunnel( m_xContext->getServiceManager(), UNO_QUERY );
859cdf0e10cSrcweir OSL_ASSERT( xTunnel.is() );
860cdf0e10cSrcweir if (xTunnel.is())
861cdf0e10cSrcweir {
862cdf0e10cSrcweir m_root = reinterpret_cast< OServiceManager * >(
863cdf0e10cSrcweir xTunnel->getSomething( smgr_getImplementationId() ) );
864cdf0e10cSrcweir OSL_ASSERT( m_root );
865cdf0e10cSrcweir if (m_root)
866cdf0e10cSrcweir {
867cdf0e10cSrcweir m_root->acquire();
868cdf0e10cSrcweir }
869cdf0e10cSrcweir }
870cdf0e10cSrcweir
871cdf0e10cSrcweir if (! m_root)
872cdf0e10cSrcweir {
873cdf0e10cSrcweir throw RuntimeException(
874cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("can only wrap OServiceManager instances!") ),
875cdf0e10cSrcweir Reference< XInterface >() );
876cdf0e10cSrcweir }
877cdf0e10cSrcweir }
878cdf0e10cSrcweir
879cdf0e10cSrcweir //##################################################################################################
880cdf0e10cSrcweir //##################################################################################################
881cdf0e10cSrcweir //##################################################################################################
882cdf0e10cSrcweir
883cdf0e10cSrcweir // XUnoTunnel
getSomething(Sequence<sal_Int8> const & id)884cdf0e10cSrcweir sal_Int64 OServiceManager::getSomething( Sequence< sal_Int8 > const & id )
885cdf0e10cSrcweir throw (RuntimeException)
886cdf0e10cSrcweir {
887cdf0e10cSrcweir check_undisposed();
888cdf0e10cSrcweir if (id == smgr_getImplementationId())
889cdf0e10cSrcweir return reinterpret_cast< sal_Int64 >(this);
890cdf0e10cSrcweir else
891cdf0e10cSrcweir return 0;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir
894cdf0e10cSrcweir /**
895cdf0e10cSrcweir * Create a ServiceManager
896cdf0e10cSrcweir */
OServiceManager(Reference<XComponentContext> const & xContext)897cdf0e10cSrcweir OServiceManager::OServiceManager( Reference< XComponentContext > const & xContext )
898cdf0e10cSrcweir : t_OServiceManager_impl( m_mutex )
899cdf0e10cSrcweir , m_xContext( xContext )
900cdf0e10cSrcweir , m_bInDisposing( false )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
903cdf0e10cSrcweir m_nUnloadingListenerId= rtl_addUnloadingListener( smgrUnloadingListener, this);
904cdf0e10cSrcweir }
905cdf0e10cSrcweir
906cdf0e10cSrcweir /**
907cdf0e10cSrcweir * Destroy the ServiceManager
908cdf0e10cSrcweir */
~OServiceManager()909cdf0e10cSrcweir OServiceManager::~OServiceManager()
910cdf0e10cSrcweir {
911cdf0e10cSrcweir if( m_nUnloadingListenerId != 0)
912cdf0e10cSrcweir rtl_removeUnloadingListener( m_nUnloadingListenerId );
913cdf0e10cSrcweir
914cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
915cdf0e10cSrcweir }
916cdf0e10cSrcweir
917cdf0e10cSrcweir // Removes entries in m_ServiceMap, m_ImplementationNameMap and m_ImplementationNameMap
918cdf0e10cSrcweir // if those entries have not been inserted through XSet::insert. Therefore the entries
919cdf0e10cSrcweir // are compared with the entries in m_SetLoadedFactories.
onUnloadingNotify()920cdf0e10cSrcweir void OServiceManager::onUnloadingNotify()
921cdf0e10cSrcweir {
922cdf0e10cSrcweir MutexGuard aGuard( m_mutex);
923cdf0e10cSrcweir
924cdf0e10cSrcweir typedef HashSet_Ref::const_iterator CIT_S;
925cdf0e10cSrcweir typedef HashMultimap_OWString_Interface::iterator IT_MM;
926cdf0e10cSrcweir
927cdf0e10cSrcweir CIT_S it_SetEnd= m_SetLoadedFactories.end();
928cdf0e10cSrcweir IT_MM it_end1= m_ServiceMap.end();
929cdf0e10cSrcweir list<IT_MM> listDeleteServiceMap;
930cdf0e10cSrcweir typedef list<IT_MM>::const_iterator CIT_DMM;
931cdf0e10cSrcweir // find occurences in m_ServiceMap
932cdf0e10cSrcweir for(IT_MM it_i1= m_ServiceMap.begin(); it_i1 != it_end1; it_i1++)
933cdf0e10cSrcweir {
934cdf0e10cSrcweir if( m_SetLoadedFactories.find( it_i1->second) != it_SetEnd)
935cdf0e10cSrcweir {
936cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( it_i1->second, UNO_QUERY);
937cdf0e10cSrcweir if( xunl.is())
938cdf0e10cSrcweir {
939cdf0e10cSrcweir if( xunl->releaseOnNotification())
940cdf0e10cSrcweir listDeleteServiceMap.push_front( it_i1);
941cdf0e10cSrcweir }
942cdf0e10cSrcweir else
943cdf0e10cSrcweir listDeleteServiceMap.push_front( it_i1);
944cdf0e10cSrcweir }
945cdf0e10cSrcweir }
946cdf0e10cSrcweir // delete elements from m_ServiceMap
947cdf0e10cSrcweir CIT_DMM it_end2= listDeleteServiceMap.end();
948cdf0e10cSrcweir for( CIT_DMM it_i2= listDeleteServiceMap.begin(); it_i2 != it_end2; it_i2++)
949cdf0e10cSrcweir m_ServiceMap.erase( *it_i2);
950cdf0e10cSrcweir
951cdf0e10cSrcweir // find elements in m_ImplementationNameMap
952cdf0e10cSrcweir typedef HashMap_OWString_Interface::iterator IT_M;
953cdf0e10cSrcweir IT_M it_end3= m_ImplementationNameMap.end();
954cdf0e10cSrcweir list<IT_M> listDeleteImplementationNameMap;
955cdf0e10cSrcweir typedef list<IT_M>::const_iterator CIT_DM;
956cdf0e10cSrcweir for( IT_M it_i3= m_ImplementationNameMap.begin(); it_i3 != it_end3; it_i3++)
957cdf0e10cSrcweir {
958cdf0e10cSrcweir if( m_SetLoadedFactories.find( it_i3->second) != it_SetEnd)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( it_i3->second, UNO_QUERY);
961cdf0e10cSrcweir if( xunl.is())
962cdf0e10cSrcweir {
963cdf0e10cSrcweir if( xunl->releaseOnNotification())
964cdf0e10cSrcweir listDeleteImplementationNameMap.push_front( it_i3);
965cdf0e10cSrcweir }
966cdf0e10cSrcweir else
967cdf0e10cSrcweir listDeleteImplementationNameMap.push_front( it_i3);
968cdf0e10cSrcweir }
969cdf0e10cSrcweir }
970cdf0e10cSrcweir // delete elements from m_ImplementationNameMap
971cdf0e10cSrcweir CIT_DM it_end4= listDeleteImplementationNameMap.end();
972cdf0e10cSrcweir for( CIT_DM it_i4= listDeleteImplementationNameMap.begin(); it_i4 != it_end4; it_i4++)
973cdf0e10cSrcweir m_ImplementationNameMap.erase( *it_i4);
974cdf0e10cSrcweir
975cdf0e10cSrcweir // find elements in m_ImplementationMap
976cdf0e10cSrcweir typedef HashSet_Ref::iterator IT_S;
977cdf0e10cSrcweir IT_S it_end5= m_ImplementationMap.end();
978cdf0e10cSrcweir list<IT_S> listDeleteImplementationMap;
979cdf0e10cSrcweir typedef list<IT_S>::const_iterator CIT_DS;
980cdf0e10cSrcweir for( IT_S it_i5= m_ImplementationMap.begin(); it_i5 != it_end5; it_i5++)
981cdf0e10cSrcweir {
982cdf0e10cSrcweir if( m_SetLoadedFactories.find( *it_i5) != it_SetEnd)
983cdf0e10cSrcweir {
984cdf0e10cSrcweir Reference<XUnloadingPreference> xunl( *it_i5, UNO_QUERY);
985cdf0e10cSrcweir if( xunl.is())
986cdf0e10cSrcweir {
987cdf0e10cSrcweir if( xunl->releaseOnNotification())
988cdf0e10cSrcweir listDeleteImplementationMap.push_front( it_i5);
989cdf0e10cSrcweir }
990cdf0e10cSrcweir else
991cdf0e10cSrcweir listDeleteImplementationMap.push_front( it_i5);
992cdf0e10cSrcweir }
993cdf0e10cSrcweir }
994cdf0e10cSrcweir // delete elements from m_ImplementationMap
995cdf0e10cSrcweir CIT_DS it_end6= listDeleteImplementationMap.end();
996cdf0e10cSrcweir for( CIT_DS it_i6= listDeleteImplementationMap.begin(); it_i6 != it_end6; it_i6++)
997cdf0e10cSrcweir m_ImplementationMap.erase( *it_i6);
998cdf0e10cSrcweir
999cdf0e10cSrcweir // remove Event listener before the factories are released.
1000cdf0e10cSrcweir IT_S it_end7= m_SetLoadedFactories.end();
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir Reference<XEventListener> xlistener= getFactoryListener();
1003cdf0e10cSrcweir for( IT_S it_i7= m_SetLoadedFactories.begin(); it_i7 != it_end7; it_i7++)
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir Reference<XComponent> xcomp( *it_i7, UNO_QUERY);
1006cdf0e10cSrcweir if( xcomp.is())
1007cdf0e10cSrcweir xcomp->removeEventListener( xlistener);
1008cdf0e10cSrcweir }
1009cdf0e10cSrcweir // release the factories in m_SetLoadedFactories
1010cdf0e10cSrcweir m_SetLoadedFactories.clear();
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir // XComponent
dispose()1014cdf0e10cSrcweir void OServiceManager::dispose()
1015cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
1018cdf0e10cSrcweir return;
1019cdf0e10cSrcweir t_OServiceManager_impl::dispose();
1020cdf0e10cSrcweir }
1021cdf0e10cSrcweir
disposing()1022cdf0e10cSrcweir void OServiceManager::disposing()
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir // dispose all factories
1025cdf0e10cSrcweir HashSet_Ref aImpls;
1026cdf0e10cSrcweir {
1027cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1028cdf0e10cSrcweir m_bInDisposing = true;
1029cdf0e10cSrcweir aImpls = m_ImplementationMap;
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir HashSet_Ref::iterator aIt = aImpls.begin();
1032cdf0e10cSrcweir while( aIt != aImpls.end() )
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir try
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( *aIt++ ) );
1037cdf0e10cSrcweir if( xComp.is() )
1038cdf0e10cSrcweir xComp->dispose();
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir catch (RuntimeException & exc)
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1043cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1044cdf0e10cSrcweir OSL_TRACE( "### RuntimeException occured upon disposing factory: %s", str.getStr() );
1045cdf0e10cSrcweir #else
1046cdf0e10cSrcweir (void) exc; // unused
1047cdf0e10cSrcweir #endif
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir
1051cdf0e10cSrcweir // dispose
1052cdf0e10cSrcweir HashSet_Ref aImplMap;
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1055cdf0e10cSrcweir // erase all members
1056cdf0e10cSrcweir m_ServiceMap = HashMultimap_OWString_Interface();
1057cdf0e10cSrcweir aImplMap = m_ImplementationMap;
1058cdf0e10cSrcweir m_ImplementationMap = HashSet_Ref();
1059cdf0e10cSrcweir m_ImplementationNameMap = HashMap_OWString_Interface();
1060cdf0e10cSrcweir m_SetLoadedFactories= HashSet_Ref();
1061cdf0e10cSrcweir }
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir m_xContext.clear();
1064cdf0e10cSrcweir
1065cdf0e10cSrcweir // not only the Event should hold the object
1066cdf0e10cSrcweir OSL_ASSERT( m_refCount != 1 );
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir // Revoke this service manager as unloading listener
1069cdf0e10cSrcweir rtl_removeUnloadingListener( m_nUnloadingListenerId);
1070cdf0e10cSrcweir m_nUnloadingListenerId=0;
1071cdf0e10cSrcweir }
1072cdf0e10cSrcweir
1073cdf0e10cSrcweir // XPropertySet
getPropertySetInfo()1074cdf0e10cSrcweir Reference<XPropertySetInfo > OServiceManager::getPropertySetInfo()
1075cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir check_undisposed();
1078cdf0e10cSrcweir if (! m_xPropertyInfo.is())
1079cdf0e10cSrcweir {
1080cdf0e10cSrcweir Sequence< beans::Property > seq( 1 );
1081cdf0e10cSrcweir seq[ 0 ] = beans::Property(
1082cdf0e10cSrcweir OUSTR("DefaultContext"), -1, ::getCppuType( &m_xContext ), 0 );
1083cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) );
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1086cdf0e10cSrcweir if (! m_xPropertyInfo.is())
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir m_xPropertyInfo = xInfo;
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir return m_xPropertyInfo;
1092cdf0e10cSrcweir }
1093cdf0e10cSrcweir
setPropertyValue(const OUString & PropertyName,const Any & aValue)1094cdf0e10cSrcweir void OServiceManager::setPropertyValue(
1095cdf0e10cSrcweir const OUString& PropertyName, const Any& aValue )
1096cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1097cdf0e10cSrcweir {
1098cdf0e10cSrcweir check_undisposed();
1099cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") ))
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir Reference< XComponentContext > xContext;
1102cdf0e10cSrcweir if (aValue >>= xContext)
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1105cdf0e10cSrcweir m_xContext = xContext;
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir else
1108cdf0e10cSrcweir {
1109cdf0e10cSrcweir throw IllegalArgumentException(
1110cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ),
1111cdf0e10cSrcweir (OWeakObject *)this, 1 );
1112cdf0e10cSrcweir }
1113cdf0e10cSrcweir }
1114cdf0e10cSrcweir else
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir throw UnknownPropertyException(
1117cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property ") ) + PropertyName,
1118cdf0e10cSrcweir (OWeakObject *)this );
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir
getPropertyValue(const OUString & PropertyName)1122cdf0e10cSrcweir Any OServiceManager::getPropertyValue(const OUString& PropertyName)
1123cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir check_undisposed();
1126cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") ))
1127cdf0e10cSrcweir {
1128cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1129cdf0e10cSrcweir if( m_xContext.is() )
1130cdf0e10cSrcweir return makeAny( m_xContext );
1131cdf0e10cSrcweir else
1132cdf0e10cSrcweir return Any();
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir else
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir UnknownPropertyException except;
1137cdf0e10cSrcweir except.Message = OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager : unknown property " ) );
1138cdf0e10cSrcweir except.Message += PropertyName;
1139cdf0e10cSrcweir throw except;
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir }
1142cdf0e10cSrcweir
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)1143cdf0e10cSrcweir void OServiceManager::addPropertyChangeListener(
1144cdf0e10cSrcweir const OUString&, const Reference<XPropertyChangeListener >&)
1145cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir check_undisposed();
1148cdf0e10cSrcweir throw UnknownPropertyException();
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)1151cdf0e10cSrcweir void OServiceManager::removePropertyChangeListener(
1152cdf0e10cSrcweir const OUString&, const Reference<XPropertyChangeListener >&)
1153cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1154cdf0e10cSrcweir {
1155cdf0e10cSrcweir check_undisposed();
1156cdf0e10cSrcweir throw UnknownPropertyException();
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1159cdf0e10cSrcweir void OServiceManager::addVetoableChangeListener(
1160cdf0e10cSrcweir const OUString&, const Reference<XVetoableChangeListener >&)
1161cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir check_undisposed();
1164cdf0e10cSrcweir throw UnknownPropertyException();
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)1167cdf0e10cSrcweir void OServiceManager::removeVetoableChangeListener(
1168cdf0e10cSrcweir const OUString&, const Reference<XVetoableChangeListener >&)
1169cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir check_undisposed();
1172cdf0e10cSrcweir throw UnknownPropertyException();
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir
1175cdf0e10cSrcweir // OServiceManager
getFactoryListener()1176cdf0e10cSrcweir Reference<XEventListener > OServiceManager::getFactoryListener()
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir check_undisposed();
1179cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1180cdf0e10cSrcweir if( !xFactoryListener.is() )
1181cdf0e10cSrcweir xFactoryListener = new OServiceManager_Listener( this );
1182cdf0e10cSrcweir return xFactoryListener;
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir
1185cdf0e10cSrcweir // XMultiServiceFactory, XContentEnumeration
getUniqueAvailableServiceNames(HashSet_OWString & aNameSet)1186cdf0e10cSrcweir Sequence< OUString > OServiceManager::getUniqueAvailableServiceNames(
1187cdf0e10cSrcweir HashSet_OWString & aNameSet )
1188cdf0e10cSrcweir {
1189cdf0e10cSrcweir check_undisposed();
1190cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1191cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator aSIt = m_ServiceMap.begin();
1192cdf0e10cSrcweir while( aSIt != m_ServiceMap.end() )
1193cdf0e10cSrcweir aNameSet.insert( (*aSIt++).first );
1194cdf0e10cSrcweir
1195cdf0e10cSrcweir /* do not return the implementation names
1196cdf0e10cSrcweir HashMap_OWString_Interface m_ImplementationNameMap;
1197cdf0e10cSrcweir HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.begin();
1198cdf0e10cSrcweir while( aIt != m_ImplementationNameMap.end() )
1199cdf0e10cSrcweir aNameSet.insert( (*aIt++).first );
1200cdf0e10cSrcweir */
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir Sequence< OUString > aNames( aNameSet.size() );
1203cdf0e10cSrcweir OUString * pArray = aNames.getArray();
1204cdf0e10cSrcweir sal_Int32 i = 0;
1205cdf0e10cSrcweir HashSet_OWString::iterator next = aNameSet.begin();
1206cdf0e10cSrcweir while( next != aNameSet.end() )
1207cdf0e10cSrcweir pArray[i++] = (*next++);
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir return aNames;
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir // XMultiComponentFactory
createInstanceWithContext(OUString const & rServiceSpecifier,Reference<XComponentContext> const & xContext)1213cdf0e10cSrcweir Reference< XInterface > OServiceManager::createInstanceWithContext(
1214cdf0e10cSrcweir OUString const & rServiceSpecifier,
1215cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
1216cdf0e10cSrcweir throw (Exception, RuntimeException)
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir check_undisposed();
1219cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1220cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY );
1221cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
1222cdf0e10cSrcweir if (xProps.is())
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir Reference< XComponentContext > xDefContext;
1225cdf0e10cSrcweir xProps->getPropertyValue(
1226cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext;
1227cdf0e10cSrcweir OSL_ENSURE(
1228cdf0e10cSrcweir xContext == xDefContext,
1229cdf0e10cSrcweir "### default context of service manager singleton differs from context holding it!" );
1230cdf0e10cSrcweir }
1231cdf0e10cSrcweir #endif
1232cdf0e10cSrcweir
1233cdf0e10cSrcweir Sequence< Reference< XInterface > > factories(
1234cdf0e10cSrcweir queryServiceFactories( rServiceSpecifier, xContext ) );
1235cdf0e10cSrcweir Reference< XInterface > const * p = factories.getConstArray();
1236cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir try
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir Reference< XInterface > const & xFactory = p[ nPos ];
1241cdf0e10cSrcweir if (xFactory.is())
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
1244cdf0e10cSrcweir if (xFac.is())
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir return xFac->createInstanceWithContext( xContext );
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir else
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
1251cdf0e10cSrcweir if (xFac2.is())
1252cdf0e10cSrcweir {
1253cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1254cdf0e10cSrcweir OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) );
1255cdf0e10cSrcweir OSL_TRACE( "### ignoring given context raising service %s !!!\n", aStr.getStr() );
1256cdf0e10cSrcweir #endif
1257cdf0e10cSrcweir return xFac2->createInstance();
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir catch (lang::DisposedException & exc)
1263cdf0e10cSrcweir {
1264cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1265cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1266cdf0e10cSrcweir OSL_TRACE( "### DisposedException occured: %s", str.getStr() );
1267cdf0e10cSrcweir #else
1268cdf0e10cSrcweir (void) exc; // unused
1269cdf0e10cSrcweir #endif
1270cdf0e10cSrcweir }
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir
1273cdf0e10cSrcweir return Reference< XInterface >();
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir // XMultiComponentFactory
createInstanceWithArgumentsAndContext(OUString const & rServiceSpecifier,Sequence<Any> const & rArguments,Reference<XComponentContext> const & xContext)1276cdf0e10cSrcweir Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext(
1277cdf0e10cSrcweir OUString const & rServiceSpecifier,
1278cdf0e10cSrcweir Sequence< Any > const & rArguments,
1279cdf0e10cSrcweir Reference< XComponentContext > const & xContext )
1280cdf0e10cSrcweir throw (Exception, RuntimeException)
1281cdf0e10cSrcweir {
1282cdf0e10cSrcweir check_undisposed();
1283cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1284cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY );
1285cdf0e10cSrcweir OSL_ASSERT( xProps.is() );
1286cdf0e10cSrcweir if (xProps.is())
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir Reference< XComponentContext > xDefContext;
1289cdf0e10cSrcweir xProps->getPropertyValue(
1290cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext;
1291cdf0e10cSrcweir OSL_ENSURE(
1292cdf0e10cSrcweir xContext == xDefContext,
1293cdf0e10cSrcweir "### default context of service manager singleton differs from context holding it!" );
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir #endif
1296cdf0e10cSrcweir
1297cdf0e10cSrcweir Sequence< Reference< XInterface > > factories(
1298cdf0e10cSrcweir queryServiceFactories( rServiceSpecifier, xContext ) );
1299cdf0e10cSrcweir Reference< XInterface > const * p = factories.getConstArray();
1300cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir try
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir Reference< XInterface > const & xFactory = p[ nPos ];
1305cdf0e10cSrcweir if (xFactory.is())
1306cdf0e10cSrcweir {
1307cdf0e10cSrcweir Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
1308cdf0e10cSrcweir if (xFac.is())
1309cdf0e10cSrcweir {
1310cdf0e10cSrcweir return xFac->createInstanceWithArgumentsAndContext( rArguments, xContext );
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir else
1313cdf0e10cSrcweir {
1314cdf0e10cSrcweir Reference< XSingleServiceFactory > xFac2( xFactory, UNO_QUERY );
1315cdf0e10cSrcweir if (xFac2.is())
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1318cdf0e10cSrcweir OString aStr( OUStringToOString( rServiceSpecifier, RTL_TEXTENCODING_ASCII_US ) );
1319cdf0e10cSrcweir OSL_TRACE( "### ignoring given context raising service %s !!!\n", aStr.getStr() );
1320cdf0e10cSrcweir #endif
1321cdf0e10cSrcweir return xFac2->createInstanceWithArguments( rArguments );
1322cdf0e10cSrcweir }
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir }
1325cdf0e10cSrcweir }
1326cdf0e10cSrcweir catch (lang::DisposedException & exc)
1327cdf0e10cSrcweir {
1328cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1329cdf0e10cSrcweir OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1330cdf0e10cSrcweir OSL_TRACE( "### DisposedException occured: %s", str.getStr() );
1331cdf0e10cSrcweir #else
1332cdf0e10cSrcweir (void) exc; // unused
1333cdf0e10cSrcweir #endif
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir
1337cdf0e10cSrcweir return Reference< XInterface >();
1338cdf0e10cSrcweir }
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir // XMultiServiceFactory, XMultiComponentFactory, XContentEnumeration
getAvailableServiceNames()1341cdf0e10cSrcweir Sequence< OUString > OServiceManager::getAvailableServiceNames()
1342cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1343cdf0e10cSrcweir {
1344cdf0e10cSrcweir check_undisposed();
1345cdf0e10cSrcweir // all names
1346cdf0e10cSrcweir HashSet_OWString aNameSet;
1347cdf0e10cSrcweir return getUniqueAvailableServiceNames( aNameSet );
1348cdf0e10cSrcweir }
1349cdf0e10cSrcweir
1350cdf0e10cSrcweir // XMultibleServiceFactory
createInstance(const OUString & rServiceSpecifier)1351cdf0e10cSrcweir Reference<XInterface > OServiceManager::createInstance(
1352cdf0e10cSrcweir const OUString& rServiceSpecifier )
1353cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1354cdf0e10cSrcweir {
1355cdf0e10cSrcweir return createInstanceWithContext(
1356cdf0e10cSrcweir rServiceSpecifier, m_xContext );
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir // XMultibleServiceFactory
createInstanceWithArguments(const OUString & rServiceSpecifier,const Sequence<Any> & rArguments)1360cdf0e10cSrcweir Reference<XInterface > OServiceManager::createInstanceWithArguments(
1361cdf0e10cSrcweir const OUString& rServiceSpecifier,
1362cdf0e10cSrcweir const Sequence<Any >& rArguments )
1363cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir return createInstanceWithArgumentsAndContext(
1366cdf0e10cSrcweir rServiceSpecifier, rArguments, m_xContext );
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir
1369cdf0e10cSrcweir // XInitialization
initialize(Sequence<Any> const &)1370cdf0e10cSrcweir void OServiceManager::initialize( Sequence< Any > const & )
1371cdf0e10cSrcweir throw (Exception)
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir check_undisposed();
1374cdf0e10cSrcweir OSL_ENSURE( 0, "not impl!" );
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir
1377cdf0e10cSrcweir // XServiceInfo
getImplementationName()1378cdf0e10cSrcweir OUString OServiceManager::getImplementationName()
1379cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir check_undisposed();
1382cdf0e10cSrcweir return getImplementationName_Static();
1383cdf0e10cSrcweir }
1384cdf0e10cSrcweir
1385cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)1386cdf0e10cSrcweir sal_Bool OServiceManager::supportsService(const OUString& ServiceName)
1387cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir check_undisposed();
1390cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames();
1391cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray();
1392cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1393cdf0e10cSrcweir if( pArray[i] == ServiceName )
1394cdf0e10cSrcweir return sal_True;
1395cdf0e10cSrcweir return sal_False;
1396cdf0e10cSrcweir }
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames()1399cdf0e10cSrcweir Sequence< OUString > OServiceManager::getSupportedServiceNames()
1400cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir check_undisposed();
1403cdf0e10cSrcweir return stoc_bootstrap::smgr_getSupportedServiceNames();
1404cdf0e10cSrcweir }
1405cdf0e10cSrcweir
1406cdf0e10cSrcweir
queryServiceFactories(const OUString & aServiceName,Reference<XComponentContext> const &)1407cdf0e10cSrcweir Sequence< Reference< XInterface > > OServiceManager::queryServiceFactories(
1408cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & )
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir Sequence< Reference< XInterface > > ret;
1411cdf0e10cSrcweir
1412cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1413cdf0e10cSrcweir ::std::pair<
1414cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator,
1415cdf0e10cSrcweir HashMultimap_OWString_Interface::iterator> p(
1416cdf0e10cSrcweir m_ServiceMap.equal_range( aServiceName ) );
1417cdf0e10cSrcweir
1418cdf0e10cSrcweir if (p.first == p.second) // no factories
1419cdf0e10cSrcweir {
1420cdf0e10cSrcweir // no service found, look for an implementation
1421cdf0e10cSrcweir HashMap_OWString_Interface::iterator aIt = m_ImplementationNameMap.find( aServiceName );
1422cdf0e10cSrcweir if( aIt != m_ImplementationNameMap.end() )
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir Reference< XInterface > const & x = aIt->second;
1425cdf0e10cSrcweir // an implementation found
1426cdf0e10cSrcweir ret = Sequence< Reference< XInterface > >( &x, 1 );
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir else
1430cdf0e10cSrcweir {
1431cdf0e10cSrcweir ::std::vector< Reference< XInterface > > vec;
1432cdf0e10cSrcweir vec.reserve( 4 );
1433cdf0e10cSrcweir while (p.first != p.second)
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir vec.push_back( p.first->second );
1436cdf0e10cSrcweir ++p.first;
1437cdf0e10cSrcweir }
1438cdf0e10cSrcweir ret = Sequence< Reference< XInterface > >(
1439cdf0e10cSrcweir vec.empty() ? 0 : &vec[ 0 ], vec.size() );
1440cdf0e10cSrcweir }
1441cdf0e10cSrcweir
1442cdf0e10cSrcweir return ret;
1443cdf0e10cSrcweir }
1444cdf0e10cSrcweir
1445cdf0e10cSrcweir // XContentEnumerationAccess
createContentEnumeration(const OUString & aServiceName,Reference<XComponentContext> const & xContext)1446cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createContentEnumeration(
1447cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext )
1448cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1449cdf0e10cSrcweir {
1450cdf0e10cSrcweir check_undisposed();
1451cdf0e10cSrcweir Sequence< Reference< XInterface > > factories(
1452cdf0e10cSrcweir OServiceManager::queryServiceFactories( aServiceName, xContext ) );
1453cdf0e10cSrcweir if (factories.getLength())
1454cdf0e10cSrcweir return new ServiceEnumeration_Impl( factories );
1455cdf0e10cSrcweir else
1456cdf0e10cSrcweir return Reference< XEnumeration >();
1457cdf0e10cSrcweir }
createContentEnumeration(const OUString & aServiceName)1458cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createContentEnumeration(
1459cdf0e10cSrcweir const OUString& aServiceName )
1460cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1461cdf0e10cSrcweir {
1462cdf0e10cSrcweir return createContentEnumeration( aServiceName, m_xContext );
1463cdf0e10cSrcweir }
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir // XEnumeration
createEnumeration()1466cdf0e10cSrcweir Reference<XEnumeration > OServiceManager::createEnumeration() throw(::com::sun::star::uno::RuntimeException)
1467cdf0e10cSrcweir {
1468cdf0e10cSrcweir check_undisposed();
1469cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1470cdf0e10cSrcweir return new ImplementationEnumeration_Impl( m_ImplementationMap );
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir // XElementAccess
getElementType()1474cdf0e10cSrcweir Type OServiceManager::getElementType()
1475cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir check_undisposed();
1478cdf0e10cSrcweir return ::getCppuType( (const Reference< XInterface > *)0 );
1479cdf0e10cSrcweir }
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir // XElementAccess
hasElements()1482cdf0e10cSrcweir sal_Bool OServiceManager::hasElements()
1483cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir check_undisposed();
1486cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1487cdf0e10cSrcweir return !m_ImplementationMap.empty();
1488cdf0e10cSrcweir }
1489cdf0e10cSrcweir
1490cdf0e10cSrcweir // XSet
has(const Any & Element)1491cdf0e10cSrcweir sal_Bool OServiceManager::has( const Any & Element )
1492cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1493cdf0e10cSrcweir {
1494cdf0e10cSrcweir check_undisposed();
1495cdf0e10cSrcweir if( Element.getValueTypeClass() == TypeClass_INTERFACE )
1496cdf0e10cSrcweir {
1497cdf0e10cSrcweir Reference<XInterface > xEle( Element, UNO_QUERY_THROW );
1498cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1499cdf0e10cSrcweir return m_ImplementationMap.find( xEle ) !=
1500cdf0e10cSrcweir m_ImplementationMap.end();
1501cdf0e10cSrcweir }
1502cdf0e10cSrcweir else if (Element.getValueTypeClass() == TypeClass_STRING)
1503cdf0e10cSrcweir {
1504cdf0e10cSrcweir OUString const & implName =
1505cdf0e10cSrcweir *reinterpret_cast< OUString const * >(Element.getValue());
1506cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1507cdf0e10cSrcweir return m_ImplementationNameMap.find( implName ) !=
1508cdf0e10cSrcweir m_ImplementationNameMap.end();
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir return sal_False;
1511cdf0e10cSrcweir }
1512cdf0e10cSrcweir
1513cdf0e10cSrcweir // XSet
insert(const Any & Element)1514cdf0e10cSrcweir void OServiceManager::insert( const Any & Element )
1515cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException)
1516cdf0e10cSrcweir {
1517cdf0e10cSrcweir check_undisposed();
1518cdf0e10cSrcweir if( Element.getValueTypeClass() != TypeClass_INTERFACE )
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir throw IllegalArgumentException(
1521cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("no interface given!") ),
1522cdf0e10cSrcweir Reference< XInterface >(), 0 );
1523cdf0e10cSrcweir }
1524cdf0e10cSrcweir Reference<XInterface > xEle( Element, UNO_QUERY_THROW );
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir {
1527cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1528cdf0e10cSrcweir HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );
1529cdf0e10cSrcweir if( aIt != m_ImplementationMap.end() )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir throw ElementExistException(
1532cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element already exists!") ),
1533cdf0e10cSrcweir Reference< XInterface >() );
1534cdf0e10cSrcweir }
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir // put into the implementation hashmap
1537cdf0e10cSrcweir m_ImplementationMap.insert( xEle );
1538cdf0e10cSrcweir
1539cdf0e10cSrcweir // put into the implementation name hashmap
1540cdf0e10cSrcweir Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) );
1541cdf0e10cSrcweir if( xInfo.is() )
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir OUString aImplName = xInfo->getImplementationName();
1544cdf0e10cSrcweir if( aImplName.getLength() )
1545cdf0e10cSrcweir m_ImplementationNameMap[ aImplName ] = xEle;
1546cdf0e10cSrcweir
1547cdf0e10cSrcweir //put into the service map
1548cdf0e10cSrcweir Sequence< OUString > aServiceNames = xInfo->getSupportedServiceNames();
1549cdf0e10cSrcweir const OUString * pArray = aServiceNames.getConstArray();
1550cdf0e10cSrcweir for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
1551cdf0e10cSrcweir {
1552cdf0e10cSrcweir m_ServiceMap.insert( HashMultimap_OWString_Interface::value_type(
1553cdf0e10cSrcweir pArray[i], *(Reference<XInterface > *)Element.getValue() ) );
1554cdf0e10cSrcweir }
1555cdf0e10cSrcweir }
1556cdf0e10cSrcweir }
1557cdf0e10cSrcweir // add the disposing listener to the factory
1558cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) );
1559cdf0e10cSrcweir if( xComp.is() )
1560cdf0e10cSrcweir xComp->addEventListener( getFactoryListener() );
1561cdf0e10cSrcweir }
1562cdf0e10cSrcweir
1563cdf0e10cSrcweir // helper function
haveFactoryWithThisImplementation(const OUString & aImplName)1564cdf0e10cSrcweir sal_Bool OServiceManager::haveFactoryWithThisImplementation(const OUString& aImplName)
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir return ( m_ImplementationNameMap.find(aImplName) != m_ImplementationNameMap.end());
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir
1569cdf0e10cSrcweir // XSet
remove(const Any & Element)1570cdf0e10cSrcweir void OServiceManager::remove( const Any & Element )
1571cdf0e10cSrcweir throw(::com::sun::star::lang::IllegalArgumentException,
1572cdf0e10cSrcweir ::com::sun::star::container::NoSuchElementException,
1573cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException)
1574cdf0e10cSrcweir {
1575cdf0e10cSrcweir if (is_disposed())
1576cdf0e10cSrcweir return;
1577cdf0e10cSrcweir
1578cdf0e10cSrcweir Reference<XInterface > xEle;
1579cdf0e10cSrcweir if (Element.getValueTypeClass() == TypeClass_INTERFACE)
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir xEle.set( Element, UNO_QUERY_THROW );
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir else if (Element.getValueTypeClass() == TypeClass_STRING)
1584cdf0e10cSrcweir {
1585cdf0e10cSrcweir OUString const & implName =
1586cdf0e10cSrcweir *reinterpret_cast< OUString const * >(Element.getValue());
1587cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1588cdf0e10cSrcweir HashMap_OWString_Interface::const_iterator const iFind(
1589cdf0e10cSrcweir m_ImplementationNameMap.find( implName ) );
1590cdf0e10cSrcweir if (iFind == m_ImplementationNameMap.end())
1591cdf0e10cSrcweir {
1592cdf0e10cSrcweir throw NoSuchElementException(
1593cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element is not in: ") )
1594cdf0e10cSrcweir + implName, static_cast< OWeakObject * >(this) );
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir xEle = iFind->second;
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir else
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir throw IllegalArgumentException(
1601cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
1602cdf0e10cSrcweir "neither interface nor string given!") ),
1603cdf0e10cSrcweir Reference< XInterface >(), 0 );
1604cdf0e10cSrcweir }
1605cdf0e10cSrcweir
1606cdf0e10cSrcweir // remove the disposing listener from the factory
1607cdf0e10cSrcweir Reference<XComponent > xComp( Reference<XComponent >::query( xEle ) );
1608cdf0e10cSrcweir if( xComp.is() )
1609cdf0e10cSrcweir xComp->removeEventListener( getFactoryListener() );
1610cdf0e10cSrcweir
1611cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1612cdf0e10cSrcweir HashSet_Ref::iterator aIt = m_ImplementationMap.find( xEle );
1613cdf0e10cSrcweir if( aIt == m_ImplementationMap.end() )
1614cdf0e10cSrcweir {
1615cdf0e10cSrcweir throw NoSuchElementException(
1616cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("element is not in!") ),
1617cdf0e10cSrcweir static_cast< OWeakObject * >(this) );
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir //First remove all factories which have been loaded by ORegistryServiceManager.
1620cdf0e10cSrcweir m_SetLoadedFactories.erase( *aIt);
1621cdf0e10cSrcweir //Remove from the implementation map. It contains all factories of m_SetLoadedFactories
1622cdf0e10cSrcweir //which have been added directly through XSet, that is not via ORegistryServiceManager
1623cdf0e10cSrcweir m_ImplementationMap.erase( aIt );
1624cdf0e10cSrcweir
1625cdf0e10cSrcweir // remove from the implementation name hashmap
1626cdf0e10cSrcweir Reference<XServiceInfo > xInfo( Reference<XServiceInfo >::query( xEle ) );
1627cdf0e10cSrcweir if( xInfo.is() )
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir OUString aImplName = xInfo->getImplementationName();
1630cdf0e10cSrcweir if( aImplName.getLength() )
1631cdf0e10cSrcweir m_ImplementationNameMap.erase( aImplName );
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir
1634cdf0e10cSrcweir //remove from the service map
1635cdf0e10cSrcweir Reference<XServiceInfo > xSF( Reference<XServiceInfo >::query( xEle ) );
1636cdf0e10cSrcweir if( xSF.is() )
1637cdf0e10cSrcweir {
1638cdf0e10cSrcweir Sequence< OUString > aServiceNames = xSF->getSupportedServiceNames();
1639cdf0e10cSrcweir const OUString * pArray = aServiceNames.getConstArray();
1640cdf0e10cSrcweir for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
1641cdf0e10cSrcweir {
1642cdf0e10cSrcweir pair<HashMultimap_OWString_Interface::iterator, HashMultimap_OWString_Interface::iterator> p =
1643cdf0e10cSrcweir m_ServiceMap.equal_range( pArray[i] );
1644cdf0e10cSrcweir
1645cdf0e10cSrcweir while( p.first != p.second )
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir if( xEle == (*p.first).second )
1648cdf0e10cSrcweir {
1649cdf0e10cSrcweir m_ServiceMap.erase( p.first );
1650cdf0e10cSrcweir break;
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir ++p.first;
1653cdf0e10cSrcweir }
1654cdf0e10cSrcweir }
1655cdf0e10cSrcweir }
1656cdf0e10cSrcweir }
1657cdf0e10cSrcweir
1658cdf0e10cSrcweir /*****************************************************************************
1659cdf0e10cSrcweir class ORegistryServiceManager
1660cdf0e10cSrcweir *****************************************************************************/
1661cdf0e10cSrcweir class ORegistryServiceManager : public OServiceManager
1662cdf0e10cSrcweir {
1663cdf0e10cSrcweir public:
1664cdf0e10cSrcweir ORegistryServiceManager( Reference< XComponentContext > const & xContext );
1665cdf0e10cSrcweir virtual ~ORegistryServiceManager();
1666cdf0e10cSrcweir
1667cdf0e10cSrcweir // XInitialization
1668cdf0e10cSrcweir void SAL_CALL initialize(const Sequence< Any >& Arguments)
1669cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
1670cdf0e10cSrcweir
1671cdf0e10cSrcweir // XServiceInfo
getImplementationName()1672cdf0e10cSrcweir OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException)
1673cdf0e10cSrcweir { return stoc_bootstrap::regsmgr_getImplementationName(); }
1674cdf0e10cSrcweir
1675cdf0e10cSrcweir Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
1676cdf0e10cSrcweir
1677cdf0e10cSrcweir // XMultiServiceFactory
1678cdf0e10cSrcweir Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException);
1679cdf0e10cSrcweir
1680cdf0e10cSrcweir // XContentEnumerationAccess
1681cdf0e10cSrcweir //Sequence< OUString > getAvailableServiceNames() throw( (Exception) );
1682cdf0e10cSrcweir Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException);
1683cdf0e10cSrcweir virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(
1684cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext )
1685cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir // XComponent
1688cdf0e10cSrcweir void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir // OServiceManager
1691cdf0e10cSrcweir Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo()
1692cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException);
1693cdf0e10cSrcweir Any SAL_CALL getPropertyValue(const OUString& PropertyName)
1694cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
1695cdf0e10cSrcweir
1696cdf0e10cSrcweir protected:
1697cdf0e10cSrcweir //OServiceManager
1698cdf0e10cSrcweir Sequence< Reference< XInterface > > queryServiceFactories(
1699cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext );
1700cdf0e10cSrcweir private:
1701cdf0e10cSrcweir Reference<XRegistryKey > getRootKey();
1702cdf0e10cSrcweir Reference<XInterface > loadWithImplementationName(
1703cdf0e10cSrcweir const OUString & rImplName, Reference< XComponentContext > const & xContext );
1704cdf0e10cSrcweir Sequence<OUString> getFromServiceName(const OUString& serviceName);
1705cdf0e10cSrcweir Reference<XInterface > loadWithServiceName(
1706cdf0e10cSrcweir const OUString & rImplName, Reference< XComponentContext > const & xContext );
1707cdf0e10cSrcweir void fillAllNamesFromRegistry( HashSet_OWString & );
1708cdf0e10cSrcweir
1709cdf0e10cSrcweir sal_Bool m_searchedRegistry;
1710cdf0e10cSrcweir Reference<XSimpleRegistry > m_xRegistry; // readonly property Registry
1711cdf0e10cSrcweir Reference<XRegistryKey > m_xRootKey;
1712cdf0e10cSrcweir
1713cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1714cdf0e10cSrcweir bool m_init;
1715cdf0e10cSrcweir #endif
1716cdf0e10cSrcweir };
1717cdf0e10cSrcweir
1718cdf0e10cSrcweir /**
1719cdf0e10cSrcweir * Create a ServiceManager
1720cdf0e10cSrcweir */
ORegistryServiceManager(Reference<XComponentContext> const & xContext)1721cdf0e10cSrcweir ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > const & xContext )
1722cdf0e10cSrcweir : OServiceManager( xContext )
1723cdf0e10cSrcweir , m_searchedRegistry(sal_False)
1724cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1725cdf0e10cSrcweir , m_init( false )
1726cdf0e10cSrcweir #endif
1727cdf0e10cSrcweir {
1728cdf0e10cSrcweir }
1729cdf0e10cSrcweir
1730cdf0e10cSrcweir /**
1731cdf0e10cSrcweir * Destroy the ServiceManager
1732cdf0e10cSrcweir */
~ORegistryServiceManager()1733cdf0e10cSrcweir ORegistryServiceManager::~ORegistryServiceManager()
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir }
1736cdf0e10cSrcweir
1737cdf0e10cSrcweir // XComponent
dispose()1738cdf0e10cSrcweir void ORegistryServiceManager::dispose()
1739cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1740cdf0e10cSrcweir {
1741cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
1742cdf0e10cSrcweir return;
1743cdf0e10cSrcweir OServiceManager::dispose();
1744cdf0e10cSrcweir // dispose
1745cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1746cdf0e10cSrcweir // erase all members
1747cdf0e10cSrcweir m_xRegistry = Reference<XSimpleRegistry >();
1748cdf0e10cSrcweir m_xRootKey = Reference<XRegistryKey >();
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir
1751cdf0e10cSrcweir /**
1752cdf0e10cSrcweir * Return the root key of the registry. The Default registry service is ordered
1753cdf0e10cSrcweir * if no registry is set.
1754cdf0e10cSrcweir */
1755cdf0e10cSrcweir //Reference<XServiceProvider > create_DefaultRegistry_ServiceProvider();
1756cdf0e10cSrcweir
getRootKey()1757cdf0e10cSrcweir Reference<XRegistryKey > ORegistryServiceManager::getRootKey()
1758cdf0e10cSrcweir {
1759cdf0e10cSrcweir if( !m_xRootKey.is() )
1760cdf0e10cSrcweir {
1761cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1762cdf0e10cSrcweir // DefaultRegistry suchen !!!!
1763cdf0e10cSrcweir if( !m_xRegistry.is() && !m_searchedRegistry )
1764cdf0e10cSrcweir {
1765cdf0e10cSrcweir // merken, es wird nur einmal gesucht
1766cdf0e10cSrcweir m_searchedRegistry = sal_True;
1767cdf0e10cSrcweir
1768cdf0e10cSrcweir m_xRegistry.set(
1769cdf0e10cSrcweir createInstanceWithContext(
1770cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.DefaultRegistry") ),
1771cdf0e10cSrcweir m_xContext ),
1772cdf0e10cSrcweir UNO_QUERY );
1773cdf0e10cSrcweir }
1774cdf0e10cSrcweir if( m_xRegistry.is() && !m_xRootKey.is() )
1775cdf0e10cSrcweir m_xRootKey = m_xRegistry->getRootKey();
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir return m_xRootKey;
1779cdf0e10cSrcweir }
1780cdf0e10cSrcweir
1781cdf0e10cSrcweir /**
1782cdf0e10cSrcweir * Create a service provider from the registry with an implementation name
1783cdf0e10cSrcweir */
loadWithImplementationName(const OUString & name,Reference<XComponentContext> const & xContext)1784cdf0e10cSrcweir Reference<XInterface > ORegistryServiceManager::loadWithImplementationName(
1785cdf0e10cSrcweir const OUString& name, Reference< XComponentContext > const & xContext )
1786cdf0e10cSrcweir {
1787cdf0e10cSrcweir Reference<XInterface > ret;
1788cdf0e10cSrcweir
1789cdf0e10cSrcweir Reference<XRegistryKey > xRootKey = getRootKey();
1790cdf0e10cSrcweir if( !xRootKey.is() )
1791cdf0e10cSrcweir return ret;
1792cdf0e10cSrcweir
1793cdf0e10cSrcweir try
1794cdf0e10cSrcweir {
1795cdf0e10cSrcweir OUString implementationName = OUString( RTL_CONSTASCII_USTRINGPARAM("/IMPLEMENTATIONS/") ) + name;
1796cdf0e10cSrcweir Reference<XRegistryKey > xImpKey = m_xRootKey->openKey(implementationName);
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir if( xImpKey.is() )
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMgr;
1801cdf0e10cSrcweir if (xContext.is())
1802cdf0e10cSrcweir xMgr.set( xContext->getServiceManager(), UNO_QUERY_THROW );
1803cdf0e10cSrcweir else
1804cdf0e10cSrcweir xMgr.set( this );
1805cdf0e10cSrcweir ret = createSingleRegistryFactory( xMgr, name, xImpKey );
1806cdf0e10cSrcweir insert( makeAny( ret ) );
1807cdf0e10cSrcweir // Remember this factory as loaded in contrast to inserted ( XSet::insert)
1808cdf0e10cSrcweir // factories. Those loaded factories in this set are candidates for being
1809cdf0e10cSrcweir // released on an unloading notification.
1810cdf0e10cSrcweir m_SetLoadedFactories.insert( ret);
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir }
1813cdf0e10cSrcweir catch (InvalidRegistryException &)
1814cdf0e10cSrcweir {
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir
1817cdf0e10cSrcweir return ret;
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir
1820cdf0e10cSrcweir /**
1821cdf0e10cSrcweir * Return all implementation out of the registry.
1822cdf0e10cSrcweir */
getFromServiceName(const OUString & serviceName)1823cdf0e10cSrcweir Sequence<OUString> ORegistryServiceManager::getFromServiceName(
1824cdf0e10cSrcweir const OUString& serviceName )
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir OUStringBuffer buf;
1827cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "/SERVICES/" ) );
1828cdf0e10cSrcweir buf.append( serviceName );
1829cdf0e10cSrcweir return retrieveAsciiValueList( m_xRegistry, buf.makeStringAndClear() );
1830cdf0e10cSrcweir }
1831cdf0e10cSrcweir
1832cdf0e10cSrcweir /**
1833cdf0e10cSrcweir * Create a service provider from the registry
1834cdf0e10cSrcweir */
loadWithServiceName(const OUString & serviceName,Reference<XComponentContext> const & xContext)1835cdf0e10cSrcweir Reference<XInterface > ORegistryServiceManager::loadWithServiceName(
1836cdf0e10cSrcweir const OUString& serviceName, Reference< XComponentContext > const & xContext )
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir Sequence<OUString> implEntries = getFromServiceName( serviceName );
1839cdf0e10cSrcweir for (sal_Int32 i = 0; i < implEntries.getLength(); i++)
1840cdf0e10cSrcweir {
1841cdf0e10cSrcweir Reference< XInterface > x(
1842cdf0e10cSrcweir loadWithImplementationName( implEntries.getConstArray()[i], xContext ) );
1843cdf0e10cSrcweir if (x.is())
1844cdf0e10cSrcweir return x;
1845cdf0e10cSrcweir }
1846cdf0e10cSrcweir
1847cdf0e10cSrcweir return Reference<XInterface >();
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir
1850cdf0e10cSrcweir /**
1851cdf0e10cSrcweir * Return a sequence of all service names from the registry.
1852cdf0e10cSrcweir */
fillAllNamesFromRegistry(HashSet_OWString & rSet)1853cdf0e10cSrcweir void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet )
1854cdf0e10cSrcweir {
1855cdf0e10cSrcweir Reference<XRegistryKey > xRootKey = getRootKey();
1856cdf0e10cSrcweir if( !xRootKey.is() )
1857cdf0e10cSrcweir return;
1858cdf0e10cSrcweir
1859cdf0e10cSrcweir try
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir Reference<XRegistryKey > xServicesKey = xRootKey->openKey(
1862cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("SERVICES") ) );
1863cdf0e10cSrcweir // root + /Services + /
1864cdf0e10cSrcweir if( xServicesKey.is() )
1865cdf0e10cSrcweir {
1866cdf0e10cSrcweir sal_Int32 nPrefix = xServicesKey->getKeyName().getLength() +1;
1867cdf0e10cSrcweir Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys();
1868cdf0e10cSrcweir for( sal_Int32 i = 0; i < aKeys.getLength(); i++ )
1869cdf0e10cSrcweir rSet.insert( aKeys.getConstArray()[i]->getKeyName().copy( nPrefix ) );
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir }
1872cdf0e10cSrcweir catch (InvalidRegistryException &)
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir }
1876cdf0e10cSrcweir
1877cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & Arguments)1878cdf0e10cSrcweir void ORegistryServiceManager::initialize(const Sequence< Any >& Arguments)
1879cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1880cdf0e10cSrcweir {
1881cdf0e10cSrcweir check_undisposed();
1882cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1883cdf0e10cSrcweir if (Arguments.getLength() > 0)
1884cdf0e10cSrcweir {
1885cdf0e10cSrcweir m_xRootKey.clear();
1886cdf0e10cSrcweir Arguments[ 0 ] >>= m_xRegistry;
1887cdf0e10cSrcweir }
1888cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1889cdf0e10cSrcweir // to find all bootstrapping processes to be fixed...
1890cdf0e10cSrcweir OSL_ENSURE( !m_init, "### second init of service manager instance!" );
1891cdf0e10cSrcweir m_init = true;
1892cdf0e10cSrcweir #endif
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir // XMultiServiceFactory, XContentEnumeration
getAvailableServiceNames()1896cdf0e10cSrcweir Sequence< OUString > ORegistryServiceManager::getAvailableServiceNames()
1897cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1898cdf0e10cSrcweir {
1899cdf0e10cSrcweir check_undisposed();
1900cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1901cdf0e10cSrcweir // all names
1902cdf0e10cSrcweir HashSet_OWString aNameSet;
1903cdf0e10cSrcweir
1904cdf0e10cSrcweir // all names from the registry
1905cdf0e10cSrcweir fillAllNamesFromRegistry( aNameSet );
1906cdf0e10cSrcweir
1907cdf0e10cSrcweir return OServiceManager::getUniqueAvailableServiceNames( aNameSet );
1908cdf0e10cSrcweir }
1909cdf0e10cSrcweir
1910cdf0e10cSrcweir // XServiceInfo
getSupportedServiceNames()1911cdf0e10cSrcweir Sequence< OUString > ORegistryServiceManager::getSupportedServiceNames()
1912cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1913cdf0e10cSrcweir {
1914cdf0e10cSrcweir check_undisposed();
1915cdf0e10cSrcweir return stoc_bootstrap::regsmgr_getSupportedServiceNames();
1916cdf0e10cSrcweir }
1917cdf0e10cSrcweir
1918cdf0e10cSrcweir
1919cdf0e10cSrcweir // OServiceManager
queryServiceFactories(const OUString & aServiceName,Reference<XComponentContext> const & xContext)1920cdf0e10cSrcweir Sequence< Reference< XInterface > > ORegistryServiceManager::queryServiceFactories(
1921cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext )
1922cdf0e10cSrcweir {
1923cdf0e10cSrcweir Sequence< Reference< XInterface > > ret(
1924cdf0e10cSrcweir OServiceManager::queryServiceFactories( aServiceName, xContext ) );
1925cdf0e10cSrcweir if (ret.getLength())
1926cdf0e10cSrcweir {
1927cdf0e10cSrcweir return ret;
1928cdf0e10cSrcweir }
1929cdf0e10cSrcweir else
1930cdf0e10cSrcweir {
1931cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1932cdf0e10cSrcweir Reference< XInterface > x( loadWithServiceName( aServiceName, xContext ) );
1933cdf0e10cSrcweir if (! x.is())
1934cdf0e10cSrcweir x = loadWithImplementationName( aServiceName, xContext );
1935cdf0e10cSrcweir return Sequence< Reference< XInterface > >( &x, 1 );
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir }
1938cdf0e10cSrcweir
1939cdf0e10cSrcweir // XContentEnumerationAccess
createContentEnumeration(const OUString & aServiceName,Reference<XComponentContext> const & xContext)1940cdf0e10cSrcweir Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration(
1941cdf0e10cSrcweir const OUString& aServiceName, Reference< XComponentContext > const & xContext )
1942cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1943cdf0e10cSrcweir {
1944cdf0e10cSrcweir check_undisposed();
1945cdf0e10cSrcweir MutexGuard aGuard( ((ORegistryServiceManager *)this)->m_mutex );
1946cdf0e10cSrcweir // get all implementation names registered under this service name from the registry
1947cdf0e10cSrcweir Sequence<OUString> aImpls = ((ORegistryServiceManager *)this)->getFromServiceName( aServiceName );
1948cdf0e10cSrcweir // load and insert all factories specified by the registry
1949cdf0e10cSrcweir sal_Int32 i;
1950cdf0e10cSrcweir OUString aImplName;
1951cdf0e10cSrcweir for( i = 0; i < aImpls.getLength(); i++ )
1952cdf0e10cSrcweir {
1953cdf0e10cSrcweir aImplName = aImpls.getConstArray()[i];
1954cdf0e10cSrcweir if ( !haveFactoryWithThisImplementation(aImplName) )
1955cdf0e10cSrcweir {
1956cdf0e10cSrcweir loadWithImplementationName( aImplName, xContext );
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir }
1959cdf0e10cSrcweir // call the superclass to enumerate all contents
1960cdf0e10cSrcweir return OServiceManager::createContentEnumeration( aServiceName, xContext );
1961cdf0e10cSrcweir }
createContentEnumeration(const OUString & aServiceName)1962cdf0e10cSrcweir Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration(
1963cdf0e10cSrcweir const OUString& aServiceName )
1964cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1965cdf0e10cSrcweir {
1966cdf0e10cSrcweir return createContentEnumeration( aServiceName, m_xContext );
1967cdf0e10cSrcweir }
1968cdf0e10cSrcweir
1969cdf0e10cSrcweir // OServiceManager
getPropertySetInfo()1970cdf0e10cSrcweir Reference<XPropertySetInfo > ORegistryServiceManager::getPropertySetInfo()
1971cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException)
1972cdf0e10cSrcweir {
1973cdf0e10cSrcweir check_undisposed();
1974cdf0e10cSrcweir if (! m_xPropertyInfo.is())
1975cdf0e10cSrcweir {
1976cdf0e10cSrcweir Sequence< beans::Property > seq( 2 );
1977cdf0e10cSrcweir seq[ 0 ] = beans::Property(
1978cdf0e10cSrcweir OUSTR("DefaultContext"), -1, ::getCppuType( &m_xContext ), 0 );
1979cdf0e10cSrcweir seq[ 1 ] = beans::Property(
1980cdf0e10cSrcweir OUSTR("Registry"), -1, ::getCppuType( &m_xRegistry ),
1981cdf0e10cSrcweir beans::PropertyAttribute::READONLY );
1982cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( new PropertySetInfo_Impl( seq ) );
1983cdf0e10cSrcweir
1984cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
1985cdf0e10cSrcweir if (! m_xPropertyInfo.is())
1986cdf0e10cSrcweir {
1987cdf0e10cSrcweir m_xPropertyInfo = xInfo;
1988cdf0e10cSrcweir }
1989cdf0e10cSrcweir }
1990cdf0e10cSrcweir return m_xPropertyInfo;
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir
getPropertyValue(const OUString & PropertyName)1993cdf0e10cSrcweir Any ORegistryServiceManager::getPropertyValue(const OUString& PropertyName)
1994cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1995cdf0e10cSrcweir {
1996cdf0e10cSrcweir check_undisposed();
1997cdf0e10cSrcweir if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Registry") ))
1998cdf0e10cSrcweir {
1999cdf0e10cSrcweir MutexGuard aGuard( m_mutex );
2000cdf0e10cSrcweir if( m_xRegistry.is() )
2001cdf0e10cSrcweir return makeAny( m_xRegistry );
2002cdf0e10cSrcweir else
2003cdf0e10cSrcweir return Any();
2004cdf0e10cSrcweir }
2005cdf0e10cSrcweir return OServiceManager::getPropertyValue( PropertyName );
2006cdf0e10cSrcweir }
2007cdf0e10cSrcweir
2008cdf0e10cSrcweir /* This is the listener function used by the service manager in order
2009cdf0e10cSrcweir to implement the unloading mechanism, id is the this pointer of the
2010cdf0e10cSrcweir service manager instances. On notification, that is the function is being called
2011cdf0e10cSrcweir by rtl_unloadUnusedModules, the cached factroies are being removed from the
2012cdf0e10cSrcweir service manager ( except manually inserted factories).
2013cdf0e10cSrcweir */
smgrUnloadingListener(void * id)2014cdf0e10cSrcweir extern "C" void SAL_CALL smgrUnloadingListener(void* id)
2015cdf0e10cSrcweir {
2016cdf0e10cSrcweir stoc_smgr::OServiceManager* pMgr= reinterpret_cast<stoc_smgr::OServiceManager*>( id);
2017cdf0e10cSrcweir pMgr->onUnloadingNotify();
2018cdf0e10cSrcweir }
2019cdf0e10cSrcweir
2020cdf0e10cSrcweir } // namespace
2021cdf0e10cSrcweir
2022cdf0e10cSrcweir namespace stoc_bootstrap
2023cdf0e10cSrcweir {
2024cdf0e10cSrcweir /**
2025cdf0e10cSrcweir * Create the ServiceManager
2026cdf0e10cSrcweir */
OServiceManager_CreateInstance(const Reference<XComponentContext> & xContext)2027cdf0e10cSrcweir Reference<XInterface > SAL_CALL OServiceManager_CreateInstance(
2028cdf0e10cSrcweir const Reference< XComponentContext > & xContext )
2029cdf0e10cSrcweir {
2030cdf0e10cSrcweir return Reference<XInterface >(
2031cdf0e10cSrcweir SAL_STATIC_CAST(
2032cdf0e10cSrcweir XInterface *, SAL_STATIC_CAST(
2033cdf0e10cSrcweir OWeakObject *, new stoc_smgr::OServiceManager( xContext ) ) ) );
2034cdf0e10cSrcweir }
2035cdf0e10cSrcweir
2036cdf0e10cSrcweir /**
2037cdf0e10cSrcweir * Create the ServiceManager
2038cdf0e10cSrcweir */
ORegistryServiceManager_CreateInstance(const Reference<XComponentContext> & xContext)2039cdf0e10cSrcweir Reference<XInterface > SAL_CALL ORegistryServiceManager_CreateInstance(
2040cdf0e10cSrcweir const Reference< XComponentContext > & xContext )
2041cdf0e10cSrcweir throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
2042cdf0e10cSrcweir {
2043cdf0e10cSrcweir return Reference<XInterface >(
2044cdf0e10cSrcweir SAL_STATIC_CAST(
2045cdf0e10cSrcweir XInterface *, SAL_STATIC_CAST(
2046cdf0e10cSrcweir OWeakObject *, new stoc_smgr::ORegistryServiceManager( xContext ) ) ) );
2047cdf0e10cSrcweir }
2048cdf0e10cSrcweir
OServiceManagerWrapper_CreateInstance(const Reference<XComponentContext> & xContext)2049cdf0e10cSrcweir Reference<XInterface > SAL_CALL OServiceManagerWrapper_CreateInstance(
2050cdf0e10cSrcweir const Reference< XComponentContext > & xContext )
2051cdf0e10cSrcweir throw (Exception)
2052cdf0e10cSrcweir {
2053cdf0e10cSrcweir return (OWeakObject *)new stoc_smgr::OServiceManagerWrapper( xContext );
2054cdf0e10cSrcweir }
2055cdf0e10cSrcweir }
2056