1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 28cdf0e10cSrcweir #include "osl/diagnose.h" 29cdf0e10cSrcweir #include "rtl/string.hxx" 30cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 31cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 32cdf0e10cSrcweir #include "comphelper/sequence.hxx" 33cdf0e10cSrcweir #include "com/sun/star/lang/XSingleComponentFactory.hpp" 34cdf0e10cSrcweir #include <vector> 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace com::sun::star; 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace comphelper { 39cdf0e10cSrcweir namespace service_decl { 40cdf0e10cSrcweir 41cdf0e10cSrcweir class ServiceDecl::Factory : 42cdf0e10cSrcweir public cppu::WeakImplHelper2<lang::XSingleComponentFactory, 43cdf0e10cSrcweir lang::XServiceInfo>, 44cdf0e10cSrcweir private boost::noncopyable 45cdf0e10cSrcweir { 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir explicit Factory( ServiceDecl const& rServiceDecl ) 48cdf0e10cSrcweir : m_rServiceDecl(rServiceDecl) {} 49cdf0e10cSrcweir 50cdf0e10cSrcweir // XServiceInfo: 51cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 52cdf0e10cSrcweir throw (uno::RuntimeException); 53cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( rtl::OUString const& name ) 54cdf0e10cSrcweir throw (uno::RuntimeException); 55cdf0e10cSrcweir virtual uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames() 56cdf0e10cSrcweir throw (uno::RuntimeException); 57cdf0e10cSrcweir // XSingleComponentFactory: 58cdf0e10cSrcweir virtual uno::Reference<uno::XInterface> SAL_CALL createInstanceWithContext( 59cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 60cdf0e10cSrcweir throw (uno::Exception); 61cdf0e10cSrcweir virtual uno::Reference<uno::XInterface> SAL_CALL 62cdf0e10cSrcweir createInstanceWithArgumentsAndContext( 63cdf0e10cSrcweir uno::Sequence<uno::Any> const& args, 64cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 65cdf0e10cSrcweir throw (uno::Exception); 66cdf0e10cSrcweir 67cdf0e10cSrcweir private: 68cdf0e10cSrcweir virtual ~Factory(); 69cdf0e10cSrcweir 70cdf0e10cSrcweir ServiceDecl const& m_rServiceDecl; 71cdf0e10cSrcweir }; 72cdf0e10cSrcweir 73cdf0e10cSrcweir ServiceDecl::Factory::~Factory() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // XServiceInfo: 78cdf0e10cSrcweir rtl::OUString ServiceDecl::Factory::getImplementationName() 79cdf0e10cSrcweir throw (uno::RuntimeException) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir return m_rServiceDecl.getImplementationName(); 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir sal_Bool ServiceDecl::Factory::supportsService( rtl::OUString const& name ) 85cdf0e10cSrcweir throw (uno::RuntimeException) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return m_rServiceDecl.supportsService(name); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir uno::Sequence<rtl::OUString> ServiceDecl::Factory::getSupportedServiceNames() 91cdf0e10cSrcweir throw (uno::RuntimeException) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir return m_rServiceDecl.getSupportedServiceNames(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // XSingleComponentFactory: 97cdf0e10cSrcweir uno::Reference<uno::XInterface> ServiceDecl::Factory::createInstanceWithContext( 98cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 99cdf0e10cSrcweir throw (uno::Exception) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir return m_rServiceDecl.m_createFunc( 102cdf0e10cSrcweir m_rServiceDecl, uno::Sequence<uno::Any>(), xContext ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir uno::Reference<uno::XInterface> 106cdf0e10cSrcweir ServiceDecl::Factory::createInstanceWithArgumentsAndContext( 107cdf0e10cSrcweir uno::Sequence<uno::Any > const& args, 108cdf0e10cSrcweir uno::Reference<uno::XComponentContext> const& xContext ) 109cdf0e10cSrcweir throw (uno::Exception) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir return m_rServiceDecl.m_createFunc( 112cdf0e10cSrcweir m_rServiceDecl, args, xContext ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir void * ServiceDecl::getFactory( sal_Char const* pImplName ) const 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if (rtl_str_compare(m_pImplName, pImplName) == 0) { 118cdf0e10cSrcweir lang::XSingleComponentFactory * const pFac( new Factory(*this) ); 119cdf0e10cSrcweir pFac->acquire(); 120cdf0e10cSrcweir return pFac; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir return 0; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir uno::Sequence<rtl::OUString> ServiceDecl::getSupportedServiceNames() const 126cdf0e10cSrcweir { 127cdf0e10cSrcweir std::vector<rtl::OUString> vec; 128cdf0e10cSrcweir 129cdf0e10cSrcweir rtl::OString const str(m_pServiceNames); 130cdf0e10cSrcweir sal_Int32 nIndex = 0; 131cdf0e10cSrcweir do { 132cdf0e10cSrcweir rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) ); 133cdf0e10cSrcweir vec.push_back( rtl::OUString( token.getStr(), token.getLength(), 134cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir while (nIndex >= 0); 137cdf0e10cSrcweir 138cdf0e10cSrcweir return comphelper::containerToSequence(vec); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir bool ServiceDecl::supportsService( ::rtl::OUString const& name ) const 142cdf0e10cSrcweir { 143cdf0e10cSrcweir rtl::OString const str(m_pServiceNames); 144cdf0e10cSrcweir sal_Int32 nIndex = 0; 145cdf0e10cSrcweir do { 146cdf0e10cSrcweir rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) ); 147cdf0e10cSrcweir if (name.equalsAsciiL( token.getStr(), token.getLength() )) 148cdf0e10cSrcweir return true; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir while (nIndex >= 0); 151cdf0e10cSrcweir return false; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir rtl::OUString ServiceDecl::getImplementationName() const 155cdf0e10cSrcweir { 156cdf0e10cSrcweir return rtl::OUString::createFromAscii(m_pImplName); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir } // namespace service_decl 160cdf0e10cSrcweir } // namespace comphelper 161cdf0e10cSrcweir 162