1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
28cdf0e10cSrcweir #include "com/sun/star/container/XSet.hpp"
29cdf0e10cSrcweir #include "com/sun/star/lang/XMain.hpp"
30cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp"
31cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
32cdf0e10cSrcweir #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
33cdf0e10cSrcweir #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp"
34cdf0e10cSrcweir #include "com/sun/star/reflection/XPublished.hpp"
35cdf0e10cSrcweir #include "com/sun/star/reflection/XStructTypeDescription.hpp"
36cdf0e10cSrcweir #include "com/sun/star/reflection/XTypeDescription.hpp"
37cdf0e10cSrcweir #include "com/sun/star/registry/InvalidRegistryException.hpp"
38cdf0e10cSrcweir #include "com/sun/star/registry/XRegistryKey.hpp"
39cdf0e10cSrcweir #include "com/sun/star/registry/XSimpleRegistry.hpp"
40cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
41cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
42cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
43cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
44cdf0e10cSrcweir #include "com/sun/star/uno/TypeClass.hpp"
45cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
46cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
47cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
48cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
49cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
50cdf0e10cSrcweir #include "osl/file.h"
51cdf0e10cSrcweir #include "osl/thread.h"
52cdf0e10cSrcweir #include "rtl/textenc.h"
53cdf0e10cSrcweir #include "rtl/ustring.h"
54cdf0e10cSrcweir #include "rtl/ustring.hxx"
55cdf0e10cSrcweir #include "sal/types.h"
56cdf0e10cSrcweir #include "uno/environment.h"
57cdf0e10cSrcweir #include "uno/lbnames.h"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include /*MSVC trouble: <cstdlib>*/ <stdlib.h>
60cdf0e10cSrcweir #include <iostream>
61cdf0e10cSrcweir #include <ostream>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace css = com::sun::star;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir namespace {
66cdf0e10cSrcweir 
67cdf0e10cSrcweir class Service: public cppu::WeakImplHelper1< css::lang::XMain > {
68cdf0e10cSrcweir public:
69cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL
70cdf0e10cSrcweir     run(css::uno::Sequence< rtl::OUString > const & arguments)
71cdf0e10cSrcweir         throw (css::uno::RuntimeException);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     static rtl::OUString getImplementationName();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     static css::uno::Sequence< rtl::OUString > getSupportedServiceNames();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     static css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
78cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & context)
79cdf0e10cSrcweir         throw (css::uno::Exception);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir private:
Service(css::uno::Reference<css::uno::XComponentContext> const & context)82cdf0e10cSrcweir     explicit Service(
83cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & context):
84cdf0e10cSrcweir         m_context(context)
85cdf0e10cSrcweir     {}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > m_context;
88cdf0e10cSrcweir };
89cdf0e10cSrcweir 
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir namespace {
93cdf0e10cSrcweir 
operator <<(std::ostream & out,rtl::OUString const & value)94cdf0e10cSrcweir std::ostream & operator <<(std::ostream & out, rtl::OUString const & value) {
95cdf0e10cSrcweir     return out << rtl::OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
assertTrue(bool argument)98cdf0e10cSrcweir void assertTrue(bool argument) {
99cdf0e10cSrcweir     if (!argument) {
100cdf0e10cSrcweir         std::cerr
101cdf0e10cSrcweir             << "assertTrue(" << argument << ") failed" << std::endl;
102cdf0e10cSrcweir         /*MSVC trouble: std::*/abort();
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
assertFalse(bool argument)106cdf0e10cSrcweir void assertFalse(bool argument) {
107cdf0e10cSrcweir     if (argument) {
108cdf0e10cSrcweir         std::cerr
109cdf0e10cSrcweir             << "assertFalse(" << argument << ") failed" << std::endl;
110cdf0e10cSrcweir         /*MSVC trouble: std::*/abort();
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
assertEqual(T const & value,T const & argument)114cdf0e10cSrcweir template< typename T > void assertEqual(T const & value, T const & argument) {
115cdf0e10cSrcweir     if (argument != value) {
116cdf0e10cSrcweir         std::cerr
117cdf0e10cSrcweir             << "assertEqual(" << value << ", " << argument << ") failed"
118cdf0e10cSrcweir             << std::endl;
119cdf0e10cSrcweir         /*MSVC trouble: std::*/abort();
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
run(css::uno::Sequence<rtl::OUString> const & arguments)125cdf0e10cSrcweir sal_Int32 Service::run(css::uno::Sequence< rtl::OUString > const & arguments)
126cdf0e10cSrcweir     throw (css::uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiComponentFactory > factory(
129cdf0e10cSrcweir         m_context->getServiceManager());
130cdf0e10cSrcweir     assertTrue(factory.is());
131cdf0e10cSrcweir     css::uno::Reference< css::container::XHierarchicalNameAccess > manager(
132cdf0e10cSrcweir         m_context->getValueByName(
133cdf0e10cSrcweir             rtl::OUString(
134cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
135cdf0e10cSrcweir                     "/singletons/"
136cdf0e10cSrcweir                     "com.sun.star.reflection.theTypeDescriptionManager"))),
137cdf0e10cSrcweir         css::uno::UNO_QUERY_THROW);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     ////////////////////////////////////////
140cdf0e10cSrcweir     // test: add cmd line rdbs to manager
141cdf0e10cSrcweir     ////////////////////////////////////////
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     OSL_ASSERT( arguments.getLength() > 0 );
144cdf0e10cSrcweir     css::uno::Reference<css::container::XSet> xSet(
145cdf0e10cSrcweir         manager, css::uno::UNO_QUERY_THROW );
146cdf0e10cSrcweir     for ( sal_Int32 argPos = 0; argPos < arguments.getLength(); ++argPos ) {
147cdf0e10cSrcweir         rtl::OUString url;
148cdf0e10cSrcweir         OSL_VERIFY( osl_File_E_None == osl_getFileURLFromSystemPath(
149cdf0e10cSrcweir                         arguments[argPos].pData, &url.pData ) );
150cdf0e10cSrcweir         bool supposedToBeCompatible = ! url.endsWithIgnoreAsciiCaseAsciiL(
151cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("_incomp.rdb") );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         css::uno::Reference<css::registry::XSimpleRegistry> xReg(
154cdf0e10cSrcweir             m_context->getServiceManager()->createInstanceWithContext(
155cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
156cdf0e10cSrcweir                                    "com.sun.star.registry.SimpleRegistry") ),
157cdf0e10cSrcweir                 m_context ), css::uno::UNO_QUERY_THROW );
158cdf0e10cSrcweir         xReg->open( url, true /* read-only */, false /* ! create */ );
159cdf0e10cSrcweir         css::uno::Any arg( css::uno::makeAny(xReg) );
160cdf0e10cSrcweir         css::uno::Reference<css::container::XHierarchicalNameAccess> xTDprov(
161cdf0e10cSrcweir             m_context->getServiceManager()->
162cdf0e10cSrcweir             createInstanceWithArgumentsAndContext(
163cdf0e10cSrcweir                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
164cdf0e10cSrcweir                                    "com.sun.star.comp.stoc."
165cdf0e10cSrcweir                                    "RegistryTypeDescriptionProvider") ),
166cdf0e10cSrcweir                 css::uno::Sequence<css::uno::Any>( &arg, 1 ), m_context ),
167cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW );
168cdf0e10cSrcweir         try {
169cdf0e10cSrcweir             xSet->insert( css::uno::makeAny(xTDprov) );
170cdf0e10cSrcweir             if (! supposedToBeCompatible)
171cdf0e10cSrcweir                 std::cerr << "current rdb file: " <<
172cdf0e10cSrcweir                     rtl::OUStringToOString(
173cdf0e10cSrcweir                         url, osl_getThreadTextEncoding()).getStr() << std::endl;
174cdf0e10cSrcweir             assertTrue(supposedToBeCompatible);
175cdf0e10cSrcweir         } catch (css::lang::IllegalArgumentException &) {
176cdf0e10cSrcweir             if (supposedToBeCompatible)
177cdf0e10cSrcweir                 throw;
178cdf0e10cSrcweir             assertFalse(supposedToBeCompatible);
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     ///////
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     css::uno::Reference< css::reflection::XIndirectTypeDescription > sequence(
185cdf0e10cSrcweir         manager->getByHierarchicalName(
186cdf0e10cSrcweir             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[][]boolean"))),
187cdf0e10cSrcweir         css::uno::UNO_QUERY_THROW);
188cdf0e10cSrcweir     assertEqual(css::uno::TypeClass_SEQUENCE, sequence->getTypeClass());
189cdf0e10cSrcweir     assertEqual(
190cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[][]boolean")),
191cdf0e10cSrcweir         sequence->getName());
192cdf0e10cSrcweir     assertEqual(
193cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[]boolean")),
194cdf0e10cSrcweir         sequence->getReferencedType()->getName());
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     css::uno::Reference< css::reflection::XStructTypeDescription > structure(
197cdf0e10cSrcweir         manager->getByHierarchicalName(
198cdf0e10cSrcweir             rtl::OUString(
199cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
200cdf0e10cSrcweir                     "test.tdmanager.Struct<boolean,test.tdmanager.Struct<"
201cdf0e10cSrcweir                     "any,com.sun.star.uno.XInterface>>"))),
202cdf0e10cSrcweir         css::uno::UNO_QUERY_THROW);
203cdf0e10cSrcweir     assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass());
204cdf0e10cSrcweir     assertEqual(
205cdf0e10cSrcweir         rtl::OUString(
206cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM(
207cdf0e10cSrcweir                 "test.tdmanager.Struct<boolean,test.tdmanager.Struct<"
208cdf0e10cSrcweir                 "any,com.sun.star.uno.XInterface>>")),
209cdf0e10cSrcweir         structure->getName());
210cdf0e10cSrcweir     assertEqual< bool >(false, structure->getBaseType().is());
211cdf0e10cSrcweir     assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength());
212cdf0e10cSrcweir     assertEqual(
213cdf0e10cSrcweir         rtl::OUString(
214cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM(
215cdf0e10cSrcweir                 "test.tdmanager.Struct<any,com.sun.star.uno.XInterface>")),
216cdf0e10cSrcweir         structure->getMemberTypes()[0]->getName());
217cdf0e10cSrcweir     assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength());
218cdf0e10cSrcweir     assertEqual(
219cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s")),
220cdf0e10cSrcweir         structure->getMemberNames()[0]);
221cdf0e10cSrcweir     assertEqual< sal_Int32 >(0, structure->getTypeParameters().getLength());
222cdf0e10cSrcweir     assertEqual< sal_Int32 >(2, structure->getTypeArguments().getLength());
223cdf0e10cSrcweir     assertEqual(
224cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("boolean")),
225cdf0e10cSrcweir         structure->getTypeArguments()[0]->getName());
226cdf0e10cSrcweir     assertEqual(
227cdf0e10cSrcweir         rtl::OUString(
228cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM(
229cdf0e10cSrcweir                 "test.tdmanager.Struct<any,com.sun.star.uno.XInterface>")),
230cdf0e10cSrcweir         structure->getTypeArguments()[1]->getName());
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     css::uno::Reference< css::reflection::XInterfaceMethodTypeDescription >
233cdf0e10cSrcweir         method(
234cdf0e10cSrcweir             manager->getByHierarchicalName(
235cdf0e10cSrcweir                 rtl::OUString(
236cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM(
237cdf0e10cSrcweir                         "com.sun.star.uno.XComponentContext::getValueByName"))),
238cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
239cdf0e10cSrcweir     assertEqual(css::uno::TypeClass_INTERFACE_METHOD, method->getTypeClass());
240cdf0e10cSrcweir     assertEqual(
241cdf0e10cSrcweir         rtl::OUString(
242cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM(
243cdf0e10cSrcweir                 "com.sun.star.uno.XComponentContext::getValueByName")),
244cdf0e10cSrcweir         method->getName());
245cdf0e10cSrcweir     assertEqual(
246cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getValueByName")),
247cdf0e10cSrcweir         method->getMemberName());
248cdf0e10cSrcweir     assertEqual< sal_Int32 >(3, method->getPosition());
249cdf0e10cSrcweir     assertEqual(
250cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")),
251cdf0e10cSrcweir         method->getReturnType()->getName());
252cdf0e10cSrcweir     assertEqual< bool >(false, method->isOneway());
253cdf0e10cSrcweir     assertEqual< sal_Int32 >(1, method->getParameters().getLength());
254cdf0e10cSrcweir     assertEqual(
255cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name")),
256cdf0e10cSrcweir         method->getParameters()[0]->getName());
257cdf0e10cSrcweir     assertEqual(
258cdf0e10cSrcweir         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("string")),
259cdf0e10cSrcweir         method->getParameters()[0]->getType()->getName());
260cdf0e10cSrcweir     assertEqual< bool >(true, method->getParameters()[0]->isIn());
261cdf0e10cSrcweir     assertEqual< bool >(false, method->getParameters()[0]->isOut());
262cdf0e10cSrcweir     assertEqual< sal_Int32 >(0, method->getParameters()[0]->getPosition());
263cdf0e10cSrcweir     assertEqual< sal_Int32 >(0, method->getExceptions().getLength());
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     assertFalse(
266cdf0e10cSrcweir         css::uno::Reference< css::reflection::XPublished >(
267cdf0e10cSrcweir             css::uno::Reference< css::reflection::XTypeDescription >(
268cdf0e10cSrcweir                 manager->getByHierarchicalName(
269cdf0e10cSrcweir                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[]boolean"))),
270cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW),
271cdf0e10cSrcweir             css::uno::UNO_QUERY).is());
272cdf0e10cSrcweir     assertFalse(
273cdf0e10cSrcweir         css::uno::Reference< css::reflection::XPublished >(
274cdf0e10cSrcweir             css::uno::Reference< css::reflection::XTypeDescription >(
275cdf0e10cSrcweir                 manager->getByHierarchicalName(
276cdf0e10cSrcweir                     rtl::OUString(
277cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
278cdf0e10cSrcweir                             "com.sun.star.beans.XIntroTest::ObjectName"))),
279cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW),
280cdf0e10cSrcweir             css::uno::UNO_QUERY).is());
281cdf0e10cSrcweir     assertFalse(
282cdf0e10cSrcweir         css::uno::Reference< css::reflection::XPublished >(
283cdf0e10cSrcweir             css::uno::Reference< css::reflection::XTypeDescription >(
284cdf0e10cSrcweir                 manager->getByHierarchicalName(
285cdf0e10cSrcweir                     rtl::OUString(
286cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
287cdf0e10cSrcweir                             "com.sun.star.beans.XIntroTest::writeln"))),
288cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW),
289cdf0e10cSrcweir             css::uno::UNO_QUERY).is());
290cdf0e10cSrcweir     //TODO: check that the reflection of a property of an accumulation-based
291cdf0e10cSrcweir     // service does not support XPublished
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     return 0;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
getImplementationName()296cdf0e10cSrcweir rtl::OUString Service::getImplementationName() {
297cdf0e10cSrcweir     return rtl::OUString::createFromAscii("test.tdmanager.impl");
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
getSupportedServiceNames()300cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > Service::getSupportedServiceNames() {
301cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >();
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
createInstance(css::uno::Reference<css::uno::XComponentContext> const & context)304cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > Service::createInstance(
305cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context)
306cdf0e10cSrcweir     throw (css::uno::Exception)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(new Service(context));
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
component_getImplementationEnvironment(char const ** envTypeName,uno_Environment **)311cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
312cdf0e10cSrcweir     char const ** envTypeName, uno_Environment **)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     if (envTypeName != 0) {
315cdf0e10cSrcweir         *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
component_getFactory(char const * implName,void * serviceManager,void *)319cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(char const * implName,
320cdf0e10cSrcweir                                                 void * serviceManager, void *) {
321cdf0e10cSrcweir     void * p = 0;
322cdf0e10cSrcweir     if (serviceManager != 0) {
323cdf0e10cSrcweir         css::uno::Reference< css::lang::XSingleComponentFactory > f;
324cdf0e10cSrcweir         if (Service::getImplementationName().equalsAscii(implName)) {
325cdf0e10cSrcweir             f = cppu::createSingleComponentFactory(
326cdf0e10cSrcweir                 &Service::createInstance, Service::getImplementationName(),
327cdf0e10cSrcweir                 Service::getSupportedServiceNames());
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir         if (f.is()) {
330cdf0e10cSrcweir             f->acquire();
331cdf0e10cSrcweir             p = f.get();
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir     return p;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir namespace {
338cdf0e10cSrcweir 
writeInfo(void * registryKey,rtl::OUString const & implementationName,css::uno::Sequence<rtl::OUString> const & serviceNames)339cdf0e10cSrcweir bool writeInfo(void * registryKey, rtl::OUString const & implementationName,
340cdf0e10cSrcweir                css::uno::Sequence< rtl::OUString > const & serviceNames) {
341cdf0e10cSrcweir     rtl::OUString keyName(rtl::OUString::createFromAscii("/"));
342cdf0e10cSrcweir     keyName += implementationName;
343cdf0e10cSrcweir     keyName += rtl::OUString::createFromAscii("/UNO/SERVICES");
344cdf0e10cSrcweir     css::uno::Reference< css::registry::XRegistryKey > key;
345cdf0e10cSrcweir     try {
346cdf0e10cSrcweir         key = static_cast< css::registry::XRegistryKey * >(registryKey)->
347cdf0e10cSrcweir             createKey(keyName);
348cdf0e10cSrcweir     } catch (css::registry::InvalidRegistryException &) {}
349cdf0e10cSrcweir     if (!key.is()) {
350cdf0e10cSrcweir         return false;
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir     bool success = true;
353cdf0e10cSrcweir     for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
354cdf0e10cSrcweir         try {
355cdf0e10cSrcweir             key->createKey(serviceNames[i]);
356cdf0e10cSrcweir         } catch (css::registry::InvalidRegistryException &) {
357cdf0e10cSrcweir             success = false;
358cdf0e10cSrcweir             break;
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir     return success;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
component_writeInfo(void *,void * registryKey)366cdf0e10cSrcweir extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * registryKey) {
367cdf0e10cSrcweir     return registryKey
368cdf0e10cSrcweir         && writeInfo(registryKey, Service::getImplementationName(),
369cdf0e10cSrcweir                      Service::getSupportedServiceNames());
370cdf0e10cSrcweir }
371