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: res_services.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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "res_services.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/registry/XRegistryKey.hpp>
37 /** === end UNO includes === **/
39 /** === begin UNO using === **/
40 using ::com::sun::star::registry::XRegistryKey
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::com::sun::star::uno::Exception
;
44 using ::com::sun::star::lang::XMultiServiceFactory
;
45 using ::com::sun::star::lang::XSingleServiceFactory
;
46 using ::com::sun::star::uno::UNO_QUERY
;
47 /** === end UNO using === **/
53 ::std::vector
< ComponentInfo
> getComponentInfos()
55 ::std::vector
< ::res::ComponentInfo
> aComponentInfos
;
56 aComponentInfos
.push_back( getComponentInfo_VclStringResourceLoader() );
57 aComponentInfos
.push_back( getComponentInfo_OpenOfficeResourceLoader() );
58 return aComponentInfos
;
64 void SAL_CALL
component_getImplementationEnvironment(
65 const sal_Char
** ppEnvTypeName
, uno_Environment
** /*ppEnv*/ )
67 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
70 sal_Bool SAL_CALL
component_writeInfo( void * /*pServiceManager*/, XRegistryKey
* pRegistryKey
)
74 ::std::vector
< ::res::ComponentInfo
> aComponentInfos( ::res::getComponentInfos() );
75 for ( ::std::vector
< ::res::ComponentInfo
>::const_iterator loop
= aComponentInfos
.begin();
76 loop
!= aComponentInfos
.end();
80 Reference
< XRegistryKey
> xNewKey
=
81 pRegistryKey
->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") )
82 + loop
->sImplementationName
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES" ) ) );
84 for( sal_Int32 i
= 0; i
< loop
->aSupportedServices
.getLength(); ++i
)
85 xNewKey
->createKey( loop
->aSupportedServices
.getConstArray()[i
]);
87 if ( loop
->sSingletonName
.getLength() )
89 OSL_ENSURE( loop
->aSupportedServices
.getLength() == 1, "singletons must support exactly one service!" );
90 xNewKey
= pRegistryKey
->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") )
91 + loop
->sImplementationName
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SINGLETONS/" ) )
92 + loop
->sSingletonName
);
93 xNewKey
->setStringValue( loop
->aSupportedServices
[ 0 ] );
101 // not allowed to throw an exception over the c function.
102 //OSL_ENSURE( sal_False, "Exception cannot register component!" );
107 void * SAL_CALL
component_getFactory(
108 const sal_Char
* pImplName
, XMultiServiceFactory
* /*pServiceManager*/, void * /*pRegistryKey*/ )
111 ::std::vector
< ::res::ComponentInfo
> aComponentInfos( ::res::getComponentInfos() );
112 for ( ::std::vector
< ::res::ComponentInfo
>::const_iterator loop
= aComponentInfos
.begin();
113 loop
!= aComponentInfos
.end();
117 if ( 0 == loop
->sImplementationName
.compareToAscii( pImplName
) )
119 // create the factory
120 Reference
< XSingleServiceFactory
> xFactory( ::cppu::createSingleComponentFactory(
121 loop
->pFactory
, loop
->sImplementationName
, loop
->aSupportedServices
),
123 // acquire, because we return an interface pointer instead of a reference
125 pRet
= xFactory
.get();