1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <comphelper/servicedecl.hxx>
22 #include <osl/diagnose.h>
23 #include <rtl/string.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <cppuhelper/implbase2.hxx>
26 #include <comphelper/sequence.hxx>
27 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
30 using namespace com::sun::star
;
32 namespace comphelper
{
33 namespace service_decl
{
35 class ServiceDecl::Factory
:
36 public cppu::WeakImplHelper2
<lang::XSingleComponentFactory
,
38 private boost::noncopyable
41 explicit Factory( ServiceDecl
const& rServiceDecl
)
42 : m_rServiceDecl(rServiceDecl
) {}
45 virtual OUString SAL_CALL
getImplementationName()
46 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
47 virtual sal_Bool SAL_CALL
supportsService( OUString
const& name
)
48 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
49 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames()
50 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
51 // XSingleComponentFactory:
52 virtual uno::Reference
<uno::XInterface
> SAL_CALL
createInstanceWithContext(
53 uno::Reference
<uno::XComponentContext
> const& xContext
)
54 throw (uno::Exception
, std::exception
) SAL_OVERRIDE
;
55 virtual uno::Reference
<uno::XInterface
> SAL_CALL
56 createInstanceWithArgumentsAndContext(
57 uno::Sequence
<uno::Any
> const& args
,
58 uno::Reference
<uno::XComponentContext
> const& xContext
)
59 throw (uno::Exception
, std::exception
) SAL_OVERRIDE
;
64 ServiceDecl
const& m_rServiceDecl
;
67 ServiceDecl::Factory::~Factory()
72 OUString
ServiceDecl::Factory::getImplementationName()
73 throw (uno::RuntimeException
, std::exception
)
75 return m_rServiceDecl
.getImplementationName();
78 sal_Bool
ServiceDecl::Factory::supportsService( OUString
const& name
)
79 throw (uno::RuntimeException
, std::exception
)
81 return m_rServiceDecl
.supportsService(name
);
84 uno::Sequence
<OUString
> ServiceDecl::Factory::getSupportedServiceNames()
85 throw (uno::RuntimeException
, std::exception
)
87 return m_rServiceDecl
.getSupportedServiceNames();
90 // XSingleComponentFactory:
91 uno::Reference
<uno::XInterface
> ServiceDecl::Factory::createInstanceWithContext(
92 uno::Reference
<uno::XComponentContext
> const& xContext
)
93 throw (uno::Exception
, std::exception
)
95 return m_rServiceDecl
.m_createFunc(
96 m_rServiceDecl
, uno::Sequence
<uno::Any
>(), xContext
);
99 uno::Reference
<uno::XInterface
>
100 ServiceDecl::Factory::createInstanceWithArgumentsAndContext(
101 uno::Sequence
<uno::Any
> const& args
,
102 uno::Reference
<uno::XComponentContext
> const& xContext
)
103 throw (uno::Exception
, std::exception
)
105 return m_rServiceDecl
.m_createFunc(
106 m_rServiceDecl
, args
, xContext
);
109 void * ServiceDecl::getFactory( sal_Char
const* pImplName
) const
111 if (rtl_str_compare(m_pImplName
, pImplName
) == 0) {
112 lang::XSingleComponentFactory
* const pFac( new Factory(*this) );
119 uno::Sequence
<OUString
> ServiceDecl::getSupportedServiceNames() const
121 std::vector
<OUString
> vec
;
123 OString
const str(m_pServiceNames
);
124 sal_Int32 nIndex
= 0;
126 OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
127 vec
.push_back( OUString( token
.getStr(), token
.getLength(),
128 RTL_TEXTENCODING_ASCII_US
) );
132 return comphelper::containerToSequence(vec
);
135 bool ServiceDecl::supportsService( OUString
const& name
) const
137 OString
const str(m_pServiceNames
);
138 sal_Int32 nIndex
= 0;
140 OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
141 if (name
.equalsAsciiL( token
.getStr(), token
.getLength() ))
148 OUString
ServiceDecl::getImplementationName() const
150 return OUString::createFromAscii(m_pImplName
);
153 } // namespace service_decl
154 } // namespace comphelper
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */