xref: /trunk/main/xmlhelp/source/treeview/tvfactory.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_xmlhelp.hxx"
31 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include "tvfactory.hxx"
35 #include "tvread.hxx"
36 
37 
38 using namespace treeview;
39 using namespace com::sun::star;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::container;
44 
45 
46 
47 TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
48     : m_xMSF( xMSF )
49 {
50 }
51 
52 
53 TVFactory::~TVFactory()
54 {
55 }
56 
57 
58 //////////////////////////////////////////////////////////////////////////
59 // XInterface
60 //////////////////////////////////////////////////////////////////////////
61 
62 void SAL_CALL
63 TVFactory::acquire(
64     void )
65     throw()
66 {
67   OWeakObject::acquire();
68 }
69 
70 
71 void SAL_CALL
72 TVFactory::release(
73               void )
74   throw()
75 {
76   OWeakObject::release();
77 }
78 
79 
80 Any SAL_CALL
81 TVFactory::queryInterface(
82     const Type& rType )
83     throw( RuntimeException )
84 {
85     Any aRet = cppu::queryInterface( rType,
86                                      SAL_STATIC_CAST( XServiceInfo*,  this ),
87                                      SAL_STATIC_CAST( XTypeProvider*, this ),
88                                      SAL_STATIC_CAST( XMultiServiceFactory*, this ) );
89 
90     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
91 }
92 
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 //
96 // XTypeProvider methods.
97 
98 XTYPEPROVIDER_IMPL_3( TVFactory,
99                       XServiceInfo,
100                       XTypeProvider,
101                       XMultiServiceFactory );
102 
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 
107 // XServiceInfo methods.
108 
109 rtl::OUString SAL_CALL
110 TVFactory::getImplementationName()
111     throw( RuntimeException )
112 {
113     return TVFactory::getImplementationName_static();
114 }
115 
116 
117 sal_Bool SAL_CALL
118 TVFactory::supportsService(
119     const rtl::OUString& ServiceName )
120     throw( RuntimeException )
121 {
122     return
123         ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
124         ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
125 }
126 
127 
128 Sequence< rtl::OUString > SAL_CALL
129 TVFactory::getSupportedServiceNames( void )
130     throw( RuntimeException )
131 {
132     return TVFactory::getSupportedServiceNames_static();
133 }
134 
135 
136 
137 // XMultiServiceFactory
138 
139 Reference< XInterface > SAL_CALL
140 TVFactory::createInstance(
141     const rtl::OUString& aServiceSpecifier )
142     throw( Exception,
143            RuntimeException )
144 {
145     Any aAny;
146     aAny <<= rtl::OUString();
147     Sequence< Any > seq( 1 );
148     seq[0] <<= PropertyValue(
149         rtl::OUString::createFromAscii( "nodepath" ),
150         -1,
151         aAny,
152         PropertyState_DIRECT_VALUE );
153 
154     return createInstanceWithArguments( aServiceSpecifier,
155                                         seq );
156 }
157 
158 
159 Reference< XInterface > SAL_CALL
160 TVFactory::createInstanceWithArguments(
161     const rtl::OUString& ServiceSpecifier,
162     const Sequence< Any >& Arguments )
163     throw( Exception,
164            RuntimeException )
165 {
166     (void)ServiceSpecifier;
167 
168     if( ! m_xHDS.is() )
169     {
170         cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
171         m_xHDS = Reference< XInterface >( p );
172     }
173 
174     Reference< XInterface > ret = m_xHDS;
175 
176     rtl::OUString hierview;
177     for( int i = 0; i < Arguments.getLength(); ++i )
178     {
179         PropertyValue pV;
180         if( ! ( Arguments[i] >>= pV ) )
181             continue;
182 
183         if( pV.Name.compareToAscii( "nodepath" ) )
184             continue;
185 
186         if( ! ( pV.Value >>= hierview ) )
187             continue;
188 
189         break;
190     }
191 
192     if( hierview.getLength() )
193     {
194         Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
195         Any aAny = xhieraccess->getByHierarchicalName( hierview );
196         Reference< XInterface > xInterface;
197         aAny >>= xInterface;
198         return xInterface;
199     }
200     else
201         return m_xHDS;
202 }
203 
204 
205 Sequence< rtl::OUString > SAL_CALL
206 TVFactory::getAvailableServiceNames( )
207     throw( RuntimeException )
208 {
209     Sequence< rtl::OUString > seq( 1 );
210     seq[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" );
211     return seq;
212 }
213 
214 
215 
216 // static
217 
218 
219 rtl::OUString SAL_CALL
220 TVFactory::getImplementationName_static()
221 {
222     return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" );
223 }
224 
225 
226 Sequence< rtl::OUString > SAL_CALL
227 TVFactory::getSupportedServiceNames_static()
228 {
229     Sequence< rtl::OUString > seq( 2 );
230     seq[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" );
231     seq[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" );
232     return seq;
233 }
234 
235 
236 Reference< XSingleServiceFactory > SAL_CALL
237 TVFactory::createServiceFactory(
238     const Reference< XMultiServiceFactory >& rxServiceMgr )
239 {
240     return Reference< XSingleServiceFactory > (
241         cppu::createSingleFactory(
242             rxServiceMgr,
243             TVFactory::getImplementationName_static(),
244             TVFactory::CreateInstance,
245             TVFactory::getSupportedServiceNames_static() ) );
246 }
247 
248 
249 
250 Reference< XInterface > SAL_CALL
251 TVFactory::CreateInstance(
252     const Reference< XMultiServiceFactory >& xMultiServiceFactory )
253 {
254     XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
255     return Reference< XInterface >::query( xP );
256 }
257 
258 //=========================================================================
259 extern "C" void SAL_CALL component_getImplementationEnvironment(
260     const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
261 {
262     (void)ppEnv;
263 
264     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
265 }
266 
267 //=========================================================================
268 extern "C" void * SAL_CALL component_getFactory(
269     const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
270 {
271     (void)pRegistryKey;
272 
273     void * pRet = 0;
274 
275     Reference< XMultiServiceFactory > xSMgr(
276         reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
277 
278     Reference< XSingleServiceFactory > xFactory;
279 
280     //////////////////////////////////////////////////////////////////////
281     // File Content Provider.
282     //////////////////////////////////////////////////////////////////////
283 
284     if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
285     {
286         xFactory = TVFactory::createServiceFactory( xSMgr );
287     }
288 
289     //////////////////////////////////////////////////////////////////////
290 
291     if ( xFactory.is() )
292     {
293         xFactory->acquire();
294         pRet = xFactory.get();
295     }
296 
297     return pRet;
298 }
299