Update ooo320-m1
[ooovba.git] / scripting / source / provider / ProviderCache.hxx
blobb739ee70b180e1433ad591e836717552a49eb4d9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ProviderCache.hxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_
32 #define _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_
34 #include <hash_map>
35 #include <osl/mutex.hxx>
36 #include <rtl/ustring.hxx>
37 #include <cppuhelper/implbase1.hxx>
38 #include <com/sun/star/uno/RuntimeException.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
41 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
42 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
44 #include <com/sun/star/frame/XModel.hpp>
45 #include <com/sun/star/script/provider/XScriptProvider.hpp>
47 #include "ScriptingContext.hxx"
49 namespace func_provider
51 // for simplification
52 #define css ::com::sun::star
54 //Typedefs
55 //=============================================================================
57 struct ProviderDetails
59 //css::uno::Reference< css::lang::XSingleServiceFactory > factory;
60 css::uno::Reference< css::lang::XSingleComponentFactory > factory;
61 css::uno::Reference< css::script::provider::XScriptProvider > provider;
63 typedef ::std::hash_map < ::rtl::OUString, ProviderDetails , ::rtl::OUStringHash,
64 ::std::equal_to< ::rtl::OUString > > ProviderDetails_hash;
67 class ProviderCache
70 public:
71 ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext )
72 throw ( css::uno::RuntimeException );
73 ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext,
74 const css::uno::Sequence< ::rtl::OUString >& blackList )
75 throw ( css::uno::RuntimeException );
76 ~ProviderCache();
77 css::uno::Reference< css::script::provider::XScriptProvider >
78 getProvider( const ::rtl::OUString& providerName );
79 css::uno::Sequence < css::uno::Reference< css::script::provider::XScriptProvider > >
80 getAllProviders() throw ( css::uno::RuntimeException );
81 private:
82 void populateCache()
83 throw ( css::uno::RuntimeException );
85 css::uno::Reference< css::script::provider::XScriptProvider >
86 createProvider( ProviderDetails& details ) throw ( css::uno::RuntimeException );
87 bool isInBlackList( const ::rtl::OUString& serviceName )
89 if ( m_sBlackList.getLength() > 0 )
91 for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ )
93 if ( m_sBlackList[ index ].equals( serviceName ) )
95 return true;
99 return false;
101 css::uno::Sequence< ::rtl::OUString > m_sBlackList;
102 ProviderDetails_hash m_hProviderDetailsCache;
103 osl::Mutex m_mutex;
104 css::uno::Sequence< css::uno::Any > m_Sctx;
105 css::uno::Reference< css::uno::XComponentContext > m_xContext;
106 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
110 } // func_provider
111 #endif