1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include "comphelper/servicedecl.hxx"
32 #include "osl/diagnose.h"
33 #include "rtl/string.hxx"
34 #include "rtl/ustrbuf.hxx"
35 #include "cppuhelper/implbase2.hxx"
36 #include "comphelper/sequence.hxx"
37 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
40 using namespace com::sun::star
;
42 namespace comphelper
{
43 namespace service_decl
{
45 class ServiceDecl::Factory
:
46 public cppu::WeakImplHelper2
<lang::XSingleComponentFactory
,
48 private boost::noncopyable
51 explicit Factory( ServiceDecl
const& rServiceDecl
)
52 : m_rServiceDecl(rServiceDecl
) {}
55 virtual rtl::OUString SAL_CALL
getImplementationName()
56 throw (uno::RuntimeException
);
57 virtual sal_Bool SAL_CALL
supportsService( rtl::OUString
const& name
)
58 throw (uno::RuntimeException
);
59 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
getSupportedServiceNames()
60 throw (uno::RuntimeException
);
61 // XSingleComponentFactory:
62 virtual uno::Reference
<uno::XInterface
> SAL_CALL
createInstanceWithContext(
63 uno::Reference
<uno::XComponentContext
> const& xContext
)
64 throw (uno::Exception
);
65 virtual uno::Reference
<uno::XInterface
> SAL_CALL
66 createInstanceWithArgumentsAndContext(
67 uno::Sequence
<uno::Any
> const& args
,
68 uno::Reference
<uno::XComponentContext
> const& xContext
)
69 throw (uno::Exception
);
74 ServiceDecl
const& m_rServiceDecl
;
77 ServiceDecl::Factory::~Factory()
82 rtl::OUString
ServiceDecl::Factory::getImplementationName()
83 throw (uno::RuntimeException
)
85 return m_rServiceDecl
.getImplementationName();
88 sal_Bool
ServiceDecl::Factory::supportsService( rtl::OUString
const& name
)
89 throw (uno::RuntimeException
)
91 return m_rServiceDecl
.supportsService(name
);
94 uno::Sequence
<rtl::OUString
> ServiceDecl::Factory::getSupportedServiceNames()
95 throw (uno::RuntimeException
)
97 return m_rServiceDecl
.getSupportedServiceNames();
100 // XSingleComponentFactory:
101 uno::Reference
<uno::XInterface
> ServiceDecl::Factory::createInstanceWithContext(
102 uno::Reference
<uno::XComponentContext
> const& xContext
)
103 throw (uno::Exception
)
105 return m_rServiceDecl
.m_createFunc(
106 m_rServiceDecl
, uno::Sequence
<uno::Any
>(), xContext
);
109 uno::Reference
<uno::XInterface
>
110 ServiceDecl::Factory::createInstanceWithArgumentsAndContext(
111 uno::Sequence
<uno::Any
> const& args
,
112 uno::Reference
<uno::XComponentContext
> const& xContext
)
113 throw (uno::Exception
)
115 return m_rServiceDecl
.m_createFunc(
116 m_rServiceDecl
, args
, xContext
);
119 void * ServiceDecl::getFactory( sal_Char
const* pImplName
) const
121 if (rtl_str_compare(m_pImplName
, pImplName
) == 0) {
122 lang::XSingleComponentFactory
* const pFac( new Factory(*this) );
129 uno::Sequence
<rtl::OUString
> ServiceDecl::getSupportedServiceNames() const
131 std::vector
<rtl::OUString
> vec
;
133 rtl::OString
const str(m_pServiceNames
);
134 sal_Int32 nIndex
= 0;
136 rtl::OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
137 vec
.push_back( rtl::OUString( token
.getStr(), token
.getLength(),
138 RTL_TEXTENCODING_ASCII_US
) );
142 return comphelper::containerToSequence(vec
);
145 bool ServiceDecl::supportsService( ::rtl::OUString
const& name
) const
147 rtl::OString
const str(m_pServiceNames
);
148 sal_Int32 nIndex
= 0;
150 rtl::OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
151 if (name
.equalsAsciiL( token
.getStr(), token
.getLength() ))
158 rtl::OUString
ServiceDecl::getImplementationName() const
160 return rtl::OUString::createFromAscii(m_pImplName
);
163 } // namespace service_decl
164 } // namespace comphelper