1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ 25 #define _FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ 26 27 #include <rtl/ustring.hxx> 28 29 #include <cppuhelper/implbase5.hxx> 30 31 #include <com/sun/star/lang/XServiceInfo.hpp> 32 #include <com/sun/star/uno/RuntimeException.hpp> 33 #include <com/sun/star/container/XNameContainer.hpp> 34 #include <com/sun/star/document/XScriptInvocationContext.hpp> 35 36 #include <com/sun/star/lang/XInitialization.hpp> 37 38 #include <com/sun/star/script/provider/XScriptProvider.hpp> 39 #include <com/sun/star/script/browse/XBrowseNode.hpp> 40 41 #include "ProviderCache.hxx" 42 43 namespace func_provider 44 { 45 // for simplification 46 #define css ::com::sun::star 47 48 typedef ::cppu::WeakImplHelper5< 49 css::script::provider::XScriptProvider, 50 css::script::browse::XBrowseNode, css::lang::XServiceInfo, 51 css::lang::XInitialization, 52 css::container::XNameContainer > t_helper; 53 54 class MasterScriptProvider : 55 public t_helper 56 { 57 public: 58 MasterScriptProvider( 59 const css::uno::Reference< css::uno::XComponentContext > 60 & xContext ); 61 ~MasterScriptProvider(); 62 63 // XServiceInfo implementation 64 virtual ::rtl::OUString SAL_CALL getImplementationName( ); 65 66 // XBrowseNode implementation 67 virtual ::rtl::OUString SAL_CALL getName(); 68 virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes(); 69 virtual sal_Bool SAL_CALL hasChildNodes(); 70 virtual sal_Int16 SAL_CALL getType(); 71 // XNameContainer 72 virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ); 73 virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ); 74 75 // XNameReplace 76 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ); 77 // XNameAccess 78 virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ); 79 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ); 80 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ); 81 82 // XElementAccess 83 virtual css::uno::Type SAL_CALL getElementType( ); 84 virtual sal_Bool SAL_CALL hasElements( ); 85 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ); 86 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ); 87 88 // XScriptProvider implementation 89 virtual css::uno::Reference < css::script::provider::XScript > SAL_CALL 90 getScript( const ::rtl::OUString& scriptURI ); 91 92 /** 93 * XInitialise implementation 94 * 95 * @param args expected to contain a single ::rtl::OUString 96 * containing the URI 97 */ 98 virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any > & args ); 99 100 // Public method to return all Language Providers in this MasterScriptProviders 101 // context. 102 css::uno::Sequence< css::uno::Reference< css::script::provider::XScriptProvider > > SAL_CALL 103 getAllProviders(); 104 isPkgProvider()105 bool isPkgProvider() { return m_bIsPkgMSP; } getPkgProvider()106 css::uno::Reference< css::script::provider::XScriptProvider > getPkgProvider() { return m_xMSPPkg; } 107 // returns context string for this provider, eg getContextString()108 ::rtl::OUString getContextString() { return m_sCtxString; } 109 110 private: 111 ::rtl::OUString parseLocationName( const ::rtl::OUString& location ); 112 void createPkgProvider(); 113 bool isValid(); 114 ::rtl::OUString getURLForModel(); 115 const css::uno::Sequence< ::rtl::OUString >& getProviderNames(); 116 117 ProviderCache* providerCache(); 118 /* to obtain other services if needed */ 119 css::uno::Reference< css::uno::XComponentContext > m_xContext; 120 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 121 css::uno::Reference< css::frame::XModel > m_xModel; 122 css::uno::Reference< css::document::XScriptInvocationContext > m_xInvocationContext; 123 css::uno::Sequence< css::uno::Any > m_sAargs; 124 ::rtl::OUString m_sNodeName; 125 126 // This component supports XInitialization, it can be created 127 // using createInstanceXXX() or createInstanceWithArgumentsXXX using 128 // the service Manager. 129 // Need to detect proper initialisation and validity 130 // for the object, so m_bIsValid indicates that the object is valid is set in ctor 131 // in case of createInstanceWithArgumentsXXX() called m_bIsValid is set to reset 132 // and then set to true when initialisation is complete 133 bool m_bIsValid; 134 // m_bInitialised ensure initialisation only takes place once. 135 bool m_bInitialised; 136 bool m_bIsPkgMSP; 137 css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg; 138 ProviderCache* m_pPCache; 139 osl::Mutex m_mutex; 140 ::rtl::OUString m_sCtxString; 141 }; 142 } // namespace func_provider 143 #endif //_FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ 144