xref: /aoo41x/main/io/test/stm/testfactreg.cxx (revision cdf0e10c)
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_io.hxx"
30 #include <stdio.h>
31 #include <string.h>
32 
33 #include <osl/diagnose.h>
34 
35 #include <cppuhelper/factory.hxx>  // for EXTERN_SERVICE_CALLTYPE
36 
37 using namespace ::rtl;
38 using namespace ::cppu;
39 using namespace ::com::sun::star::registry;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 
43 #include "testfactreg.hxx"
44 
45 
46 extern "C"
47 {
48 
49 void SAL_CALL component_getImplementationEnvironment(
50 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
51 {
52 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
53 }
54 
55 
56 sal_Bool SAL_CALL component_writeInfo(
57 	void * pServiceManager, void * pRegistryKey )
58 {
59 	if (pRegistryKey)
60 	{
61 		try
62 		{
63 			Reference< XRegistryKey > xKey(
64 				reinterpret_cast< XRegistryKey * >( pRegistryKey ) );
65 
66 			OUString str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
67 				OPipeTest_getImplementationName() +
68 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
69 			Reference< XRegistryKey >  xNewKey = xKey->createKey( str );
70 			xNewKey->createKey( OPipeTest_getServiceName() );
71 
72 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
73 				OPumpTest_getImplementationName() +
74 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
75 			xNewKey = xKey->createKey( str );
76 			xNewKey->createKey( OPumpTest_getServiceName() );
77 
78 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
79 				ODataStreamTest_getImplementationName(1) +
80 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
81 			xNewKey = xKey->createKey( str );
82 			xNewKey->createKey( ODataStreamTest_getServiceName(1) );
83 
84 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
85 				ODataStreamTest_getImplementationName(2) +
86 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
87 			xNewKey = xKey->createKey( str );
88 			xNewKey->createKey( ODataStreamTest_getServiceName(2) );
89 
90 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
91 				OObjectStreamTest_getImplementationName(1) +
92 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
93 			xNewKey = xKey->createKey( str );
94 			xNewKey->createKey( OObjectStreamTest_getServiceName(1) );
95 
96 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
97 				OObjectStreamTest_getImplementationName(2) +
98 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
99 			xNewKey = xKey->createKey( str );
100 			xNewKey->createKey( OObjectStreamTest_getServiceName(2) );
101 
102 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
103 				OMarkableOutputStreamTest_getImplementationName() +
104 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
105 			xNewKey = xKey->createKey( str );
106 			xNewKey->createKey( OMarkableOutputStreamTest_getServiceName() );
107 
108 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
109 				OMarkableInputStreamTest_getImplementationName() +
110 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
111 			xNewKey = xKey->createKey( str );
112 			xNewKey->createKey( OMarkableInputStreamTest_getServiceName() );
113 
114 			str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
115 				OMyPersistObject_getImplementationName() +
116 				OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
117 			xNewKey = xKey->createKey( str );
118 			xNewKey->createKey( OMyPersistObject_getServiceName() );
119 
120 			return sal_True;
121 		}
122 		catch (InvalidRegistryException &)
123 		{
124 			OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
125 		}
126 	}
127 	return sal_False;
128 }
129 
130 void * SAL_CALL component_getFactory(
131 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
132 {
133 	void * pRet = 0;
134 
135 	if (pServiceManager )
136 	{
137 		Reference< XSingleServiceFactory > xRet;
138 		Reference< XMultiServiceFactory > xSMgr =
139 			reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
140 
141 		OUString aImplementationName = OUString::createFromAscii( pImplName );
142 
143 		if (aImplementationName == OPipeTest_getImplementationName() )
144 		{
145 			xRet = createSingleFactory( xSMgr, aImplementationName,
146 										OPipeTest_CreateInstance,
147 										OPipeTest_getSupportedServiceNames() );
148 		}
149 		else if (aImplementationName == OPumpTest_getImplementationName() )
150 		{
151 			xRet = createSingleFactory( xSMgr, aImplementationName,
152 										OPumpTest_CreateInstance,
153 										OPumpTest_getSupportedServiceNames() );
154 		}
155 
156 		else if( aImplementationName == ODataStreamTest_getImplementationName(1) ) {
157 			xRet = createSingleFactory( xSMgr , aImplementationName,
158 										ODataStreamTest_CreateInstance,
159 										ODataStreamTest_getSupportedServiceNames(1) );
160 		}
161 		else if( aImplementationName == ODataStreamTest_getImplementationName(2) ) {
162 			xRet = createSingleFactory( xSMgr , aImplementationName,
163 										ODataStreamTest_CreateInstance,
164 										ODataStreamTest_getSupportedServiceNames(2) );
165 		}
166 		else if( aImplementationName == OObjectStreamTest_getImplementationName(1) ) {
167 			xRet = createSingleFactory( xSMgr , aImplementationName,
168 										OObjectStreamTest_CreateInstance,
169 										OObjectStreamTest_getSupportedServiceNames(1) );
170 		}
171 		else if( aImplementationName == OObjectStreamTest_getImplementationName(2) ) {
172 			xRet = createSingleFactory( xSMgr , aImplementationName,
173 										OObjectStreamTest_CreateInstance,
174 										OObjectStreamTest_getSupportedServiceNames(2) );
175 		}
176 		else if( aImplementationName == OMarkableOutputStreamTest_getImplementationName() ) {
177 			xRet = createSingleFactory( xSMgr , aImplementationName,
178 										OMarkableOutputStreamTest_CreateInstance,
179 										OMarkableOutputStreamTest_getSupportedServiceNames() );
180 		}
181 		else if( aImplementationName == OMarkableInputStreamTest_getImplementationName() ) {
182 			xRet = createSingleFactory( xSMgr , aImplementationName,
183 										OMarkableInputStreamTest_CreateInstance,
184 										OMarkableInputStreamTest_getSupportedServiceNames() );
185 		}
186 		else if( aImplementationName == OMyPersistObject_getImplementationName() ) {
187 			xRet = createSingleFactory( xSMgr , aImplementationName,
188 									OMyPersistObject_CreateInstance,
189 										OMyPersistObject_getSupportedServiceNames() );
190 		}
191 		if (xRet.is())
192 		{
193 			xRet->acquire();
194 			pRet = xRet.get();
195 		}
196 	}
197 
198 	return pRet;
199 }
200 
201 }
202 
203 Sequence<sal_Int8 > createSeq( char * p )
204 {
205 	Sequence<sal_Int8> seq( strlen( p )+1 );
206 	strcpy( (char * ) seq.getArray() , p );
207 	return seq;
208 }
209 
210 Sequence<sal_Int8> createIntSeq( sal_Int32 i )
211 {
212 	char pcCount[20];
213 	sprintf( pcCount , "%d" , i );
214 	return createSeq( pcCount );
215 }
216 
217