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 #ifndef _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_ 25 #define _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_ 26 27 #include <hash_map> 28 #include <osl/mutex.hxx> 29 #include <rtl/ustring.hxx> 30 #include <cppuhelper/implbase1.hxx> 31 #include <com/sun/star/uno/RuntimeException.hpp> 32 #include <com/sun/star/lang/XServiceInfo.hpp> 33 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 34 #include <com/sun/star/lang/XSingleComponentFactory.hpp> 35 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 36 37 #include <com/sun/star/frame/XModel.hpp> 38 #include <com/sun/star/script/provider/XScriptProvider.hpp> 39 40 #include "ScriptingContext.hxx" 41 42 namespace func_provider 43 { 44 // for simplification 45 #define css ::com::sun::star 46 47 //Typedefs 48 //============================================================================= 49 50 struct ProviderDetails 51 { 52 //css::uno::Reference< css::lang::XSingleServiceFactory > factory; 53 css::uno::Reference< css::lang::XSingleComponentFactory > factory; 54 css::uno::Reference< css::script::provider::XScriptProvider > provider; 55 }; 56 typedef ::std::hash_map < ::rtl::OUString, ProviderDetails , ::rtl::OUStringHash, 57 ::std::equal_to< ::rtl::OUString > > ProviderDetails_hash; 58 59 60 class ProviderCache 61 { 62 63 public: 64 ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext ); 65 ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext, 66 const css::uno::Sequence< ::rtl::OUString >& blackList ); 67 ~ProviderCache(); 68 css::uno::Reference< css::script::provider::XScriptProvider > 69 getProvider( const ::rtl::OUString& providerName ); 70 css::uno::Sequence < css::uno::Reference< css::script::provider::XScriptProvider > > 71 getAllProviders(); 72 private: 73 void populateCache(); 74 75 css::uno::Reference< css::script::provider::XScriptProvider > 76 createProvider( ProviderDetails& details ); isInBlackList(const::rtl::OUString & serviceName)77 bool isInBlackList( const ::rtl::OUString& serviceName ) 78 { 79 if ( m_sBlackList.getLength() > 0 ) 80 { 81 for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ ) 82 { 83 if ( m_sBlackList[ index ].equals( serviceName ) ) 84 { 85 return true; 86 } 87 } 88 } 89 return false; 90 } 91 css::uno::Sequence< ::rtl::OUString > m_sBlackList; 92 ProviderDetails_hash m_hProviderDetailsCache; 93 osl::Mutex m_mutex; 94 css::uno::Sequence< css::uno::Any > m_Sctx; 95 css::uno::Reference< css::uno::XComponentContext > m_xContext; 96 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 97 98 99 }; 100 } // func_provider 101 #endif 102