Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / scripting / source / provider / MasterScriptProvider.hxx
blobc0bd17674eca7ee0c5b22673cfd07c8eb5745c90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SCRIPTING_SOURCE_PROVIDER_MASTERSCRIPTPROVIDER_HXX
21 #define INCLUDED_SCRIPTING_SOURCE_PROVIDER_MASTERSCRIPTPROVIDER_HXX
23 #include <rtl/ustring.hxx>
25 #include <cppuhelper/implbase.hxx>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/uno/RuntimeException.hpp>
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/document/XScriptInvocationContext.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/script/provider/XScriptProvider.hpp>
36 #include <com/sun/star/script/browse/XBrowseNode.hpp>
38 #include "ProviderCache.hxx"
39 #include <memory>
41 namespace func_provider
44 typedef ::cppu::WeakImplHelper<
45 css::script::provider::XScriptProvider,
46 css::script::browse::XBrowseNode, css::lang::XServiceInfo,
47 css::lang::XInitialization,
48 css::container::XNameContainer > t_helper;
50 class MasterScriptProvider :
51 public t_helper
53 public:
54 /// @throws css::uno::RuntimeException
55 explicit MasterScriptProvider(
56 const css::uno::Reference< css::uno::XComponentContext >
57 & xContext );
58 virtual ~MasterScriptProvider() override;
60 // XServiceInfo implementation
61 virtual OUString SAL_CALL getImplementationName( ) override;
63 // XBrowseNode implementation
64 virtual OUString SAL_CALL getName() override;
65 virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() override;
66 virtual sal_Bool SAL_CALL hasChildNodes() override;
67 virtual sal_Int16 SAL_CALL getType() override;
68 // XNameContainer
69 virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
70 virtual void SAL_CALL removeByName( const OUString& Name ) override;
72 // XNameReplace
73 virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
74 // XNameAccess
75 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
76 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
77 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
79 // XElementAccess
80 virtual css::uno::Type SAL_CALL getElementType( ) override;
81 virtual sal_Bool SAL_CALL hasElements( ) override;
82 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
83 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
85 // XScriptProvider implementation
86 virtual css::uno::Reference < css::script::provider::XScript > SAL_CALL
87 getScript( const OUString& scriptURI ) override;
89 /**
90 * XInitialise implementation
92 * @param args expected to contain a single OUString
93 * containing the URI
95 virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any > & args ) override;
97 // returns context string for this provider, eg
98 const OUString& getContextString() const { return m_sCtxString; }
100 private:
101 static OUString parseLocationName( const OUString& location );
102 void createPkgProvider();
104 ProviderCache* providerCache();
105 /* to obtain other services if needed */
106 css::uno::Reference< css::uno::XComponentContext > m_xContext;
107 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr;
108 css::uno::Reference< css::frame::XModel > m_xModel;
109 css::uno::Reference< css::document::XScriptInvocationContext > m_xInvocationContext;
110 css::uno::Sequence< css::uno::Any > m_sAargs;
111 OUString m_sNodeName;
113 // This component supports XInitialization, it can be created
114 // using createInstanceXXX() or createInstanceWithArgumentsXXX using
115 // the service Manager.
116 // Need to detect proper initialisation and validity
117 // for the object, so m_bIsValid indicates that the object is valid is set in ctor
118 // in case of createInstanceWithArgumentsXXX() called m_bIsValid is set to reset
119 // and then set to true when initialisation is complete
120 bool m_bIsValid;
121 // m_bInitialised ensure initialisation only takes place once.
122 bool m_bInitialised;
123 bool m_bIsPkgMSP;
124 css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg;
125 std::unique_ptr<ProviderCache> m_pPCache;
126 osl::Mutex m_mutex;
127 OUString m_sCtxString;
130 OUString mspf_getImplementationName() ;
131 css::uno::Reference< css::uno::XInterface > mspf_create( css::uno::Reference< css::uno::XComponentContext > const & xComponentContext );
132 css::uno::Sequence< OUString > mspf_getSupportedServiceNames();
136 namespace browsenodefactory
138 OUString bnf_getImplementationName() ;
139 css::uno::Reference< css::uno::XInterface > bnf_create( css::uno::Reference< css::uno::XComponentContext > const & xComponentContext );
140 css::uno::Sequence< OUString > bnf_getSupportedServiceNames();
143 #endif // INCLUDED_SCRIPTING_SOURCE_PROVIDER_MASTERSCRIPTPROVIDER_HXX
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */