1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cppuhelper.hxx"
30 #include <cppuhelper/implementationentry.hxx>
31 #include <rtl/ustrbuf.hxx>
32 
33 using namespace ::rtl;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::registry;
37 
38 namespace cppu {
39 
40 sal_Bool component_writeInfoHelper(
41 	void *, void *pRegistryKey , const struct ImplementationEntry entries[] )
42 {
43 	sal_Bool bRet = sal_False;
44 	try
45 	{
46 		if( pRegistryKey )
47 		{
48 			for( sal_Int32 i = 0; entries[i].create ; i ++ )
49 			{
50 				OUStringBuffer buf( 124 );
51 				buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/") );
52 				buf.append( entries[i].getImplementationName() );
53 				buf.appendAscii(RTL_CONSTASCII_STRINGPARAM( "/UNO/SERVICES" ) );
54 				Reference< XRegistryKey > xNewKey(
55 					reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( buf.makeStringAndClear()  ) );
56 
57 				Sequence< OUString > seq = entries[i].getSupportedServiceNames();
58 				const OUString *pArray = seq.getConstArray();
59 				for ( sal_Int32 nPos = 0 ; nPos < seq.getLength(); nPos ++ )
60 					xNewKey->createKey( pArray[nPos] );
61 			}
62 			bRet = sal_True;
63 		}
64 	}
65 	catch ( InvalidRegistryException & )
66 	{
67 		OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
68 	}
69 	return bRet;
70 }
71 
72 
73 void * component_getFactoryHelper(
74 	const sal_Char * pImplName, void *, void *,
75 	const struct ImplementationEntry entries[] )
76 {
77 
78   	void * pRet = 0;
79 	Reference< XSingleComponentFactory > xFactory;
80 
81 	for( sal_Int32 i = 0 ; entries[i].create ; i ++ )
82 	{
83 		OUString implName = entries[i].getImplementationName();
84 		if( 0 == implName.compareToAscii( pImplName ) )
85 		{
86 			xFactory = entries[i].createFactory(
87 				entries[i].create,
88 				implName,
89 				entries[i].getSupportedServiceNames(),
90 				entries[i].moduleCounter );
91 		}
92 	}
93 
94 	if( xFactory.is() )
95 	{
96 		xFactory->acquire();
97 		pRet = xFactory.get();
98 	}
99 	return pRet;
100 }
101 
102 }
103