Update ooo320-m1
[ooovba.git] / bridges / test / java_uno / nativethreadpool / testnativethreadpoolserver.cxx
blobd2402492ce1d872eb8ac5595563b85fdf519c07d
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: testnativethreadpoolserver.cxx,v $
10 * $Revision: 1.7 $
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 "test/javauno/nativethreadpool/XSource.hpp"
36 #include "com/sun/star/bridge/UnoUrlResolver.hpp"
37 #include "com/sun/star/bridge/XUnoUrlResolver.hpp"
38 #include "com/sun/star/connection/ConnectionSetupException.hpp"
39 #include "com/sun/star/connection/NoConnectException.hpp"
40 #include "com/sun/star/lang/IllegalArgumentException.hpp"
41 #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
42 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
43 #include "com/sun/star/uno/Exception.hpp"
44 #include "com/sun/star/uno/Reference.hxx"
45 #include "com/sun/star/uno/RuntimeException.hpp"
46 #include "com/sun/star/uno/Sequence.hxx"
47 #include "com/sun/star/uno/XComponentContext.hpp"
48 #include "com/sun/star/uno/XInterface.hpp"
49 #include "cppuhelper/factory.hxx"
50 #include "cppuhelper/implbase1.hxx"
51 #include "cppuhelper/implementationentry.hxx"
52 #include "cppuhelper/weak.hxx"
53 #include "rtl/ustring.hxx"
54 #include "sal/types.h"
55 #include "uno/lbnames.h"
57 namespace css = com::sun::star;
59 namespace {
61 class Server:
62 public cppu::WeakImplHelper1< test::javauno::nativethreadpool::XSource >
64 public:
65 explicit Server(
66 css::uno::Reference< css::uno::XComponentContext > const & theContext):
67 context(theContext) {}
69 private:
70 virtual ~Server() {}
72 virtual sal_Int64 SAL_CALL get() throw (css::uno::RuntimeException);
74 css::uno::Reference< css::uno::XComponentContext > context;
77 sal_Int64 Server::get() throw (css::uno::RuntimeException) {
78 css::uno::Reference< css::lang::XMultiComponentFactory > factory(
79 context->getServiceManager());
80 if (!factory.is()) {
81 throw new css::uno::RuntimeException(
82 rtl::OUString::createFromAscii(
83 "no component context service manager"),
84 static_cast< cppu::OWeakObject * >(this));
86 css::uno::Reference< test::javauno::nativethreadpool::XSource > source;
87 try {
88 // Use "127.0.0.1" instead of "localhost", see #i32281#:
89 source
90 = css::uno::Reference< test::javauno::nativethreadpool::XSource >(
91 css::bridge::UnoUrlResolver::create(context)->resolve(
92 rtl::OUString::createFromAscii(
93 "uno:socket,host=127.0.0.1,port=3831;urp;test")),
94 css::uno::UNO_QUERY_THROW);
95 } catch (css::connection::NoConnectException & e) {
96 throw css::lang::WrappedTargetRuntimeException(
97 rtl::OUString::createFromAscii(
98 "com.sun.star.uno.UnoUrlResolver.resolve"),
99 static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
100 } catch (css::connection::ConnectionSetupException & e) {
101 throw css::lang::WrappedTargetRuntimeException(
102 rtl::OUString::createFromAscii(
103 "com.sun.star.uno.UnoUrlResolver.resolve"),
104 static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
105 } catch (css::lang::IllegalArgumentException & e) {
106 throw css::lang::WrappedTargetRuntimeException(
107 rtl::OUString::createFromAscii(
108 "com.sun.star.uno.UnoUrlResolver.resolve"),
109 static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
111 return source->get();
114 css::uno::Reference< css::uno::XInterface > SAL_CALL create(
115 css::uno::Reference< css::uno::XComponentContext > const & context)
116 SAL_THROW((css::uno::Exception))
118 return static_cast< cppu::OWeakObject * >(new Server(context));
121 rtl::OUString SAL_CALL getImplementationName() {
122 return rtl::OUString::createFromAscii(
123 "test.javauno.nativethreadpool.server");
126 css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() {
127 return css::uno::Sequence< rtl::OUString >();
130 cppu::ImplementationEntry entries[] = {
131 { &create, &getImplementationName, &getSupportedServiceNames,
132 &cppu::createSingleComponentFactory, 0, 0 },
133 { 0, 0, 0, 0, 0, 0 }
138 extern "C" void * SAL_CALL component_getFactory(
139 char const * implName, void * serviceManager, void * registryKey)
141 return cppu::component_getFactoryHelper(
142 implName, serviceManager, registryKey, entries);
145 extern "C" void SAL_CALL component_getImplementationEnvironment(
146 char const ** envTypeName, uno_Environment **)
148 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;