update dev300-m58
[ooovba.git] / extensions / source / plugin / base / manager.cxx
blob77e18cd4d544e25e5e3c0c8e6a692c22c51b0b78
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: manager.cxx,v $
10 * $Revision: 1.11 $
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_extensions.hxx"
34 #if STLPORT_VERSION>=321
35 #include <cstdarg>
36 #endif
38 #include <plugin/impl.hxx>
40 #ifndef _OSL_MUTEX_HXX
41 #include <osl/mutex.hxx>
42 #endif
43 #include <svtools/pathoptions.hxx>
44 #include <com/sun/star/container/XEnumerationAccess.hpp>
45 #include <com/sun/star/container/XNameAccess.hpp>
46 #include <com/sun/star/container/XEnumeration.hpp>
47 #include <com/sun/star/container/XElementAccess.hpp>
48 #include <com/sun/star/container/XIndexAccess.hpp>
49 #include <com/sun/star/loader/XImplementationLoader.hpp>
50 #include <com/sun/star/loader/CannotActivateFactoryException.hpp>
52 PluginManager* PluginManager::pManager = NULL;
54 PluginManager& PluginManager::get()
56 if( ! pManager )
57 pManager = new PluginManager();
58 return *pManager;
61 void PluginManager::setServiceFactory( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
63 PluginManager& rManager = get();
64 if( ! rManager.m_xSMgr.is() )
65 rManager.m_xSMgr = xFactory;
68 PluginManager::PluginManager()
72 const Sequence< ::rtl::OUString >& PluginManager::getAdditionalSearchPaths()
74 static Sequence< ::rtl::OUString > aPaths;
76 if( ! aPaths.getLength() )
78 SvtPathOptions aOptions;
79 String aPluginPath( aOptions.GetPluginPath() );
80 if( aPluginPath.Len() )
82 USHORT nPaths = aPluginPath.GetTokenCount( ';' );
83 aPaths.realloc( nPaths );
84 for( USHORT i = 0; i < nPaths; i++ )
85 aPaths.getArray()[i] = aPluginPath.GetToken( i, ';' );
89 return aPaths;
92 //==================================================================================================
93 Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) throw( Exception )
95 Reference< XInterface > xService = *new XPluginManager_Impl( rSMgr );
96 return xService;
99 // ::com::sun::star::lang::XServiceInfo
100 ::rtl::OUString XPluginManager_Impl::getImplementationName() throw( )
103 return getImplementationName_Static();
107 // ::com::sun::star::lang::XServiceInfo
108 sal_Bool XPluginManager_Impl::supportsService(const ::rtl::OUString& ServiceName) throw( )
110 Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
111 const ::rtl::OUString * pArray = aSNL.getConstArray();
112 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
113 if( pArray[i] == ServiceName )
114 return sal_True;
115 return sal_False;
118 // ::com::sun::star::lang::XServiceInfo
119 Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames(void) throw( )
121 return getSupportedServiceNames_Static();
124 // XPluginManager_Impl
125 Sequence< ::rtl::OUString > XPluginManager_Impl::getSupportedServiceNames_Static(void) throw( )
127 Sequence< ::rtl::OUString > aSNS( 1 );
128 aSNS.getArray()[0] = ::rtl::OUString::createFromAscii( "com.sun.star.plugin.PluginManager" );
129 return aSNS;
132 XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr )
133 : m_xSMgr( rSMgr )
135 PluginManager::setServiceFactory( rSMgr );
138 XPluginManager_Impl::~XPluginManager_Impl()
142 XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance )
144 ::std::list<XPlugin_Impl*>::iterator iter;
145 for( iter = PluginManager::get().getPlugins().begin();
146 iter != PluginManager::get().getPlugins().end(); ++iter )
148 if( (*iter)->getNPPInstance() == instance )
149 return *iter;
152 return NULL;
155 XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin )
157 ::std::list<XPlugin_Impl*>::iterator iter;
158 for( iter = PluginManager::get().getPlugins().begin();
159 iter != PluginManager::get().getPlugins().end(); ++iter )
161 if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) )
162 return *iter;
165 return NULL;
168 Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPlugin( const Reference< ::com::sun::star::plugin::XPluginContext >& acontext, INT16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const ::com::sun::star::plugin::PluginDescription& plugintype)
169 throw( RuntimeException,::com::sun::star::plugin::PluginException )
171 XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr );
172 pImpl->setPluginContext( acontext );
174 PluginManager::get().getPlugins().push_back( pImpl );
176 pImpl->initInstance( plugintype,
177 argn,
178 argv,
179 mode );
181 return pImpl;
184 Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::createPluginFromURL( const Reference< ::com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< ::rtl::OUString >& argn, const Sequence< ::rtl::OUString >& argv, const Reference< ::com::sun::star::awt::XToolkit > & toolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & parent, const ::rtl::OUString& url ) throw()
186 XPlugin_Impl* pImpl = new XPlugin_Impl( m_xSMgr );
187 Reference< ::com::sun::star::plugin::XPlugin > xRef = pImpl;
189 pImpl->setPluginContext( acontext );
191 PluginManager::get().getPlugins().push_back( pImpl );
194 pImpl->initInstance( url,
195 argn,
196 argv,
197 mode );
199 pImpl->createPeer( toolkit, parent );
201 pImpl->provideNewStream( pImpl->getDescription().Mimetype,
202 Reference< com::sun::star::io::XActiveDataSource >(),
203 url,
204 0, 0, (sal_Bool)(url.compareToAscii( "file:", 5 ) == 0) );
206 if( ! pImpl->getPluginComm() )
208 pImpl->dispose();
209 xRef = NULL;
212 return xRef;