1*6998d047SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6998d047SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6998d047SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6998d047SAndrew Rist * distributed with this work for additional information 6*6998d047SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6998d047SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6998d047SAndrew Rist * "License"); you may not use this file except in compliance 9*6998d047SAndrew Rist * with the License. You may obtain a copy of the License at 10*6998d047SAndrew Rist * 11*6998d047SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6998d047SAndrew Rist * 13*6998d047SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6998d047SAndrew Rist * software distributed under the License is distributed on an 15*6998d047SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6998d047SAndrew Rist * KIND, either express or implied. See the License for the 17*6998d047SAndrew Rist * specific language governing permissions and limitations 18*6998d047SAndrew Rist * under the License. 19*6998d047SAndrew Rist * 20*6998d047SAndrew Rist *************************************************************/ 21*6998d047SAndrew Rist 22*6998d047SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_ 25cdf0e10cSrcweir #define _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <hash_map> 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <rtl/ustring.hxx> 30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 34cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 38cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProvider.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include "ScriptingContext.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace func_provider 43cdf0e10cSrcweir { 44cdf0e10cSrcweir // for simplification 45cdf0e10cSrcweir #define css ::com::sun::star 46cdf0e10cSrcweir 47cdf0e10cSrcweir //Typedefs 48cdf0e10cSrcweir //============================================================================= 49cdf0e10cSrcweir 50cdf0e10cSrcweir struct ProviderDetails 51cdf0e10cSrcweir { 52cdf0e10cSrcweir //css::uno::Reference< css::lang::XSingleServiceFactory > factory; 53cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleComponentFactory > factory; 54cdf0e10cSrcweir css::uno::Reference< css::script::provider::XScriptProvider > provider; 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir typedef ::std::hash_map < ::rtl::OUString, ProviderDetails , ::rtl::OUStringHash, 57cdf0e10cSrcweir ::std::equal_to< ::rtl::OUString > > ProviderDetails_hash; 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir class ProviderCache 61cdf0e10cSrcweir { 62cdf0e10cSrcweir 63cdf0e10cSrcweir public: 64cdf0e10cSrcweir ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext ) 65cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 66cdf0e10cSrcweir ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext, 67cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString >& blackList ) 68cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 69cdf0e10cSrcweir ~ProviderCache(); 70cdf0e10cSrcweir css::uno::Reference< css::script::provider::XScriptProvider > 71cdf0e10cSrcweir getProvider( const ::rtl::OUString& providerName ); 72cdf0e10cSrcweir css::uno::Sequence < css::uno::Reference< css::script::provider::XScriptProvider > > 73cdf0e10cSrcweir getAllProviders() throw ( css::uno::RuntimeException ); 74cdf0e10cSrcweir private: 75cdf0e10cSrcweir void populateCache() 76cdf0e10cSrcweir throw ( css::uno::RuntimeException ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir css::uno::Reference< css::script::provider::XScriptProvider > 79cdf0e10cSrcweir createProvider( ProviderDetails& details ) throw ( css::uno::RuntimeException ); isInBlackList(const::rtl::OUString & serviceName)80cdf0e10cSrcweir bool isInBlackList( const ::rtl::OUString& serviceName ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir if ( m_sBlackList.getLength() > 0 ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir if ( m_sBlackList[ index ].equals( serviceName ) ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir return true; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } 91cdf0e10cSrcweir } 92cdf0e10cSrcweir return false; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > m_sBlackList; 95cdf0e10cSrcweir ProviderDetails_hash m_hProviderDetailsCache; 96cdf0e10cSrcweir osl::Mutex m_mutex; 97cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > m_Sctx; 98cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_xContext; 99cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 100cdf0e10cSrcweir 101cdf0e10cSrcweir 102cdf0e10cSrcweir }; 103cdf0e10cSrcweir } // func_provider 104cdf0e10cSrcweir #endif 105