1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_bridges.hxx"
30 
31 #include "test/javauno/nativethreadpool/XSource.hpp"
32 
33 #include "com/sun/star/bridge/UnoUrlResolver.hpp"
34 #include "com/sun/star/bridge/XUnoUrlResolver.hpp"
35 #include "com/sun/star/connection/ConnectionSetupException.hpp"
36 #include "com/sun/star/connection/NoConnectException.hpp"
37 #include "com/sun/star/lang/IllegalArgumentException.hpp"
38 #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
39 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
40 #include "com/sun/star/uno/Exception.hpp"
41 #include "com/sun/star/uno/Reference.hxx"
42 #include "com/sun/star/uno/RuntimeException.hpp"
43 #include "com/sun/star/uno/Sequence.hxx"
44 #include "com/sun/star/uno/XComponentContext.hpp"
45 #include "com/sun/star/uno/XInterface.hpp"
46 #include "cppuhelper/factory.hxx"
47 #include "cppuhelper/implbase1.hxx"
48 #include "cppuhelper/implementationentry.hxx"
49 #include "cppuhelper/weak.hxx"
50 #include "rtl/ustring.hxx"
51 #include "sal/types.h"
52 #include "uno/lbnames.h"
53 
54 namespace css = com::sun::star;
55 
56 namespace {
57 
58 class Server:
59     public cppu::WeakImplHelper1< test::javauno::nativethreadpool::XSource >
60 {
61 public:
62     explicit Server(
63         css::uno::Reference< css::uno::XComponentContext > const & theContext):
64         context(theContext) {}
65 
66 private:
67     virtual ~Server() {}
68 
69     virtual sal_Int32 SAL_CALL get() throw (css::uno::RuntimeException);
70 
71     css::uno::Reference< css::uno::XComponentContext > context;
72 };
73 
74 sal_Int32 Server::get() throw (css::uno::RuntimeException) {
75     css::uno::Reference< css::lang::XMultiComponentFactory > factory(
76         context->getServiceManager());
77     if (!factory.is()) {
78         throw new css::uno::RuntimeException(
79             rtl::OUString::createFromAscii(
80                 "no component context service manager"),
81             static_cast< cppu::OWeakObject * >(this));
82     }
83     css::uno::Reference< test::javauno::nativethreadpool::XSource > source;
84     try {
85         // Use "127.0.0.1" instead of "localhost", see #i32281#:
86         source
87             = css::uno::Reference< test::javauno::nativethreadpool::XSource >(
88                 css::bridge::UnoUrlResolver::create(context)->resolve(
89                     rtl::OUString::createFromAscii(
90                         "uno:socket,host=127.0.0.1,port=3831;urp;test")),
91                 css::uno::UNO_QUERY_THROW);
92     } catch (css::connection::NoConnectException & e) {
93         throw css::lang::WrappedTargetRuntimeException(
94             rtl::OUString::createFromAscii(
95                 "com.sun.star.uno.UnoUrlResolver.resolve"),
96             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
97     } catch (css::connection::ConnectionSetupException & e) {
98         throw css::lang::WrappedTargetRuntimeException(
99             rtl::OUString::createFromAscii(
100                 "com.sun.star.uno.UnoUrlResolver.resolve"),
101             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
102     } catch (css::lang::IllegalArgumentException & e) {
103         throw css::lang::WrappedTargetRuntimeException(
104             rtl::OUString::createFromAscii(
105                 "com.sun.star.uno.UnoUrlResolver.resolve"),
106             static_cast< cppu::OWeakObject * >(this), css::uno::makeAny(e));
107     }
108     return source->get();
109 }
110 
111 css::uno::Reference< css::uno::XInterface > SAL_CALL create(
112     css::uno::Reference< css::uno::XComponentContext > const & context)
113     SAL_THROW((css::uno::Exception))
114 {
115     return static_cast< cppu::OWeakObject * >(new Server(context));
116 }
117 
118 rtl::OUString SAL_CALL getImplementationName() {
119     return rtl::OUString::createFromAscii(
120         "test.javauno.nativethreadpool.server");
121 }
122 
123 css::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() {
124     return css::uno::Sequence< rtl::OUString >();
125 }
126 
127 cppu::ImplementationEntry entries[] = {
128     { &create, &getImplementationName, &getSupportedServiceNames,
129       &cppu::createSingleComponentFactory, 0, 0 },
130     { 0, 0, 0, 0, 0, 0 }
131 };
132 
133 }
134 
135 extern "C" void * SAL_CALL component_getFactory(
136     char const * implName, void * serviceManager, void * registryKey)
137 {
138     return cppu::component_getFactoryHelper(
139         implName, serviceManager, registryKey, entries);
140 }
141 
142 extern "C" void SAL_CALL component_getImplementationEnvironment(
143     char const ** envTypeName, uno_Environment **)
144 {
145     *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
146 }
147