1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: servicedecl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 #include "comphelper/servicedecl.hxx"
35 #include "osl/diagnose.h"
36 #include "rtl/string.hxx"
37 #include "rtl/ustrbuf.hxx"
38 #include "cppuhelper/implbase2.hxx"
39 #include "comphelper/sequence.hxx"
40 #include "com/sun/star/lang/XSingleComponentFactory.hpp"
43 using namespace com::sun::star
;
45 namespace comphelper
{
46 namespace service_decl
{
48 class ServiceDecl::Factory
:
49 public cppu::WeakImplHelper2
<lang::XSingleComponentFactory
,
51 private boost::noncopyable
54 explicit Factory( ServiceDecl
const& rServiceDecl
)
55 : m_rServiceDecl(rServiceDecl
) {}
58 virtual rtl::OUString SAL_CALL
getImplementationName()
59 throw (uno::RuntimeException
);
60 virtual sal_Bool SAL_CALL
supportsService( rtl::OUString
const& name
)
61 throw (uno::RuntimeException
);
62 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
getSupportedServiceNames()
63 throw (uno::RuntimeException
);
64 // XSingleComponentFactory:
65 virtual uno::Reference
<uno::XInterface
> SAL_CALL
createInstanceWithContext(
66 uno::Reference
<uno::XComponentContext
> const& xContext
)
67 throw (uno::Exception
);
68 virtual uno::Reference
<uno::XInterface
> SAL_CALL
69 createInstanceWithArgumentsAndContext(
70 uno::Sequence
<uno::Any
> const& args
,
71 uno::Reference
<uno::XComponentContext
> const& xContext
)
72 throw (uno::Exception
);
77 ServiceDecl
const& m_rServiceDecl
;
80 ServiceDecl::Factory::~Factory()
85 rtl::OUString
ServiceDecl::Factory::getImplementationName()
86 throw (uno::RuntimeException
)
88 return m_rServiceDecl
.getImplementationName();
91 sal_Bool
ServiceDecl::Factory::supportsService( rtl::OUString
const& name
)
92 throw (uno::RuntimeException
)
94 return m_rServiceDecl
.supportsService(name
);
97 uno::Sequence
<rtl::OUString
> ServiceDecl::Factory::getSupportedServiceNames()
98 throw (uno::RuntimeException
)
100 return m_rServiceDecl
.getSupportedServiceNames();
103 // XSingleComponentFactory:
104 uno::Reference
<uno::XInterface
> ServiceDecl::Factory::createInstanceWithContext(
105 uno::Reference
<uno::XComponentContext
> const& xContext
)
106 throw (uno::Exception
)
108 return m_rServiceDecl
.m_createFunc(
109 m_rServiceDecl
, uno::Sequence
<uno::Any
>(), xContext
);
112 uno::Reference
<uno::XInterface
>
113 ServiceDecl::Factory::createInstanceWithArgumentsAndContext(
114 uno::Sequence
<uno::Any
> const& args
,
115 uno::Reference
<uno::XComponentContext
> const& xContext
)
116 throw (uno::Exception
)
118 return m_rServiceDecl
.m_createFunc(
119 m_rServiceDecl
, args
, xContext
);
122 bool ServiceDecl::writeInfo( registry::XRegistryKey
* xKey
) const
126 rtl::OUStringBuffer buf
;
127 buf
.append( static_cast<sal_Unicode
>('/') );
128 buf
.appendAscii( m_pImplName
);
129 buf
.appendAscii( RTL_CONSTASCII_STRINGPARAM("/UNO/SERVICES") );
131 uno::Reference
<registry::XRegistryKey
> const xNewKey(
132 xKey
->createKey( buf
.makeStringAndClear() ) );
134 rtl::OString
const str(m_pServiceNames
);
135 sal_Int32 nIndex
= 0;
137 rtl::OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
139 rtl::OUString( token
.getStr(), token
.getLength(),
140 RTL_TEXTENCODING_ASCII_US
) );
146 catch (registry::InvalidRegistryException
const&) {
147 OSL_ENSURE( false, "### InvalidRegistryException!" );
153 void * ServiceDecl::getFactory( sal_Char
const* pImplName
) const
155 if (rtl_str_compare(m_pImplName
, pImplName
) == 0) {
156 lang::XSingleComponentFactory
* const pFac( new Factory(*this) );
163 uno::Sequence
<rtl::OUString
> ServiceDecl::getSupportedServiceNames() const
165 std::vector
<rtl::OUString
> vec
;
167 rtl::OString
const str(m_pServiceNames
);
168 sal_Int32 nIndex
= 0;
170 rtl::OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
171 vec
.push_back( rtl::OUString( token
.getStr(), token
.getLength(),
172 RTL_TEXTENCODING_ASCII_US
) );
176 return comphelper::containerToSequence(vec
);
179 bool ServiceDecl::supportsService( ::rtl::OUString
const& name
) const
181 rtl::OString
const str(m_pServiceNames
);
182 sal_Int32 nIndex
= 0;
184 rtl::OString
const token( str
.getToken( 0, m_cDelim
, nIndex
) );
185 if (name
.equalsAsciiL( token
.getStr(), token
.getLength() ))
192 rtl::OUString
ServiceDecl::getImplementationName() const
194 return rtl::OUString::createFromAscii(m_pImplName
);
197 } // namespace service_decl
198 } // namespace comphelper