1*6998d047SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6998d047SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6998d047SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6998d047SAndrew Rist * distributed with this work for additional information 6*6998d047SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6998d047SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6998d047SAndrew Rist * "License"); you may not use this file except in compliance 9*6998d047SAndrew Rist * with the License. You may obtain a copy of the License at 10*6998d047SAndrew Rist * 11*6998d047SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6998d047SAndrew Rist * 13*6998d047SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6998d047SAndrew Rist * software distributed under the License is distributed on an 15*6998d047SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6998d047SAndrew Rist * KIND, either express or implied. See the License for the 17*6998d047SAndrew Rist * specific language governing permissions and limitations 18*6998d047SAndrew Rist * under the License. 19*6998d047SAndrew Rist * 20*6998d047SAndrew Rist *************************************************************/ 21*6998d047SAndrew Rist 22*6998d047SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #ifndef _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 26cdf0e10cSrcweir #define _FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 34cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 35cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 36cdf0e10cSrcweir #include <com/sun/star/script/CannotConvertException.hpp> 37cdf0e10cSrcweir #include <com/sun/star/reflection/InvocationTargetException.hpp> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/runtime/XScriptInvocation.hpp> 40cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/runtime/XScriptNameResolver.hpp> 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace scripting_runtimemgr 43cdf0e10cSrcweir { 44cdf0e10cSrcweir // for simplification 45cdf0e10cSrcweir #define css ::com::sun::star 46cdf0e10cSrcweir #define dcsssf ::drafts::com::sun::star::script::framework 47cdf0e10cSrcweir 48cdf0e10cSrcweir /** 49cdf0e10cSrcweir * Class responsible for managing the various ScriptRuntime implementations. 50cdf0e10cSrcweir */ 51cdf0e10cSrcweir class ScriptRuntimeManager : public 52cdf0e10cSrcweir ::cppu::WeakImplHelper3< dcsssf::runtime::XScriptInvocation, css::lang::XServiceInfo, 53cdf0e10cSrcweir dcsssf::runtime::XScriptNameResolver > 54cdf0e10cSrcweir { 55cdf0e10cSrcweir public: 56cdf0e10cSrcweir explicit ScriptRuntimeManager( 57cdf0e10cSrcweir const css::uno::Reference< css::uno::XComponentContext > & xContext ); 58cdf0e10cSrcweir ~ScriptRuntimeManager(); 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir // XServiceInfo implementation 62cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() 63cdf0e10cSrcweir throw( css::uno::RuntimeException ); 64cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 65cdf0e10cSrcweir throw( css::uno::RuntimeException ); 66cdf0e10cSrcweir virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() 67cdf0e10cSrcweir throw( css::uno::RuntimeException ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir /** 70cdf0e10cSrcweir * implements XScriptInvocation, invokes the script named in scriptURI 71cdf0e10cSrcweir * (resolving it first, if necessary), with the args passed. 72cdf0e10cSrcweir * 73cdf0e10cSrcweir * @param scriptURI the URI, which may not be fully qualified, for the 74cdf0e10cSrcweir * script to be invoked 75cdf0e10cSrcweir * 76cdf0e10cSrcweir ************************************************************* 77cdf0e10cSrcweir Invoke 78cdf0e10cSrcweir @param scriptUri script uri describing the script 79cdf0e10cSrcweir @param invocationCtx 80cdf0e10cSrcweir the invocation context contains the documentStorageID and document reference 81cdf0e10cSrcweir for use in script name resolving 82cdf0e10cSrcweir 83cdf0e10cSrcweir @param aParams all parameters; pure, out params are undefined in sequence, 84cdf0e10cSrcweir i.e., the value has to be ignored by the callee 85cdf0e10cSrcweir @param aOutParamIndex out indices 86cdf0e10cSrcweir @param aOutParam out parameters 87cdf0e10cSrcweir 88cdf0e10cSrcweir @returns 89cdf0e10cSrcweir the value returned from the function being invoked 90cdf0e10cSrcweir 91cdf0e10cSrcweir @throws IllegalArgumentException 92cdf0e10cSrcweir if there is no matching script name 93cdf0e10cSrcweir 94cdf0e10cSrcweir @throws CannotConvertException 95cdf0e10cSrcweir if args do not match or cannot be converted the those 96cdf0e10cSrcweir of the invokee 97cdf0e10cSrcweir 98cdf0e10cSrcweir @throws InvocationTargetException 99cdf0e10cSrcweir if the running script throws an exception this information is captured and 100cdf0e10cSrcweir rethrown as this exception type. 101cdf0e10cSrcweir 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir virtual css::uno::Any SAL_CALL invoke( 104cdf0e10cSrcweir const ::rtl::OUString & scriptUri, 105cdf0e10cSrcweir const css::uno::Any& invocationCtx, 106cdf0e10cSrcweir const css::uno::Sequence< css::uno::Any >& aParams, 107cdf0e10cSrcweir css::uno::Sequence< sal_Int16 >& aOutParamIndex, 108cdf0e10cSrcweir css::uno::Sequence< css::uno::Any >& aOutParam ) 109cdf0e10cSrcweir throw ( css::lang::IllegalArgumentException, 110cdf0e10cSrcweir css::script::CannotConvertException, 111cdf0e10cSrcweir css::reflection::InvocationTargetException, 112cdf0e10cSrcweir css::uno::RuntimeException ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir /** 115cdf0e10cSrcweir * implements XScriptNameResolver, attempts to resolve the script URI 116cdf0e10cSrcweir * passed in 117cdf0e10cSrcweir * 118cdf0e10cSrcweir * @param scriptURI the URI to be resolved 119cdf0e10cSrcweir * @param invocationCtx the invocation context contains the 120cdf0e10cSrcweir * documentStorageID and document reference for use in script name 121cdf0e10cSrcweir * resolving. On full name resolution it sets the resolvedScriptStorageID to 122cdf0e10cSrcweir * the actual storage location of the fully resolved script. May or may not * be the 123cdf0e10cSrcweir same as the documentStorageID. 124cdf0e10cSrcweir * @return the resolved URI 125cdf0e10cSrcweir */ 126cdf0e10cSrcweir virtual css::uno::Reference< dcsssf::storage::XScriptInfo > SAL_CALL resolve( 127cdf0e10cSrcweir const ::rtl::OUString& scriptUri, 128cdf0e10cSrcweir css::uno::Any& invocationCtx ) 129cdf0e10cSrcweir throw( css::lang::IllegalArgumentException, css::script::CannotConvertException, 130cdf0e10cSrcweir css::uno::RuntimeException ); 131cdf0e10cSrcweir 132cdf0e10cSrcweir private: 133cdf0e10cSrcweir css::uno::Reference< dcsssf::runtime::XScriptInvocation > SAL_CALL getScriptRuntime( 134cdf0e10cSrcweir const css::uno::Reference< css::uno::XInterface > & scriptInfo ) 135cdf0e10cSrcweir throw( css::uno::RuntimeException ); 136cdf0e10cSrcweir css::uno::Reference< dcsssf::runtime::XScriptNameResolver > SAL_CALL getScriptNameResolver() 137cdf0e10cSrcweir throw( css::uno::RuntimeException ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > m_xContext; 140cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiComponentFactory > m_xMgr; 141cdf0e10cSrcweir ::osl::Mutex m_mutex; 142cdf0e10cSrcweir }; 143cdf0e10cSrcweir } // scripting_runtimemgr 144cdf0e10cSrcweir 145cdf0e10cSrcweir #endif //_FRAMEWORK_SCRIPT_SCRIPTRUNTIMEMANAGER_HXX_ 146