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