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 29 #ifndef _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 30 #define _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 31 32 #include <osl/mutex.hxx> 33 34 #include <cppuhelper/implbase3.hxx> 35 #include <com/sun/star/lang/XServiceInfo.hpp> 36 37 #include <com/sun/star/lang/IllegalArgumentException.hpp> 38 #include <com/sun/star/uno/RuntimeException.hpp> 39 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 40 #include <com/sun/star/script/CannotConvertException.hpp> 41 #include <com/sun/star/reflection/InvocationTargetException.hpp> 42 43 #include <drafts/com/sun/star/script/framework/runtime/XScriptInvocation.hpp> 44 #include <drafts/com/sun/star/script/framework/runtime/XScriptNameResolver.hpp> 45 46 namespace scripting_runtimemgr 47 { 48 // for simplification 49 #define css ::com::sun::star 50 #define dcsssf ::drafts::com::sun::star::script::framework 51 52 /** 53 * Class responsible for managing the various ScriptRuntime implementations. 54 */ 55 class ScriptRuntimeManager : public 56 ::cppu::WeakImplHelper3< dcsssf::runtime::XScriptInvocation, css::lang::XServiceInfo, 57 dcsssf::runtime::XScriptNameResolver > 58 { 59 public: 60 explicit ScriptRuntimeManager( 61 const css::uno::Reference< css::uno::XComponentContext > & xContext ); 62 ~ScriptRuntimeManager(); 63 64 65 // XServiceInfo implementation 66 virtual ::rtl::OUString SAL_CALL getImplementationName() 67 throw( css::uno::RuntimeException ); 68 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 69 throw( css::uno::RuntimeException ); 70 virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 71 throw( css::uno::RuntimeException ); 72 73 /** 74 * implements XScriptInvocation, invokes the script named in scriptURI 75 * (resolving it first, if necessary), with the args passed. 76 * 77 * @param scriptURI the URI, which may not be fully qualified, for the 78 * script to be invoked 79 * 80 ************************************************************* 81 Invoke 82 @param scriptUri script uri describing the script 83 @param invocationCtx 84 the invocation context contains the documentStorageID and document reference 85 for use in script name resolving 86 87 @param aParams all parameters; pure, out params are undefined in sequence, 88 i.e., the value has to be ignored by the callee 89 @param aOutParamIndex out indices 90 @param aOutParam out parameters 91 92 @returns 93 the value returned from the function being invoked 94 95 @throws IllegalArgumentException 96 if there is no matching script name 97 98 @throws CannotConvertException 99 if args do not match or cannot be converted the those 100 of the invokee 101 102 @throws InvocationTargetException 103 if the running script throws an exception this information is captured and 104 rethrown as this exception type. 105 106 */ 107 virtual css::uno::Any SAL_CALL invoke( 108 const ::rtl::OUString & scriptUri, 109 const css::uno::Any& invocationCtx, 110 const css::uno::Sequence< css::uno::Any >& aParams, 111 css::uno::Sequence< sal_Int16 >& aOutParamIndex, 112 css::uno::Sequence< css::uno::Any >& aOutParam ) 113 throw ( css::lang::IllegalArgumentException, 114 css::script::CannotConvertException, 115 css::reflection::InvocationTargetException, 116 css::uno::RuntimeException ); 117 118 /** 119 * implements XScriptNameResolver, attempts to resolve the script URI 120 * passed in 121 * 122 * @param scriptURI the URI to be resolved 123 * @param invocationCtx the invocation context contains the 124 * documentStorageID and document reference for use in script name 125 * resolving. On full name resolution it sets the resolvedScriptStorageID to 126 * the actual storage location of the fully resolved script. May or may not * be the 127 same as the documentStorageID. 128 * @return the resolved URI 129 */ 130 virtual css::uno::Reference< dcsssf::storage::XScriptInfo > SAL_CALL resolve( 131 const ::rtl::OUString& scriptUri, 132 css::uno::Any& invocationCtx ) 133 throw( css::lang::IllegalArgumentException, css::script::CannotConvertException, 134 css::uno::RuntimeException ); 135 136 private: 137 css::uno::Reference< dcsssf::runtime::XScriptInvocation > SAL_CALL getScriptRuntime( 138 const css::uno::Reference< css::uno::XInterface > & scriptInfo ) 139 throw( css::uno::RuntimeException ); 140 css::uno::Reference< dcsssf::runtime::XScriptNameResolver > SAL_CALL getScriptNameResolver() 141 throw( css::uno::RuntimeException ); 142 143 css::uno::Reference< css::uno::XComponentContext > m_xContext; 144 css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 145 ::osl::Mutex m_mutex; 146 }; 147 } // scripting_runtimemgr 148 149 #endif //_FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 150