1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 32*cdf0e10cSrcweir #include "osl/diagnose.h" 33*cdf0e10cSrcweir #include "rtl/string.hxx" 34*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 35*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 36*cdf0e10cSrcweir #include "comphelper/sequence.hxx" 37*cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp" 38*cdf0e10cSrcweir #include <vector> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using namespace com::sun::star; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace comphelper { 43*cdf0e10cSrcweir namespace service_decl { 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir class ServiceDecl::Factory : 46*cdf0e10cSrcweir public cppu::WeakImplHelper2<lang::XSingleComponentFactory, 47*cdf0e10cSrcweir lang::XServiceInfo>, 48*cdf0e10cSrcweir private boost::noncopyable 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir explicit Factory( ServiceDecl const& rServiceDecl ) 52*cdf0e10cSrcweir : m_rServiceDecl(rServiceDecl) {} 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // XServiceInfo: 55*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 56*cdf0e10cSrcweir throw (uno::RuntimeException); 57*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( rtl::OUString const& name ) 58*cdf0e10cSrcweir throw (uno::RuntimeException); 59*cdf0e10cSrcweir virtual uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames() 60*cdf0e10cSrcweir throw (uno::RuntimeException); 61*cdf0e10cSrcweir // XSingleComponentFactory: 62*cdf0e10cSrcweir virtual uno::Reference<uno::XInterface> SAL_CALL createInstanceWithContext( 63*cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 64*cdf0e10cSrcweir throw (uno::Exception); 65*cdf0e10cSrcweir virtual uno::Reference<uno::XInterface> SAL_CALL 66*cdf0e10cSrcweir createInstanceWithArgumentsAndContext( 67*cdf0e10cSrcweir uno::Sequence<uno::Any> const& args, 68*cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 69*cdf0e10cSrcweir throw (uno::Exception); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir private: 72*cdf0e10cSrcweir virtual ~Factory(); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir ServiceDecl const& m_rServiceDecl; 75*cdf0e10cSrcweir }; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir ServiceDecl::Factory::~Factory() 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // XServiceInfo: 82*cdf0e10cSrcweir rtl::OUString ServiceDecl::Factory::getImplementationName() 83*cdf0e10cSrcweir throw (uno::RuntimeException) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir return m_rServiceDecl.getImplementationName(); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir sal_Bool ServiceDecl::Factory::supportsService( rtl::OUString const& name ) 89*cdf0e10cSrcweir throw (uno::RuntimeException) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir return m_rServiceDecl.supportsService(name); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir uno::Sequence<rtl::OUString> ServiceDecl::Factory::getSupportedServiceNames() 95*cdf0e10cSrcweir throw (uno::RuntimeException) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir return m_rServiceDecl.getSupportedServiceNames(); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // XSingleComponentFactory: 101*cdf0e10cSrcweir uno::Reference<uno::XInterface> ServiceDecl::Factory::createInstanceWithContext( 102*cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 103*cdf0e10cSrcweir throw (uno::Exception) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir return m_rServiceDecl.m_createFunc( 106*cdf0e10cSrcweir m_rServiceDecl, uno::Sequence<uno::Any>(), xContext ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir uno::Reference<uno::XInterface> 110*cdf0e10cSrcweir ServiceDecl::Factory::createInstanceWithArgumentsAndContext( 111*cdf0e10cSrcweir uno::Sequence<uno::Any > const& args, 112*cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 113*cdf0e10cSrcweir throw (uno::Exception) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return m_rServiceDecl.m_createFunc( 116*cdf0e10cSrcweir m_rServiceDecl, args, xContext ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void * ServiceDecl::getFactory( sal_Char const* pImplName ) const 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if (rtl_str_compare(m_pImplName, pImplName) == 0) { 122*cdf0e10cSrcweir lang::XSingleComponentFactory * const pFac( new Factory(*this) ); 123*cdf0e10cSrcweir pFac->acquire(); 124*cdf0e10cSrcweir return pFac; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir return 0; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir uno::Sequence<rtl::OUString> ServiceDecl::getSupportedServiceNames() const 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir std::vector<rtl::OUString> vec; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir rtl::OString const str(m_pServiceNames); 134*cdf0e10cSrcweir sal_Int32 nIndex = 0; 135*cdf0e10cSrcweir do { 136*cdf0e10cSrcweir rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) ); 137*cdf0e10cSrcweir vec.push_back( rtl::OUString( token.getStr(), token.getLength(), 138*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir while (nIndex >= 0); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir return comphelper::containerToSequence(vec); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir bool ServiceDecl::supportsService( ::rtl::OUString const& name ) const 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir rtl::OString const str(m_pServiceNames); 148*cdf0e10cSrcweir sal_Int32 nIndex = 0; 149*cdf0e10cSrcweir do { 150*cdf0e10cSrcweir rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) ); 151*cdf0e10cSrcweir if (name.equalsAsciiL( token.getStr(), token.getLength() )) 152*cdf0e10cSrcweir return true; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir while (nIndex >= 0); 155*cdf0e10cSrcweir return false; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir rtl::OUString ServiceDecl::getImplementationName() const 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir return rtl::OUString::createFromAscii(m_pImplName); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir } // namespace service_decl 164*cdf0e10cSrcweir } // namespace comphelper 165*cdf0e10cSrcweir 166