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_XFUNCTIONPROVIDER_HXX_ 29 #define _FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ 30 31 #include <rtl/ustring.hxx> 32 33 #include <cppuhelper/implbase5.hxx> 34 35 #include <com/sun/star/lang/XServiceInfo.hpp> 36 #include <com/sun/star/uno/RuntimeException.hpp> 37 #include <com/sun/star/container/XNameContainer.hpp> 38 #include <com/sun/star/document/XScriptInvocationContext.hpp> 39 40 #include <com/sun/star/lang/XInitialization.hpp> 41 42 #include <com/sun/star/script/provider/XScriptProvider.hpp> 43 #include <com/sun/star/script/browse/XBrowseNode.hpp> 44 45 #include "ProviderCache.hxx" 46 47 namespace func_provider 48 { 49 // for simplification 50 #define css ::com::sun::star 51 52 typedef ::cppu::WeakImplHelper5< 53 css::script::provider::XScriptProvider, 54 css::script::browse::XBrowseNode, css::lang::XServiceInfo, 55 css::lang::XInitialization, 56 css::container::XNameContainer > t_helper; 57 58 class MasterScriptProvider : 59 public t_helper 60 { 61 public: 62 MasterScriptProvider( 63 const css::uno::Reference< css::uno::XComponentContext > 64 & xContext ) throw( css::uno::RuntimeException ); 65 ~MasterScriptProvider(); 66 67 // XServiceInfo implementation 68 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 69 throw( css::uno::RuntimeException ); 70 71 // XBrowseNode implementation 72 virtual ::rtl::OUString SAL_CALL getName() 73 throw ( css::uno::RuntimeException ); 74 virtual css::uno::Sequence< css::uno::Reference< css::script::browse::XBrowseNode > > SAL_CALL getChildNodes() 75 throw ( css::uno::RuntimeException ); 76 virtual sal_Bool SAL_CALL hasChildNodes() 77 throw ( css::uno::RuntimeException ); 78 virtual sal_Int16 SAL_CALL getType() 79 throw ( css::uno::RuntimeException ); 80 // XNameContainer 81 virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ) throw ( css::lang::IllegalArgumentException, css::container::ElementExistException, css::lang::WrappedTargetException, css::uno::RuntimeException); 82 virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); 83 84 // XNameReplace 85 virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const css::uno::Any& aElement ) throw ( css::lang::IllegalArgumentException, css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); 86 // XNameAccess 87 virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw ( css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); 88 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw ( css::uno::RuntimeException); 89 virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException); 90 91 // XElementAccess 92 virtual css::uno::Type SAL_CALL getElementType( ) throw ( css::uno::RuntimeException); 93 virtual sal_Bool SAL_CALL hasElements( ) throw ( css::uno::RuntimeException); 94 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 95 throw( css::uno::RuntimeException ); 96 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 97 throw( css::uno::RuntimeException ); 98 99 // XScriptProvider implementation 100 virtual css::uno::Reference < css::script::provider::XScript > SAL_CALL 101 getScript( const ::rtl::OUString& scriptURI ) 102 throw( css::script::provider::ScriptFrameworkErrorException, 103 css::uno::RuntimeException ); 104 105 /** 106 * XInitialise implementation 107 * 108 * @param args expected to contain a single ::rtl::OUString 109 * containing the URI 110 */ 111 virtual void SAL_CALL initialize( const css::uno::Sequence < css::uno::Any > & args ) 112 throw ( css::uno::Exception, css::uno::RuntimeException); 113 114 // Public method to return all Language Providers in this MasterScriptProviders 115 // context. 116 css::uno::Sequence< css::uno::Reference< css::script::provider::XScriptProvider > > SAL_CALL 117 getAllProviders() throw ( css::uno::RuntimeException ); 118 119 bool isPkgProvider() { return m_bIsPkgMSP; } 120 css::uno::Reference< css::script::provider::XScriptProvider > getPkgProvider() { return m_xMSPPkg; } 121 // returns context string for this provider, eg 122 ::rtl::OUString getContextString() { return m_sCtxString; } 123 124 private: 125 ::rtl::OUString parseLocationName( const ::rtl::OUString& location ); 126 void createPkgProvider(); 127 bool isValid(); 128 ::rtl::OUString getURLForModel(); 129 const css::uno::Sequence< ::rtl::OUString >& getProviderNames(); 130 131 ProviderCache* providerCache(); 132 /* to obtain other services if needed */ 133 css::uno::Reference< css::uno::XComponentContext > m_xContext; 134 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 135 css::uno::Reference< css::frame::XModel > m_xModel; 136 css::uno::Reference< css::document::XScriptInvocationContext > m_xInvocationContext; 137 css::uno::Sequence< css::uno::Any > m_sAargs; 138 ::rtl::OUString m_sNodeName; 139 140 // This component supports XInitialization, it can be created 141 // using createInstanceXXX() or createInstanceWithArgumentsXXX using 142 // the service Mangager. 143 // Need to detect proper initialisation and validity 144 // for the object, so m_bIsValid indicates that the object is valid is set in ctor 145 // in case of createInstanceWithArgumentsXXX() called m_bIsValid is set to reset 146 // and then set to true when initialisation is complete 147 bool m_bIsValid; 148 // m_bInitialised ensure initialisation only takes place once. 149 bool m_bInitialised; 150 bool m_bIsPkgMSP; 151 css::uno::Reference< css::script::provider::XScriptProvider > m_xMSPPkg; 152 ProviderCache* m_pPCache; 153 osl::Mutex m_mutex; 154 ::rtl::OUString m_sCtxString; 155 }; 156 } // namespace func_provider 157 #endif //_FRAMEWORK_SCRIPT_PROVIDER_XFUNCTIONPROVIDER_HXX_ 158