1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tvfactory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_xmlhelp.hxx"
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include "tvfactory.hxx"
41 using namespace treeview
;
42 using namespace com::sun::star
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::beans
;
46 using namespace com::sun::star::container
;
50 TVFactory::TVFactory( const uno::Reference
< XMultiServiceFactory
>& xMSF
)
56 TVFactory::~TVFactory()
61 //////////////////////////////////////////////////////////////////////////
63 //////////////////////////////////////////////////////////////////////////
70 OWeakObject::acquire();
79 OWeakObject::release();
84 TVFactory::queryInterface(
86 throw( RuntimeException
)
88 Any aRet
= cppu::queryInterface( rType
,
89 SAL_STATIC_CAST( XServiceInfo
*, this ),
90 SAL_STATIC_CAST( XTypeProvider
*, this ),
91 SAL_STATIC_CAST( XMultiServiceFactory
*, this ) );
93 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
97 ////////////////////////////////////////////////////////////////////////////////
99 // XTypeProvider methods.
101 XTYPEPROVIDER_IMPL_3( TVFactory
,
104 XMultiServiceFactory
);
108 ////////////////////////////////////////////////////////////////////////////////
110 // XServiceInfo methods.
112 rtl::OUString SAL_CALL
113 TVFactory::getImplementationName()
114 throw( RuntimeException
)
116 return TVFactory::getImplementationName_static();
121 TVFactory::supportsService(
122 const rtl::OUString
& ServiceName
)
123 throw( RuntimeException
)
126 ServiceName
.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
127 ServiceName
.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
131 Sequence
< rtl::OUString
> SAL_CALL
132 TVFactory::getSupportedServiceNames( void )
133 throw( RuntimeException
)
135 return TVFactory::getSupportedServiceNames_static();
140 // XMultiServiceFactory
142 Reference
< XInterface
> SAL_CALL
143 TVFactory::createInstance(
144 const rtl::OUString
& aServiceSpecifier
)
149 aAny
<<= rtl::OUString();
150 Sequence
< Any
> seq( 1 );
151 seq
[0] <<= PropertyValue(
152 rtl::OUString::createFromAscii( "nodepath" ),
155 PropertyState_DIRECT_VALUE
);
157 return createInstanceWithArguments( aServiceSpecifier
,
162 Reference
< XInterface
> SAL_CALL
163 TVFactory::createInstanceWithArguments(
164 const rtl::OUString
& ServiceSpecifier
,
165 const Sequence
< Any
>& Arguments
)
169 (void)ServiceSpecifier
;
173 cppu::OWeakObject
* p
= new TVChildTarget( m_xMSF
);
174 m_xHDS
= Reference
< XInterface
>( p
);
177 Reference
< XInterface
> ret
= m_xHDS
;
179 rtl::OUString hierview
;
180 for( int i
= 0; i
< Arguments
.getLength(); ++i
)
183 if( ! ( Arguments
[i
] >>= pV
) )
186 if( pV
.Name
.compareToAscii( "nodepath" ) )
189 if( ! ( pV
.Value
>>= hierview
) )
195 if( hierview
.getLength() )
197 Reference
< XHierarchicalNameAccess
> xhieraccess( m_xHDS
,UNO_QUERY
);
198 Any aAny
= xhieraccess
->getByHierarchicalName( hierview
);
199 Reference
< XInterface
> xInterface
;
208 Sequence
< rtl::OUString
> SAL_CALL
209 TVFactory::getAvailableServiceNames( )
210 throw( RuntimeException
)
212 Sequence
< rtl::OUString
> seq( 1 );
213 seq
[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" );
222 rtl::OUString SAL_CALL
223 TVFactory::getImplementationName_static()
225 return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" );
229 Sequence
< rtl::OUString
> SAL_CALL
230 TVFactory::getSupportedServiceNames_static()
232 Sequence
< rtl::OUString
> seq( 2 );
233 seq
[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" );
234 seq
[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" );
239 Reference
< XSingleServiceFactory
> SAL_CALL
240 TVFactory::createServiceFactory(
241 const Reference
< XMultiServiceFactory
>& rxServiceMgr
)
243 return Reference
< XSingleServiceFactory
> (
244 cppu::createSingleFactory(
246 TVFactory::getImplementationName_static(),
247 TVFactory::CreateInstance
,
248 TVFactory::getSupportedServiceNames_static() ) );
253 Reference
< XInterface
> SAL_CALL
254 TVFactory::CreateInstance(
255 const Reference
< XMultiServiceFactory
>& xMultiServiceFactory
)
257 XServiceInfo
* xP
= (XServiceInfo
*) new TVFactory( xMultiServiceFactory
);
258 return Reference
< XInterface
>::query( xP
);
263 //=========================================================================
264 static sal_Bool
writeInfo( void * pRegistryKey
,
265 const rtl::OUString
& rImplementationName
,
266 Sequence
< rtl::OUString
> const & rServiceNames
)
268 rtl::OUString
aKeyName( rtl::OUString::createFromAscii( "/" ) );
269 aKeyName
+= rImplementationName
;
270 aKeyName
+= rtl::OUString::createFromAscii( "/UNO/SERVICES" );
272 Reference
< registry::XRegistryKey
> xKey
;
275 xKey
= static_cast< registry::XRegistryKey
* >(
276 pRegistryKey
)->createKey( aKeyName
);
278 catch ( registry::InvalidRegistryException
const & )
285 sal_Bool bSuccess
= sal_True
;
287 for ( sal_Int32 n
= 0; n
< rServiceNames
.getLength(); ++n
)
291 xKey
->createKey( rServiceNames
[ n
] );
293 catch ( registry::InvalidRegistryException
const & )
295 bSuccess
= sal_False
;
304 //=========================================================================
305 extern "C" void SAL_CALL
component_getImplementationEnvironment(
306 const sal_Char
** ppEnvTypeName
, uno_Environment
** ppEnv
)
310 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
315 //=========================================================================
316 extern "C" sal_Bool SAL_CALL
component_writeInfo(
317 void * pServiceManager
, void * pRegistryKey
)
319 (void)pServiceManager
;
321 return pRegistryKey
&& writeInfo( pRegistryKey
,
322 TVFactory::getImplementationName_static(),
323 TVFactory::getSupportedServiceNames_static() );
327 //=========================================================================
328 extern "C" void * SAL_CALL
component_getFactory(
329 const sal_Char
* pImplName
,void * pServiceManager
,void * pRegistryKey
)
335 Reference
< XMultiServiceFactory
> xSMgr(
336 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
) );
338 Reference
< XSingleServiceFactory
> xFactory
;
340 //////////////////////////////////////////////////////////////////////
341 // File Content Provider.
342 //////////////////////////////////////////////////////////////////////
344 if ( TVFactory::getImplementationName_static().compareToAscii( pImplName
) == 0 )
346 xFactory
= TVFactory::createServiceFactory( xSMgr
);
349 //////////////////////////////////////////////////////////////////////
354 pRet
= xFactory
.get();