merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / java_uno / equals / testequals.cxx
blobad3207b4ea952f30e196c197e65f7f4c8230f290
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: testequals.cxx,v $
10 * $Revision: 1.6 $
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_bridges.hxx"
34 #include "com/sun/star/bridge/XBridge.hpp"
35 #include "com/sun/star/bridge/XBridgeFactory.hpp"
36 #include "com/sun/star/connection/Connector.hpp"
37 #include "com/sun/star/connection/XConnection.hpp"
38 #include "com/sun/star/connection/XConnector.hpp"
39 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
40 #include "com/sun/star/lang/XServiceInfo.hpp"
41 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
42 #include "com/sun/star/registry/InvalidRegistryException.hpp"
43 #include "com/sun/star/registry/XRegistryKey.hpp"
44 #include "com/sun/star/uno/Exception.hpp"
45 #include "com/sun/star/uno/Reference.hxx"
46 #include "com/sun/star/uno/RuntimeException.hpp"
47 #include "com/sun/star/uno/Sequence.hxx"
48 #include "com/sun/star/uno/XComponentContext.hpp"
49 #include "com/sun/star/uno/XInterface.hpp"
50 #include "cppuhelper/factory.hxx"
51 #include "cppuhelper/implbase2.hxx"
52 #include "cppuhelper/weak.hxx"
53 #include "rtl/string.h"
54 #include "rtl/ustring.hxx"
55 #include "sal/types.h"
56 #include "test/java_uno/equals/XBase.hpp"
57 #include "test/java_uno/equals/XDerived.hpp"
58 #include "test/java_uno/equals/XTestInterface.hpp"
59 #include "uno/environment.h"
60 #include "uno/lbnames.h"
62 namespace css = com::sun::star;
64 namespace {
66 class Service: public cppu::WeakImplHelper2<
67 css::lang::XServiceInfo, test::java_uno::equals::XTestInterface >
69 public:
70 virtual inline rtl::OUString SAL_CALL getImplementationName()
71 throw (css::uno::RuntimeException)
72 { return rtl::OUString::createFromAscii(getImplementationName_static()); }
74 virtual sal_Bool SAL_CALL supportsService(
75 rtl::OUString const & rServiceName) throw (css::uno::RuntimeException);
77 virtual inline css::uno::Sequence< rtl::OUString > SAL_CALL
78 getSupportedServiceNames() throw (css::uno::RuntimeException)
79 { return getSupportedServiceNames_static(); }
81 virtual void SAL_CALL connect(rtl::OUString const & rConnection,
82 rtl::OUString const & rProtocol)
83 throw (css::uno::Exception);
85 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL get(
86 rtl::OUString const & rName) throw (css::uno::RuntimeException);
88 static inline sal_Char const * getImplementationName_static()
89 { return "com.sun.star.test.bridges.testequals.impl"; }
91 static css::uno::Sequence< rtl::OUString >
92 getSupportedServiceNames_static();
94 static css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
95 css::uno::Reference< css::uno::XComponentContext > const & rContext)
96 throw (css::uno::Exception);
98 private:
99 explicit inline Service(
100 css::uno::Reference< css::uno::XComponentContext > const & rContext):
101 m_xContext(rContext) {}
103 css::uno::Reference< css::uno::XComponentContext > m_xContext;
104 css::uno::Reference< css::bridge::XBridge > m_xBridge;
109 sal_Bool Service::supportsService(rtl::OUString const & rServiceName)
110 throw (css::uno::RuntimeException)
112 css::uno::Sequence< rtl::OUString > aNames(
113 getSupportedServiceNames_static());
114 for (sal_Int32 i = 0; i< aNames.getLength(); ++i)
115 if (aNames[i] == rServiceName)
116 return true;
117 return false;
120 void Service::connect(rtl::OUString const & rConnection,
121 rtl::OUString const & rProtocol)
122 throw (css::uno::Exception)
124 css::uno::Reference< css::connection::XConnection > xConnection(
125 css::connection::Connector::create(m_xContext)->connect(rConnection));
126 css::uno::Reference< css::bridge::XBridgeFactory > xBridgeFactory(
127 m_xContext->getServiceManager()->createInstanceWithContext(
128 rtl::OUString::createFromAscii("com.sun.star.bridge.BridgeFactory"),
129 m_xContext),
130 css::uno::UNO_QUERY);
131 m_xBridge = xBridgeFactory->createBridge(rtl::OUString(), rProtocol,
132 xConnection, 0);
135 css::uno::Reference< css::uno::XInterface >
136 Service::get(rtl::OUString const & rName) throw (css::uno::RuntimeException)
138 return m_xBridge->getInstance(rName);
141 css::uno::Sequence< rtl::OUString > Service::getSupportedServiceNames_static()
143 css::uno::Sequence< rtl::OUString > aNames(1);
144 aNames[0] = rtl::OUString::createFromAscii(
145 "com.sun.star.test.bridges.testequals");
146 return aNames;
149 css::uno::Reference< css::uno::XInterface > Service::createInstance(
150 css::uno::Reference< css::uno::XComponentContext > const & rContext)
151 throw (css::uno::Exception)
153 // Make types known:
154 getCppuType(
155 static_cast<
156 css::uno::Reference< test::java_uno::equals::XBase > const * >(0));
157 getCppuType(
158 static_cast<
159 css::uno::Reference< test::java_uno::equals::XDerived > const * >(0));
160 getCppuType(
161 static_cast<
162 css::uno::Reference< test::java_uno::equals::XTestInterface > const * >(
163 0));
165 return static_cast< cppu::OWeakObject * >(new Service(rContext));
168 extern "C" void SAL_CALL component_getImplementationEnvironment(
169 sal_Char const ** pEnvTypeName, uno_Environment **)
171 *pEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
174 extern "C" void * SAL_CALL component_getFactory(sal_Char const * pImplName,
175 void * pServiceManager, void *)
177 void * pFactory = 0;
178 if (pServiceManager)
179 if (rtl_str_compare(pImplName, Service::getImplementationName_static())
180 == 0)
182 css::uno::Reference< css::lang::XSingleComponentFactory >
183 xFactory(cppu::createSingleComponentFactory(
184 &Service::createInstance,
185 rtl::OUString::createFromAscii(
186 Service::getImplementationName_static()),
187 Service::getSupportedServiceNames_static()));
188 if (xFactory.is())
190 xFactory->acquire();
191 pFactory = xFactory.get();
194 return pFactory;
197 namespace {
199 bool writeInfo(void * pRegistryKey, sal_Char const * pImplementationName,
200 css::uno::Sequence< rtl::OUString > const & rServiceNames)
202 rtl::OUString aKeyName(rtl::OUString::createFromAscii("/"));
203 aKeyName += rtl::OUString::createFromAscii(pImplementationName);
204 aKeyName += rtl::OUString::createFromAscii("/UNO/SERVICES");
205 css::uno::Reference< css::registry::XRegistryKey > xKey;
208 xKey = static_cast< css::registry::XRegistryKey * >(pRegistryKey)->
209 createKey(aKeyName);
211 catch (css::registry::InvalidRegistryException &) {}
212 if (!xKey.is())
213 return false;
214 bool bSuccess = true;
215 for (sal_Int32 i = 0; i < rServiceNames.getLength(); ++i)
218 xKey->createKey(rServiceNames[i]);
220 catch (css::registry::InvalidRegistryException &)
222 bSuccess = false;
223 break;
225 return bSuccess;
230 extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * pRegistryKey)
232 return pRegistryKey
233 && writeInfo(pRegistryKey, Service::getImplementationName_static(),
234 Service::getSupportedServiceNames_static());