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 ) 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 { 107 return static_cast< ::cppu::OWeakObject * >( 108 new MasterScriptProviderFactory( xComponentContext ) ); 109 } 110 111 //############################################################################ 112 // Implementation of XServiceInfo 113 //############################################################################ 114 115 ::rtl::OUString SAL_CALL getImplementationName()116MasterScriptProviderFactory::getImplementationName() 117 { 118 return mspf_getImplementationName(); 119 } 120 121 Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()122MasterScriptProviderFactory::getSupportedServiceNames() 123 { 124 return mspf_getSupportedServiceNames(); 125 } 126 supportsService(::rtl::OUString const & serviceName)127sal_Bool MasterScriptProviderFactory::supportsService( 128 ::rtl::OUString const & serviceName ) 129 { 130 // check(); 131 132 Sequence< ::rtl::OUString > supported_services( 133 getSupportedServiceNames() ); 134 135 ::rtl::OUString const * ar = supported_services.getConstArray(); 136 137 for ( sal_Int32 pos = supported_services.getLength(); pos--; ) 138 { 139 if (ar[ pos ].equals( serviceName )) 140 return true; 141 } 142 return false; 143 } 144 145 } // namespace browsenodefactory 146