Update ooo320-m1
[ooovba.git] / package / source / manifest / UnoRegister.cxx
blob870f574e936963fb5a8e1404e14b6908ab07b73f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoRegister.cxx,v $
10 * $Revision: 1.8 $
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_package.hxx"
33 #include <ManifestReader.hxx>
34 #include <ManifestWriter.hxx>
35 #include <cppuhelper/factory.hxx>
36 #ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP
37 #include <com/sun/star/registry/XRegistryKey.hpp>
38 #endif
39 #include <vos/diagnose.hxx>
40 #include <ZipPackage.hxx>
42 #include <zipfileaccess.hxx>
44 using namespace ::rtl;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::registry;
49 using namespace ::com::sun::star::packages;
50 using namespace ::com::sun::star::packages::manifest;
52 static sal_Bool writeInfo( void * pRegistryKey,
53 const OUString & rImplementationName,
54 Sequence< OUString > const & rServiceNames )
56 OUString aKeyName( OUString::createFromAscii( "/" ) );
57 aKeyName += rImplementationName;
58 aKeyName += OUString::createFromAscii( "/UNO/SERVICES" );
60 Reference< XRegistryKey > xKey;
61 try
63 xKey = static_cast< XRegistryKey * >(
64 pRegistryKey )->createKey( aKeyName );
66 catch ( InvalidRegistryException const & )
70 if ( !xKey.is() )
71 return sal_False;
73 sal_Bool bSuccess = sal_True;
75 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
77 try
79 xKey->createKey( rServiceNames[ n ] );
81 catch ( InvalidRegistryException const & )
83 bSuccess = sal_False;
84 break;
87 return bSuccess;
89 // C functions to implement this as a component
91 extern "C" void SAL_CALL component_getImplementationEnvironment(
92 const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
94 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
97 /**
98 * This function creates an implementation section in the registry and another subkey
99 * for each supported service.
100 * @param pServiceManager generic uno interface providing a service manager
101 * @param pRegistryKey generic uno interface providing registry key to write
103 extern "C" sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
105 return pRegistryKey &&
106 writeInfo (pRegistryKey,
107 ManifestReader::static_getImplementationName(),
108 ManifestReader::static_getSupportedServiceNames() ) &&
109 writeInfo (pRegistryKey,
110 ManifestWriter::static_getImplementationName(),
111 ManifestWriter::static_getSupportedServiceNames() ) &&
112 writeInfo (pRegistryKey,
113 ZipPackage::static_getImplementationName(),
114 ZipPackage::static_getSupportedServiceNames() ) &&
116 writeInfo (pRegistryKey,
117 OZipFileAccess::impl_staticGetImplementationName(),
118 OZipFileAccess::impl_staticGetSupportedServiceNames() );
124 * This function is called to get service factories for an implementation.
125 * @param pImplName name of implementation
126 * @param pServiceManager generic uno interface providing a service manager to instantiate components
127 * @param pRegistryKey registry data key to read and write component persistent data
128 * @return a component factory (generic uno interface)
130 extern "C" void * SAL_CALL component_getFactory(
131 const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
133 void * pRet = 0;
134 Reference< XMultiServiceFactory > xSMgr(
135 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
136 Reference< XSingleServiceFactory > xFactory;
138 if (ManifestReader::static_getImplementationName().compareToAscii( pImplName ) == 0)
139 xFactory = ManifestReader::createServiceFactory ( xSMgr );
140 else if (ManifestWriter::static_getImplementationName().compareToAscii( pImplName ) == 0)
141 xFactory = ManifestWriter::createServiceFactory ( xSMgr );
142 else if (ZipPackage::static_getImplementationName().compareToAscii( pImplName ) == 0)
143 xFactory = ZipPackage::createServiceFactory ( xSMgr );
144 else if ( OZipFileAccess::impl_staticGetImplementationName().compareToAscii( pImplName ) == 0 )
145 xFactory = ::cppu::createSingleFactory( xSMgr,
146 OZipFileAccess::impl_staticGetImplementationName(),
147 OZipFileAccess::impl_staticCreateSelfInstance,
148 OZipFileAccess::impl_staticGetSupportedServiceNames() );
150 if ( xFactory.is() )
152 xFactory->acquire();
153 pRet = xFactory.get();
155 return pRet;