merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / resource / res_services.cxx
blob6babbe48e8cdaaac8029aad0ef9b26ae4068dc78
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "res_services.hxx"
32 /** === begin UNO includes === **/
33 #include <com/sun/star/registry/XRegistryKey.hpp>
34 /** === end UNO includes === **/
36 /** === begin UNO using === **/
37 using ::com::sun::star::registry::XRegistryKey;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::lang::XMultiServiceFactory;
42 using ::com::sun::star::lang::XSingleServiceFactory;
43 using ::com::sun::star::uno::UNO_QUERY;
44 /** === end UNO using === **/
46 #include <vector>
48 namespace res
50 ::std::vector< ComponentInfo > getComponentInfos()
52 ::std::vector< ::res::ComponentInfo > aComponentInfos;
53 aComponentInfos.push_back( getComponentInfo_VclStringResourceLoader() );
54 aComponentInfos.push_back( getComponentInfo_OpenOfficeResourceLoader() );
55 return aComponentInfos;
59 extern "C" {
61 void SAL_CALL component_getImplementationEnvironment(
62 const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
64 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
67 sal_Bool SAL_CALL component_writeInfo( void * /*pServiceManager*/, XRegistryKey * pRegistryKey )
69 try
71 ::std::vector< ::res::ComponentInfo > aComponentInfos( ::res::getComponentInfos() );
72 for ( ::std::vector< ::res::ComponentInfo >::const_iterator loop = aComponentInfos.begin();
73 loop != aComponentInfos.end();
74 ++loop
77 Reference< XRegistryKey > xNewKey =
78 pRegistryKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") )
79 + loop->sImplementationName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SERVICES" ) ) );
81 for( sal_Int32 i = 0; i < loop->aSupportedServices.getLength(); ++i )
82 xNewKey->createKey( loop->aSupportedServices.getConstArray()[i]);
84 if ( loop->sSingletonName.getLength() )
86 OSL_ENSURE( loop->aSupportedServices.getLength() == 1, "singletons must support exactly one service!" );
87 xNewKey = pRegistryKey->createKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") )
88 + loop->sImplementationName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/UNO/SINGLETONS/" ) )
89 + loop->sSingletonName );
90 xNewKey->setStringValue( loop->aSupportedServices[ 0 ] );
94 return sal_True;
96 catch (Exception &)
98 // not allowed to throw an exception over the c function.
99 //OSL_ENSURE( sal_False, "Exception cannot register component!" );
100 return sal_False;
104 void * SAL_CALL component_getFactory(
105 const sal_Char * pImplName, XMultiServiceFactory * /*pServiceManager*/, void * /*pRegistryKey*/ )
107 void * pRet = 0;
108 ::std::vector< ::res::ComponentInfo > aComponentInfos( ::res::getComponentInfos() );
109 for ( ::std::vector< ::res::ComponentInfo >::const_iterator loop = aComponentInfos.begin();
110 loop != aComponentInfos.end();
111 ++loop
114 if ( 0 == loop->sImplementationName.compareToAscii( pImplName ) )
116 // create the factory
117 Reference< XSingleServiceFactory > xFactory( ::cppu::createSingleComponentFactory(
118 loop->pFactory, loop->sImplementationName, loop->aSupportedServices ),
119 UNO_QUERY );
120 // acquire, because we return an interface pointer instead of a reference
121 xFactory->acquire();
122 pRet = xFactory.get();
125 return pRet;
128 } // extern "C"