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