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