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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_scripting.hxx" 30 #include <cppuhelper/weakref.hxx> 31 #include <cppuhelper/implementationentry.hxx> 32 #include <cppuhelper/factory.hxx> 33 #include <cppuhelper/exc_hlp.hxx> 34 #include <cppuhelper/implbase1.hxx> 35 36 #include <util/util.hxx> 37 38 #include "MasterScriptProviderFactory.hxx" 39 40 using namespace ::com::sun::star; 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::script; 43 44 namespace func_provider 45 { 46 47 MasterScriptProviderFactory::MasterScriptProviderFactory( 48 Reference< XComponentContext > const & xComponentContext ) 49 : m_xComponentContext( xComponentContext ) 50 { 51 } 52 53 MasterScriptProviderFactory::~MasterScriptProviderFactory() 54 { 55 } 56 57 58 //############################################################################ 59 // Implementation of XScriptProviderFactory 60 //############################################################################ 61 62 63 Reference< provider::XScriptProvider > SAL_CALL 64 MasterScriptProviderFactory::createScriptProvider( const Any& context ) throw ( lang::IllegalArgumentException, RuntimeException) 65 { 66 Reference< provider::XScriptProvider > xMsp( getActiveMSPList() ->getMSPFromAnyContext( context ), UNO_QUERY_THROW ); 67 return xMsp; 68 } 69 70 //############################################################################ 71 // Helper methods 72 //############################################################################ 73 74 const rtl::Reference< ActiveMSPList > & 75 MasterScriptProviderFactory::getActiveMSPList() const 76 { 77 if ( !m_MSPList.is() ) 78 { 79 ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); 80 if ( !m_MSPList.is() ) 81 m_MSPList = new ActiveMSPList( m_xComponentContext ); 82 } 83 return m_MSPList; 84 } 85 86 //############################################################################ 87 // Namespace global methods for setting up MasterScriptProviderFactory service 88 //############################################################################ 89 90 Sequence< ::rtl::OUString > SAL_CALL 91 mspf_getSupportedServiceNames( ) 92 SAL_THROW( () ) 93 { 94 ::rtl::OUString str_name = ::rtl::OUString::createFromAscii( 95 "com.sun.star.script.provider.MasterScriptProviderFactory"); 96 97 return Sequence< ::rtl::OUString >( &str_name, 1 ); 98 } 99 100 ::rtl::OUString SAL_CALL 101 mspf_getImplementationName( ) 102 SAL_THROW( () ) 103 { 104 return ::rtl::OUString::createFromAscii( 105 "com.sun.star.script.provider.MasterScriptProviderFactory"); 106 } 107 108 Reference< XInterface > SAL_CALL 109 mspf_create( Reference< XComponentContext > const & xComponentContext ) 110 SAL_THROW( (Exception) ) 111 { 112 return static_cast< ::cppu::OWeakObject * >( 113 new MasterScriptProviderFactory( xComponentContext ) ); 114 } 115 116 //############################################################################ 117 // Implementation of XServiceInfo 118 //############################################################################ 119 120 ::rtl::OUString SAL_CALL 121 MasterScriptProviderFactory::getImplementationName() 122 throw (RuntimeException) 123 { 124 return mspf_getImplementationName(); 125 } 126 127 Sequence< ::rtl::OUString > SAL_CALL 128 MasterScriptProviderFactory::getSupportedServiceNames() 129 throw (RuntimeException) 130 { 131 return mspf_getSupportedServiceNames(); 132 } 133 134 sal_Bool MasterScriptProviderFactory::supportsService( 135 ::rtl::OUString const & serviceName ) 136 throw (RuntimeException) 137 { 138 // check(); 139 140 Sequence< ::rtl::OUString > supported_services( 141 getSupportedServiceNames() ); 142 143 ::rtl::OUString const * ar = supported_services.getConstArray(); 144 145 for ( sal_Int32 pos = supported_services.getLength(); pos--; ) 146 { 147 if (ar[ pos ].equals( serviceName )) 148 return true; 149 } 150 return false; 151 } 152 153 } // namespace browsenodefactory 154