merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / so_comp / services.cxx
blobb8ffb10c26eacb02a5c46d076ca4929bfb9cc559
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: services.cxx,v $
10 * $Revision: 1.9 $
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_desktop.hxx"
34 #include "evaluation.hxx"
35 #include <com/sun/star/beans/NamedValue.hpp>
36 #include <com/sun/star/registry/XRegistryKey.hpp>
37 #include <com/sun/star/util/Date.hpp>
38 #include <uno/environment.h>
39 #include <cppuhelper/factory.hxx>
40 #include <unotools/configmgr.hxx>
42 #include "oemjob.hxx"
43 #include "evaluation.hxx"
45 #include <string.h>
47 using namespace rtl;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::registry;
52 using namespace ::desktop;
54 static const char* pServices[] =
56 SOEvaluation::serviceName,
57 OEMPreloadJob::serviceName,
58 NULL
61 static const char* pImplementations[] =
63 SOEvaluation::implementationName,
64 OEMPreloadJob::implementationName,
65 NULL
68 typedef Reference<XInterface>(* fProvider)(const Reference<XMultiServiceFactory>&);
70 static const fProvider pInstanceProviders[] =
72 SOEvaluation::CreateInstance,
73 OEMPreloadJob::CreateInstance,
74 NULL
78 static const char** pSupportedServices[] =
80 SOEvaluation::interfaces,
81 OEMPreloadJob::interfaces,
82 NULL
83 };
85 static Sequence<OUString>
86 getSupportedServiceNames(int p) {
87 const char **names = pSupportedServices[p];
88 Sequence<OUString> aSeq;
89 for(int i = 0; names[i] != NULL; i++) {
90 aSeq.realloc(i+1);
91 aSeq[i] = OUString::createFromAscii(names[i]);
93 return aSeq;
96 extern "C"
98 void SAL_CALL
99 component_getImplementationEnvironment(
100 const sal_Char** ppEnvironmentTypeName,
101 uno_Environment**)
103 *ppEnvironmentTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
106 sal_Bool SAL_CALL
107 component_writeInfo(
108 void* pServiceManager,
109 void* pRegistryKey)
111 Reference<XMultiServiceFactory> xMan(
112 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
113 Reference<XRegistryKey> xKey(
114 reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
116 // iterate over service names and register them...
117 OUString aImpl;
118 const char* pServiceName = NULL;
119 const char* pImplName = NULL;
120 for (int i = 0; (pServices[i]!=NULL)&&(pImplementations[i]!=NULL); i++) {
121 pServiceName= pServices[i];
122 pImplName = pImplementations[i];
123 aImpl = OUString::createFromAscii("/")
124 + OUString::createFromAscii(pImplName)
125 + OUString::createFromAscii("/UNO/SERVICES");
126 Reference<XRegistryKey> xNewKey = xKey->createKey(aImpl);
127 xNewKey->createKey(OUString::createFromAscii(pServiceName));
129 return sal_True;
132 void* SAL_CALL
133 component_getFactory(
134 const sal_Char* pImplementationName,
135 void* pServiceManager,
136 void*)
138 // Set default return value for this operation - if it failed.
139 if ( pImplementationName && pServiceManager )
141 Reference< XSingleServiceFactory > xFactory;
142 Reference< XMultiServiceFactory > xServiceManager(
143 reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
145 // search implementation
146 for (int i = 0; (pImplementations[i]!=NULL); i++) {
147 if ( strcmp(pImplementations[i], pImplementationName ) == 0 ) {
148 // found implementation
149 xFactory = Reference<XSingleServiceFactory>(cppu::createSingleFactory(
150 xServiceManager, OUString::createFromAscii(pImplementationName),
151 pInstanceProviders[i], getSupportedServiceNames(i)));
152 if ( xFactory.is() ) {
153 // Factory is valid - service was found.
154 xFactory->acquire();
155 return xFactory.get();
158 } // for()
160 // Return with result of this operation.
161 return NULL;
163 } // extern "C"