Update ooo320-m1
[ooovba.git] / ucb / source / cacher / cacheserv.cxx
blob8daa84f0f19aa9453bc673186e019f8f50a91fb3
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: cacheserv.cxx,v $
10 * $Revision: 1.7 $
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_ucb.hxx"
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
35 #include <com/sun/star/registry/XRegistryKey.hpp>
36 #include <cachedcontentresultset.hxx>
37 #include <cachedcontentresultsetstub.hxx>
38 #include <cacheddynamicresultset.hxx>
39 #include <cacheddynamicresultsetstub.hxx>
41 using namespace rtl;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::registry;
46 //=========================================================================
47 static sal_Bool writeInfo( void * pRegistryKey,
48 const OUString & rImplementationName,
49 Sequence< OUString > const & rServiceNames )
51 OUString aKeyName( OUString::createFromAscii( "/" ) );
52 aKeyName += rImplementationName;
53 aKeyName += OUString::createFromAscii( "/UNO/SERVICES" );
55 Reference< XRegistryKey > xKey;
56 try
58 xKey = static_cast< XRegistryKey * >(
59 pRegistryKey )->createKey( aKeyName );
61 catch ( InvalidRegistryException const & )
65 if ( !xKey.is() )
66 return sal_False;
68 sal_Bool bSuccess = sal_True;
70 for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n )
72 try
74 xKey->createKey( rServiceNames[ n ] );
76 catch ( InvalidRegistryException const & )
78 bSuccess = sal_False;
79 break;
82 return bSuccess;
85 //=========================================================================
86 extern "C" void SAL_CALL component_getImplementationEnvironment(
87 const sal_Char ** ppEnvTypeName, uno_Environment ** )
89 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
92 //=========================================================================
93 extern "C" sal_Bool SAL_CALL component_writeInfo( void *, void * pRegistryKey )
95 return pRegistryKey &&
97 //////////////////////////////////////////////////////////////////////
98 // CachedContentResultSetFactory.
99 //////////////////////////////////////////////////////////////////////
101 writeInfo( pRegistryKey,
102 CachedContentResultSetFactory::getImplementationName_Static(),
103 CachedContentResultSetFactory::getSupportedServiceNames_Static() ) &&
105 //////////////////////////////////////////////////////////////////////
106 // CachedContentResultSetStubFactory.
107 //////////////////////////////////////////////////////////////////////
109 writeInfo( pRegistryKey,
110 CachedContentResultSetStubFactory::getImplementationName_Static(),
111 CachedContentResultSetStubFactory::getSupportedServiceNames_Static() ) &&
113 //////////////////////////////////////////////////////////////////////
114 // CachedDynamicResultSetFactory.
115 //////////////////////////////////////////////////////////////////////
117 writeInfo( pRegistryKey,
118 CachedDynamicResultSetFactory::getImplementationName_Static(),
119 CachedDynamicResultSetFactory::getSupportedServiceNames_Static() ) &&
121 //////////////////////////////////////////////////////////////////////
122 // CachedDynamicResultSetStubFactory.
123 //////////////////////////////////////////////////////////////////////
125 writeInfo( pRegistryKey,
126 CachedDynamicResultSetStubFactory::getImplementationName_Static(),
127 CachedDynamicResultSetStubFactory::getSupportedServiceNames_Static() );
130 //=========================================================================
131 extern "C" void * SAL_CALL component_getFactory(
132 const sal_Char * pImplName, void * pServiceManager, void * )
134 void * pRet = 0;
136 Reference< XMultiServiceFactory > xSMgr(
137 reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
138 Reference< XSingleServiceFactory > xFactory;
140 //////////////////////////////////////////////////////////////////////
141 // CachedContentResultSetFactory.
142 //////////////////////////////////////////////////////////////////////
144 if ( CachedContentResultSetFactory::getImplementationName_Static().
145 compareToAscii( pImplName ) == 0 )
147 xFactory = CachedContentResultSetFactory::createServiceFactory( xSMgr );
150 //////////////////////////////////////////////////////////////////////
151 // CachedContentResultSetStubFactory.
152 //////////////////////////////////////////////////////////////////////
154 else if ( CachedContentResultSetStubFactory::getImplementationName_Static().
155 compareToAscii( pImplName ) == 0 )
157 xFactory = CachedContentResultSetStubFactory::createServiceFactory( xSMgr );
160 //////////////////////////////////////////////////////////////////////
161 // CachedDynamicResultSetFactory.
162 //////////////////////////////////////////////////////////////////////
164 else if ( CachedDynamicResultSetFactory::getImplementationName_Static().
165 compareToAscii( pImplName ) == 0 )
167 xFactory = CachedDynamicResultSetFactory::createServiceFactory( xSMgr );
170 //////////////////////////////////////////////////////////////////////
171 // CachedDynamicResultSetStubFactory.
172 //////////////////////////////////////////////////////////////////////
174 else if ( CachedDynamicResultSetStubFactory::getImplementationName_Static().
175 compareToAscii( pImplName ) == 0 )
177 xFactory = CachedDynamicResultSetStubFactory::createServiceFactory( xSMgr );
180 //////////////////////////////////////////////////////////////////////
182 if ( xFactory.is() )
184 xFactory->acquire();
185 pRet = xFactory.get();
188 return pRet;