Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
32 : : #include <com/sun/star/beans/PropertyValue.hpp>
33 : : #include "tvfactory.hxx"
34 : : #include "tvread.hxx"
35 : :
36 : :
37 : : using namespace treeview;
38 : : using namespace com::sun::star;
39 : : using namespace com::sun::star::uno;
40 : : using namespace com::sun::star::lang;
41 : : using namespace com::sun::star::beans;
42 : : using namespace com::sun::star::container;
43 : :
44 : :
45 : :
46 : 0 : TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
47 : 0 : : m_xMSF( xMSF )
48 : : {
49 : 0 : }
50 : :
51 : :
52 : 0 : TVFactory::~TVFactory()
53 : : {
54 : 0 : }
55 : :
56 : :
57 : : //////////////////////////////////////////////////////////////////////////
58 : : // XInterface
59 : : //////////////////////////////////////////////////////////////////////////
60 : :
61 : : void SAL_CALL
62 : 0 : TVFactory::acquire(
63 : : void )
64 : : throw()
65 : : {
66 : 0 : OWeakObject::acquire();
67 : 0 : }
68 : :
69 : :
70 : : void SAL_CALL
71 : 0 : TVFactory::release(
72 : : void )
73 : : throw()
74 : : {
75 : 0 : OWeakObject::release();
76 : 0 : }
77 : :
78 : :
79 : : Any SAL_CALL
80 : 0 : TVFactory::queryInterface(
81 : : const Type& rType )
82 : : throw( RuntimeException )
83 : : {
84 : : Any aRet = cppu::queryInterface( rType,
85 : : (static_cast< XServiceInfo* >(this)),
86 : : (static_cast< XTypeProvider* >(this)),
87 : 0 : (static_cast< XMultiServiceFactory* >(this)) );
88 : :
89 : 0 : return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
90 : : }
91 : :
92 : :
93 : : ////////////////////////////////////////////////////////////////////////////////
94 : : //
95 : : // XTypeProvider methods.
96 : :
97 : 0 : XTYPEPROVIDER_IMPL_3( TVFactory,
98 : : XServiceInfo,
99 : : XTypeProvider,
100 : : XMultiServiceFactory );
101 : :
102 : :
103 : :
104 : : ////////////////////////////////////////////////////////////////////////////////
105 : :
106 : : // XServiceInfo methods.
107 : :
108 : : rtl::OUString SAL_CALL
109 : 0 : TVFactory::getImplementationName()
110 : : throw( RuntimeException )
111 : : {
112 : 0 : return TVFactory::getImplementationName_static();
113 : : }
114 : :
115 : :
116 : : sal_Bool SAL_CALL
117 : 0 : TVFactory::supportsService(
118 : : const rtl::OUString& ServiceName )
119 : : throw( RuntimeException )
120 : : {
121 : : return
122 : 0 : ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
123 : 0 : ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
124 : : }
125 : :
126 : :
127 : : Sequence< rtl::OUString > SAL_CALL
128 : 0 : TVFactory::getSupportedServiceNames( void )
129 : : throw( RuntimeException )
130 : : {
131 : 0 : return TVFactory::getSupportedServiceNames_static();
132 : : }
133 : :
134 : :
135 : :
136 : : // XMultiServiceFactory
137 : :
138 : : Reference< XInterface > SAL_CALL
139 : 0 : TVFactory::createInstance(
140 : : const rtl::OUString& aServiceSpecifier )
141 : : throw( Exception,
142 : : RuntimeException )
143 : : {
144 : 0 : Any aAny;
145 : 0 : aAny <<= rtl::OUString();
146 : 0 : Sequence< Any > seq( 1 );
147 : 0 : seq[0] <<= PropertyValue(
148 : : rtl::OUString( "nodepath" ),
149 : : -1,
150 : : aAny,
151 : 0 : PropertyState_DIRECT_VALUE );
152 : :
153 : : return createInstanceWithArguments( aServiceSpecifier,
154 : 0 : seq );
155 : : }
156 : :
157 : :
158 : : Reference< XInterface > SAL_CALL
159 : 0 : TVFactory::createInstanceWithArguments(
160 : : const rtl::OUString& ServiceSpecifier,
161 : : const Sequence< Any >& Arguments )
162 : : throw( Exception,
163 : : RuntimeException )
164 : : {
165 : : (void)ServiceSpecifier;
166 : :
167 : 0 : if( ! m_xHDS.is() )
168 : : {
169 : 0 : cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
170 : 0 : m_xHDS = Reference< XInterface >( p );
171 : : }
172 : :
173 : 0 : Reference< XInterface > ret = m_xHDS;
174 : :
175 : 0 : rtl::OUString hierview;
176 : 0 : for( int i = 0; i < Arguments.getLength(); ++i )
177 : : {
178 : 0 : PropertyValue pV;
179 : 0 : if( ! ( Arguments[i] >>= pV ) )
180 : 0 : continue;
181 : :
182 : 0 : if( pV.Name.compareToAscii( "nodepath" ) )
183 : 0 : continue;
184 : :
185 : 0 : if( ! ( pV.Value >>= hierview ) )
186 : 0 : continue;
187 : :
188 : 0 : break;
189 : 0 : }
190 : :
191 : 0 : if( !hierview.isEmpty() )
192 : : {
193 : 0 : Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
194 : 0 : Any aAny = xhieraccess->getByHierarchicalName( hierview );
195 : 0 : Reference< XInterface > xInterface;
196 : 0 : aAny >>= xInterface;
197 : 0 : return xInterface;
198 : : }
199 : : else
200 : 0 : return m_xHDS;
201 : : }
202 : :
203 : :
204 : : Sequence< rtl::OUString > SAL_CALL
205 : 0 : TVFactory::getAvailableServiceNames( )
206 : : throw( RuntimeException )
207 : : {
208 : 0 : Sequence< rtl::OUString > seq( 1 );
209 : 0 : seq[0] = rtl::OUString( "com.sun.star.ucb.HierarchyDataReadAccess" );
210 : 0 : return seq;
211 : : }
212 : :
213 : :
214 : :
215 : : // static
216 : :
217 : :
218 : : rtl::OUString SAL_CALL
219 : 0 : TVFactory::getImplementationName_static()
220 : : {
221 : 0 : return rtl::OUString( "com.sun.star.help.TreeViewImpl" );
222 : : }
223 : :
224 : :
225 : : Sequence< rtl::OUString > SAL_CALL
226 : 0 : TVFactory::getSupportedServiceNames_static()
227 : : {
228 : 0 : Sequence< rtl::OUString > seq( 2 );
229 : 0 : seq[0] = rtl::OUString( "com.sun.star.help.TreeView" );
230 : 0 : seq[1] = rtl::OUString( "com.sun.star.ucb.HiearchyDataSource" );
231 : 0 : return seq;
232 : : }
233 : :
234 : :
235 : : Reference< XSingleServiceFactory > SAL_CALL
236 : 0 : TVFactory::createServiceFactory(
237 : : const Reference< XMultiServiceFactory >& rxServiceMgr )
238 : : {
239 : : return Reference< XSingleServiceFactory > (
240 : : cppu::createSingleFactory(
241 : : rxServiceMgr,
242 : : TVFactory::getImplementationName_static(),
243 : : TVFactory::CreateInstance,
244 : 0 : TVFactory::getSupportedServiceNames_static() ) );
245 : : }
246 : :
247 : :
248 : :
249 : : Reference< XInterface > SAL_CALL
250 : 0 : TVFactory::CreateInstance(
251 : : const Reference< XMultiServiceFactory >& xMultiServiceFactory )
252 : : {
253 : 0 : XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
254 : 0 : return Reference< XInterface >::query( xP );
255 : : }
256 : :
257 : : //=========================================================================
258 : 0 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
259 : : const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
260 : : {
261 : : (void)pRegistryKey;
262 : :
263 : 0 : void * pRet = 0;
264 : :
265 : : Reference< XMultiServiceFactory > xSMgr(
266 : 0 : reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
267 : :
268 : 0 : Reference< XSingleServiceFactory > xFactory;
269 : :
270 : : //////////////////////////////////////////////////////////////////////
271 : : // File Content Provider.
272 : : //////////////////////////////////////////////////////////////////////
273 : :
274 : 0 : if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
275 : : {
276 : 0 : xFactory = TVFactory::createServiceFactory( xSMgr );
277 : : }
278 : :
279 : : //////////////////////////////////////////////////////////////////////
280 : :
281 : 0 : if ( xFactory.is() )
282 : : {
283 : 0 : xFactory->acquire();
284 : 0 : pRet = xFactory.get();
285 : : }
286 : :
287 : 0 : return pRet;
288 : : }
289 : :
290 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|