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