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_FUNCTIONIMPL_HXX_
29 #define  _FRAMEWORK_SCRIPT_PROVIDER_FUNCTIONIMPL_HXX_
30 
31 #include <cppuhelper/implbase1.hxx> // helper for XInterface, XTypeProvider etc.
32 #include <osl/mutex.hxx>
33 
34 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 #include <com/sun/star/uno/RuntimeException.hpp>
36 #include <com/sun/star/script/CannotConvertException.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/reflection/InvocationTargetException.hpp>
39 
40 #include <drafts/com/sun/star/script/framework/provider/XScript.hpp>
41 #include <drafts/com/sun/star/script/framework/runtime/XScriptInvocation.hpp>
42 
43 namespace func_provider
44 {
45 // for simplification
46 #define css ::com::sun::star
47 #define dcsssf ::drafts::com::sun::star::script::framework
48 
49 
50 class ScriptImpl :
51             public ::cppu::WeakImplHelper1 < dcsssf::provider::XScript >
52 {
53 
54 public:
55     /*************************************************************
56       ScriptImpl Constructor
57       @param runtimeMgr which is a service that implement a XScriptInvocation
58       @param scriptURI the received ScriptURI that needs to be resolve and invoked
59     */
60     ScriptImpl(
61         const css::uno::Reference< css::beans::XPropertySet > & scriptingContext,
62         const css::uno::Reference< dcsssf::runtime::XScriptInvocation > & runtimeMgr,
63         const ::rtl::OUString& scriptURI )
64     throw ( css::uno::RuntimeException );
65 
66     /*************************************************************
67       ScriptImpl Destructor
68     */
69     ~ScriptImpl();
70 
71     /*************************************************************
72       Invoke
73       @param aParams all parameters; pure, out params are undefined in sequence,
74         i.e., the value has to be ignored by the callee
75       @param aOutParamIndex out indices
76       @param aOutParam out parameters
77 
78       @returns
79             the value returned from the function being invoked
80 
81       @throws IllegalArgumentException
82             if there is no matching script name
83 
84       @throws CannotConvertException
85             if args do not match or cannot be converted the those
86             of the invokee
87 
88       @throws InvocationTargetException
89             if the running script throws an exception this information is captured and
90             rethrown as this exception type.
91 
92     */
93     virtual css::uno::Any SAL_CALL invoke(
94         const css::uno::Sequence< css::uno::Any > & aParams,
95         css::uno::Sequence< sal_Int16 > & aOutParamIndex,
96         css::uno::Sequence< css::uno::Any > & aOutParam )
97     throw ( css::lang::IllegalArgumentException,
98             css::script::CannotConvertException,
99             css::reflection::InvocationTargetException,
100             css::uno::RuntimeException );
101 
102 private:
103     css::uno::Reference< css::beans::XPropertySet > m_XScriptingContext;
104     css::uno::Reference < dcsssf::runtime::XScriptInvocation > m_RunTimeManager;
105     ::rtl::OUString m_ScriptURI;
106 
107     /* copy ctor disabled, i.e. not defined */
108     ScriptImpl( const ScriptImpl& );
109     /* assignment disabled,  i.e. not defined */
110     ScriptImpl& operator = ( const ScriptImpl& );
111 };
112 } // namespace func_provider
113 #endif //_FRAMEWORK_SCRIPT_PROVIDER_FUNCTIONIMPL_HXX_
114