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: 51 Service() {} 52 53 virtual void SAL_CALL throwException() 54 throw (test::types::TestException, css::uno::RuntimeException) 55 { 56 throw test::types::TestException( 57 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")), 58 static_cast< cppu::OWeakObject * >(this)); 59 } 60 61 private: 62 Service(Service &); // not defined 63 void operator =(Service &); // not defined 64 65 virtual ~Service() {} 66 }; 67 68 namespace CppTest { 69 70 css::uno::Reference< css::uno::XInterface > create( 71 css::uno::Reference< css::uno::XComponentContext > const &) 72 SAL_THROW((css::uno::Exception)) 73 { 74 try { 75 return static_cast< cppu::OWeakObject * >(new Service); 76 } catch (std::bad_alloc &) { 77 throw css::uno::RuntimeException( 78 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), 79 css::uno::Reference< css::uno::XInterface >()); 80 } 81 } 82 83 rtl::OUString getImplementationName() { 84 return rtl::OUString( 85 RTL_CONSTASCII_USTRINGPARAM("test.cpp.cpptest.Component")); 86 } 87 88 css::uno::Sequence< rtl::OUString > getSupportedServiceNames() { 89 rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("test.types.CppTest")); 90 return css::uno::Sequence< rtl::OUString >(&s, 1); 91 } 92 93 } 94 95 cppu::ImplementationEntry entries[] = { 96 { CppTest::create, CppTest::getImplementationName, 97 CppTest::getSupportedServiceNames, cppu::createSingleComponentFactory, 0, 98 0 }, 99 { 0, 0, 0, 0, 0, 0 } }; 100 101 } 102 103 extern "C" sal_Bool SAL_CALL component_writeInfo( 104 void * serviceManager, void * registryKey) 105 { 106 return cppu::component_writeInfoHelper( 107 serviceManager, registryKey, entries); 108 } 109 110 extern "C" void * SAL_CALL component_getFactory( 111 char const * implName, void * serviceManager, void * registryKey) 112 { 113 return cppu::component_getFactoryHelper( 114 implName, serviceManager, registryKey, entries); 115 } 116 117 extern "C" void SAL_CALL component_getImplementationEnvironment( 118 char const ** envTypeName, uno_Environment **) 119 { 120 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 121 } 122