1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: services.cxx,v $
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>
43 #include "evaluation.hxx"
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
,
61 static const char* pImplementations
[] =
63 SOEvaluation::implementationName
,
64 OEMPreloadJob::implementationName
,
68 typedef Reference
<XInterface
>(* fProvider
)(const Reference
<XMultiServiceFactory
>&);
70 static const fProvider pInstanceProviders
[] =
72 SOEvaluation::CreateInstance
,
73 OEMPreloadJob::CreateInstance
,
78 static const char** pSupportedServices
[] =
80 SOEvaluation::interfaces
,
81 OEMPreloadJob::interfaces
,
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
++) {
91 aSeq
[i
] = OUString::createFromAscii(names
[i
]);
99 component_getImplementationEnvironment(
100 const sal_Char
** ppEnvironmentTypeName
,
103 *ppEnvironmentTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
108 void* pServiceManager
,
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...
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
));
133 component_getFactory(
134 const sal_Char
* pImplementationName
,
135 void* pServiceManager
,
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.
155 return xFactory
.get();
160 // Return with result of this operation.