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 virtual sal_Bool SAL_CALL supportsService( rtl::OUString const& name );
53 virtual uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames();
54 // XSingleComponentFactory:
55 virtual uno::Reference<uno::XInterface> SAL_CALL createInstanceWithContext(
56 uno::Reference<uno::XComponentContext> const& xContext );
57 virtual uno::Reference<uno::XInterface> SAL_CALL
58 createInstanceWithArgumentsAndContext(
59 uno::Sequence<uno::Any> const& args,
60 uno::Reference<uno::XComponentContext> const& xContext );
61
62 private:
63 virtual ~Factory();
64
65 ServiceDecl const& m_rServiceDecl;
66 };
67
~Factory()68 ServiceDecl::Factory::~Factory()
69 {
70 }
71
72 // XServiceInfo:
getImplementationName()73 rtl::OUString ServiceDecl::Factory::getImplementationName()
74 {
75 return m_rServiceDecl.getImplementationName();
76 }
77
supportsService(rtl::OUString const & name)78 sal_Bool ServiceDecl::Factory::supportsService( rtl::OUString const& name )
79 {
80 return m_rServiceDecl.supportsService(name);
81 }
82
getSupportedServiceNames()83 uno::Sequence<rtl::OUString> ServiceDecl::Factory::getSupportedServiceNames()
84 {
85 return m_rServiceDecl.getSupportedServiceNames();
86 }
87
88 // XSingleComponentFactory:
createInstanceWithContext(uno::Reference<uno::XComponentContext> const & xContext)89 uno::Reference<uno::XInterface> ServiceDecl::Factory::createInstanceWithContext(
90 uno::Reference<uno::XComponentContext> const& xContext )
91 {
92 return m_rServiceDecl.m_createFunc(
93 m_rServiceDecl, uno::Sequence<uno::Any>(), xContext );
94 }
95
96 uno::Reference<uno::XInterface>
createInstanceWithArgumentsAndContext(uno::Sequence<uno::Any> const & args,uno::Reference<uno::XComponentContext> const & xContext)97 ServiceDecl::Factory::createInstanceWithArgumentsAndContext(
98 uno::Sequence<uno::Any > const& args,
99 uno::Reference<uno::XComponentContext> const& xContext )
100 {
101 return m_rServiceDecl.m_createFunc(
102 m_rServiceDecl, args, xContext );
103 }
104
getFactory(sal_Char const * pImplName) const105 void * ServiceDecl::getFactory( sal_Char const* pImplName ) const
106 {
107 if (rtl_str_compare(m_pImplName, pImplName) == 0) {
108 lang::XSingleComponentFactory * const pFac( new Factory(*this) );
109 pFac->acquire();
110 return pFac;
111 }
112 return 0;
113 }
114
getSupportedServiceNames() const115 uno::Sequence<rtl::OUString> ServiceDecl::getSupportedServiceNames() const
116 {
117 std::vector<rtl::OUString> vec;
118
119 rtl::OString const str(m_pServiceNames);
120 sal_Int32 nIndex = 0;
121 do {
122 rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) );
123 vec.push_back( rtl::OUString( token.getStr(), token.getLength(),
124 RTL_TEXTENCODING_ASCII_US ) );
125 }
126 while (nIndex >= 0);
127
128 return comphelper::containerToSequence(vec);
129 }
130
supportsService(::rtl::OUString const & name) const131 bool ServiceDecl::supportsService( ::rtl::OUString const& name ) const
132 {
133 rtl::OString const str(m_pServiceNames);
134 sal_Int32 nIndex = 0;
135 do {
136 rtl::OString const token( str.getToken( 0, m_cDelim, nIndex ) );
137 if (name.equalsAsciiL( token.getStr(), token.getLength() ))
138 return true;
139 }
140 while (nIndex >= 0);
141 return false;
142 }
143
getImplementationName() const144 rtl::OUString ServiceDecl::getImplementationName() const
145 {
146 return rtl::OUString::createFromAscii(m_pImplName);
147 }
148
149 } // namespace service_decl
150 } // namespace comphelper
151