1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "sal/config.h"
25
26 #include "com/sun/star/uno/Exception.hpp"
27 #include "com/sun/star/uno/Reference.hxx"
28 #include "com/sun/star/uno/RuntimeException.hpp"
29 #include "com/sun/star/uno/Sequence.hxx"
30 #include "com/sun/star/uno/XComponentContext.hpp"
31 #include "com/sun/star/uno/XInterface.hpp"
32 #include "cppuhelper/factory.hxx"
33 #include "cppuhelper/implbase1.hxx"
34 #include "cppuhelper/implementationentry.hxx"
35 #include "cppuhelper/weak.hxx"
36 #include "rtl/ustring.h"
37 #include "rtl/ustring.hxx"
38 #include "sal/types.h"
39 #include "uno/environment.h"
40 #include "uno/lbnames.h"
41
42 #include "test/types/TestException.hpp"
43 #include "test/types/XTest.hpp"
44
45 namespace css = com::sun::star;
46
47 namespace {
48
49 class Service: public cppu::WeakImplHelper1< test::types::XTest > {
50 public:
Service()51 Service() {}
52
throwException()53 virtual void SAL_CALL throwException()
54 {
55 throw test::types::TestException(
56 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")),
57 static_cast< cppu::OWeakObject * >(this));
58 }
59
60 private:
61 Service(Service &); // not defined
62 void operator =(Service &); // not defined
63
~Service()64 virtual ~Service() {}
65 };
66
67 namespace CppTest {
68
create(css::uno::Reference<css::uno::XComponentContext> const &)69 css::uno::Reference< css::uno::XInterface > create(
70 css::uno::Reference< css::uno::XComponentContext > const &)
71 {
72 try {
73 return static_cast< cppu::OWeakObject * >(new Service);
74 } catch (std::bad_alloc &) {
75 throw css::uno::RuntimeException(
76 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")),
77 css::uno::Reference< css::uno::XInterface >());
78 }
79 }
80
getImplementationName()81 rtl::OUString getImplementationName() {
82 return rtl::OUString(
83 RTL_CONSTASCII_USTRINGPARAM("test.cpp.cpptest.Component"));
84 }
85
getSupportedServiceNames()86 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
87 rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("test.types.CppTest"));
88 return css::uno::Sequence< rtl::OUString >(&s, 1);
89 }
90
91 }
92
93 cppu::ImplementationEntry entries[] = {
94 { CppTest::create, CppTest::getImplementationName,
95 CppTest::getSupportedServiceNames, cppu::createSingleComponentFactory, 0,
96 0 },
97 { 0, 0, 0, 0, 0, 0 } };
98
99 }
100
component_writeInfo(void * serviceManager,void * registryKey)101 extern "C" sal_Bool SAL_CALL component_writeInfo(
102 void * serviceManager, void * registryKey)
103 {
104 return cppu::component_writeInfoHelper(
105 serviceManager, registryKey, entries);
106 }
107
component_getFactory(char const * implName,void * serviceManager,void * registryKey)108 extern "C" void * SAL_CALL component_getFactory(
109 char const * implName, void * serviceManager, void * registryKey)
110 {
111 return cppu::component_getFactoryHelper(
112 implName, serviceManager, registryKey, entries);
113 }
114
component_getImplementationEnvironment(char const ** envTypeName,uno_Environment **)115 extern "C" void SAL_CALL component_getImplementationEnvironment(
116 char const ** envTypeName, uno_Environment **)
117 {
118 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
119 }
120