Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_
21 : : #define _FRAMEWORK_SCRIPT_PROVIDER_PROVIDERCACHE_HXX_
22 : :
23 : : #include <boost/unordered_map.hpp>
24 : : #include <osl/mutex.hxx>
25 : : #include <rtl/ustring.hxx>
26 : : #include <cppuhelper/implbase1.hxx>
27 : : #include <com/sun/star/uno/RuntimeException.hpp>
28 : : #include <com/sun/star/lang/XServiceInfo.hpp>
29 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30 : : #include <com/sun/star/lang/XSingleComponentFactory.hpp>
31 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
32 : :
33 : : #include <com/sun/star/frame/XModel.hpp>
34 : : #include <com/sun/star/script/provider/XScriptProvider.hpp>
35 : :
36 : : #include "ScriptingContext.hxx"
37 : :
38 : : namespace css = ::com::sun::star;
39 : :
40 : : namespace func_provider
41 : : {
42 : :
43 : : //Typedefs
44 : : //=============================================================================
45 : :
46 : 105 : struct ProviderDetails
47 : : {
48 : : //css::uno::Reference< css::lang::XSingleServiceFactory > factory;
49 : : css::uno::Reference< css::lang::XSingleComponentFactory > factory;
50 : : css::uno::Reference< css::script::provider::XScriptProvider > provider;
51 : : };
52 : : typedef ::boost::unordered_map < ::rtl::OUString, ProviderDetails , ::rtl::OUStringHash,
53 : : ::std::equal_to< ::rtl::OUString > > ProviderDetails_hash;
54 : :
55 : :
56 : : class ProviderCache
57 : : {
58 : :
59 : : public:
60 : : ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext )
61 : : throw ( css::uno::RuntimeException );
62 : : ProviderCache( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Sequence< css::uno::Any >& scriptContext,
63 : : const css::uno::Sequence< ::rtl::OUString >& blackList )
64 : : throw ( css::uno::RuntimeException );
65 : : ~ProviderCache();
66 : : css::uno::Reference< css::script::provider::XScriptProvider >
67 : : getProvider( const ::rtl::OUString& providerName );
68 : : css::uno::Sequence < css::uno::Reference< css::script::provider::XScriptProvider > >
69 : : getAllProviders() throw ( css::uno::RuntimeException );
70 : : private:
71 : : void populateCache()
72 : : throw ( css::uno::RuntimeException );
73 : :
74 : : css::uno::Reference< css::script::provider::XScriptProvider >
75 : : createProvider( ProviderDetails& details ) throw ( css::uno::RuntimeException );
76 : 21 : bool isInBlackList( const ::rtl::OUString& serviceName )
77 : : {
78 [ - + ]: 21 : if ( m_sBlackList.getLength() > 0 )
79 : : {
80 [ # # ]: 0 : for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ )
81 : : {
82 [ # # ]: 0 : if ( m_sBlackList[ index ].equals( serviceName ) )
83 : : {
84 : 0 : return true;
85 : : }
86 : : }
87 : : }
88 : 21 : return false;
89 : : }
90 : : css::uno::Sequence< ::rtl::OUString > m_sBlackList;
91 : : ProviderDetails_hash m_hProviderDetailsCache;
92 : : osl::Mutex m_mutex;
93 : : css::uno::Sequence< css::uno::Any > m_Sctx;
94 : : css::uno::Reference< css::uno::XComponentContext > m_xContext;
95 : : css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
96 : :
97 : :
98 : : };
99 : : } // func_provider
100 : : #endif
101 : :
102 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|