1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_scripting.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef _VCL_MSGBOX_HXX
32*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "ScriptExecDialog.hrc"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <util/scriptingconstants.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
40*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/EventObject.hpp>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "ScriptNameResolverImpl.hxx"
47*cdf0e10cSrcweir #include "ScriptRuntimeManager.hxx"
48*cdf0e10cSrcweir #include <util/util.hxx>
49*cdf0e10cSrcweir #include <util/scriptingconstants.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir using namespace ::rtl;
52*cdf0e10cSrcweir using namespace ::osl;
53*cdf0e10cSrcweir using namespace ::com::sun::star;
54*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55*cdf0e10cSrcweir using namespace ::drafts::com::sun::star::script::framework;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir namespace scripting_runtimemgr
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir static OUString s_implName = ::rtl::OUString::createFromAscii(
61*cdf0e10cSrcweir  "drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager" );
62*cdf0e10cSrcweir static OUString s_serviceName = ::rtl::OUString::createFromAscii(
63*cdf0e10cSrcweir  "drafts.com.sun.star.script.framework.runtime.ScriptRuntimeManager" );
64*cdf0e10cSrcweir static Sequence< OUString > s_serviceNames = Sequence< OUString >( &s_serviceName, 1 );
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir ::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir //*************************************************************************
69*cdf0e10cSrcweir // ScriptRuntimeManager Constructor
70*cdf0e10cSrcweir ScriptRuntimeManager::ScriptRuntimeManager(
71*cdf0e10cSrcweir     const Reference< XComponentContext > & xContext ) :
72*cdf0e10cSrcweir     m_xContext( xContext, UNO_SET_THROW )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     OSL_TRACE( "< ScriptRuntimeManager ctor called >\n" );
75*cdf0e10cSrcweir     m_xMgr.set( m_xContext->getServiceManager(), UNO_SET_THROW );
76*cdf0e10cSrcweir     s_moduleCount.modCnt.acquire( &s_moduleCount.modCnt );
77*cdf0e10cSrcweir     // test
78*cdf0e10cSrcweir     //scripting_securitymgr::ScriptSecurityManager ssm(xContext);
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir //*************************************************************************
82*cdf0e10cSrcweir // ScriptRuntimeManager Destructor
83*cdf0e10cSrcweir ScriptRuntimeManager::~ScriptRuntimeManager()
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     OSL_TRACE( "< ScriptRuntimeManager dtor called >\n" );
86*cdf0e10cSrcweir     s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir //*************************************************************************
90*cdf0e10cSrcweir // Get the proper XScriptInvocation
91*cdf0e10cSrcweir Reference< runtime::XScriptInvocation > SAL_CALL ScriptRuntimeManager::getScriptRuntime(
92*cdf0e10cSrcweir const Reference< XInterface >& scriptInfo )
93*cdf0e10cSrcweir throw( RuntimeException )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptRuntime\n" );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     Reference< runtime::XScriptInvocation > xScriptInvocation;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     try
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         Reference< XInterface > xInterface;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         Reference< storage::XScriptInfo > sinfo =
104*cdf0e10cSrcweir             Reference< storage::XScriptInfo >( scriptInfo, UNO_QUERY_THROW );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         OUStringBuffer* buf( 80 );
107*cdf0e10cSrcweir         buf.appendAscii("/singletons/drafts.com.sun.star.script.framework.runtime.theScriptRuntimeFor");
108*cdf0e10cSrcweir         buf.append(sinfo->getLanguage());
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         xInterface.set( m_xContext->getValueByName( buf.makeStringAndClear() ), UNO_QUERY_THROW );
111*cdf0e10cSrcweir         xScriptInvocation.set( xInterface, UNO_QUERY_THROW );
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir     catch ( Exception & e )
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptRuntime: " );
116*cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     return xScriptInvocation;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir //*************************************************************************
123*cdf0e10cSrcweir // Get the proper XScriptNameResolver
124*cdf0e10cSrcweir Reference< runtime::XScriptNameResolver > SAL_CALL
125*cdf0e10cSrcweir ScriptRuntimeManager::getScriptNameResolver()
126*cdf0e10cSrcweir throw( RuntimeException )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     OSL_TRACE( "** ==> ScriptRuntimeManager in getScriptNameResolver\n" );
129*cdf0e10cSrcweir     Reference< runtime::XScriptNameResolver > xScriptNameResolver;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     try
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         Reference< XInterface > xInterface(
134*cdf0e10cSrcweir             m_xMgr->createInstanceWithContext(
135*cdf0e10cSrcweir                 OUString::createFromAscii("drafts.com.sun.star.script.framework.runtime.DefaultScriptNameResolver" ),
136*cdf0e10cSrcweir                 m_xContext
137*cdf0e10cSrcweir             ),
138*cdf0e10cSrcweir             UNO_SET_THROW
139*cdf0e10cSrcweir         );
140*cdf0e10cSrcweir         xScriptNameResolver.set( xInterface, UNO_QUERY_THROW );
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir     catch ( Exception & e )
143*cdf0e10cSrcweir     {
144*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::GetScriptNameResolver: " );
145*cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ), Reference< XInterface >() );
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir     return xScriptNameResolver;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir //*************************************************************************
151*cdf0e10cSrcweir // XScriptInvocation implementation
152*cdf0e10cSrcweir Any SAL_CALL ScriptRuntimeManager::invoke(
153*cdf0e10cSrcweir     const ::rtl::OUString & scriptURI,
154*cdf0e10cSrcweir     const Any& invocationCtx, const Sequence< Any >& aParams,
155*cdf0e10cSrcweir     Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
156*cdf0e10cSrcweir     throw ( lang::IllegalArgumentException, script::CannotConvertException,
157*cdf0e10cSrcweir             reflection::InvocationTargetException, RuntimeException )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     OSL_TRACE( "** ==> ScriptRuntimeManager in runtimemgr invoke\n" );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     Any results;
162*cdf0e10cSrcweir     scripting_constants::ScriptingConstantsPool& scriptingConstantsPool =
163*cdf0e10cSrcweir                 scripting_constants::ScriptingConstantsPool::instance();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     // Initialise resolved context with invocation context,
166*cdf0e10cSrcweir     // the resolved context (resolvedCtx will be modified by the
167*cdf0e10cSrcweir     // resolve method to contain the storage where the script code is
168*cdf0e10cSrcweir     // stored
169*cdf0e10cSrcweir     Any resolvedCtx = invocationCtx;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     try
172*cdf0e10cSrcweir     {
173*cdf0e10cSrcweir         Reference< storage::XScriptInfo > resolvedScript = resolve( scriptURI, resolvedCtx );
174*cdf0e10cSrcweir         ENSURE_OR_THROW( resolvedScript.is(), "ScriptRuntimeManager::invoke: No resolvedURI" );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         Reference< beans::XPropertySet > xPropSetResolvedCtx;
177*cdf0e10cSrcweir         if ( sal_False == ( resolvedCtx >>= xPropSetResolvedCtx ) )
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             throw RuntimeException( OUSTR(
180*cdf0e10cSrcweir                 "ScriptRuntimeManager::invoke : unable to get XPropSetScriptingContext from param" ),
181*cdf0e10cSrcweir                 Reference< XInterface > () );
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         Any any = xPropSetResolvedCtx->getPropertyValue(
185*cdf0e10cSrcweir             scriptingConstantsPool.RESOLVED_STORAGE_ID );
186*cdf0e10cSrcweir         sal_Int32 resolvedSid;
187*cdf0e10cSrcweir         if ( sal_False == ( any >>= resolvedSid ) )
188*cdf0e10cSrcweir         {
189*cdf0e10cSrcweir             throw RuntimeException( OUSTR(
190*cdf0e10cSrcweir                 "ScriptRuntimeManager::invoke : unable to get resolved storage id from xPropSetResolvedCtx" ),
191*cdf0e10cSrcweir                 Reference< XInterface > () );
192*cdf0e10cSrcweir         }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         OSL_TRACE("Storage sid is: %d\n", resolvedSid);
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir         // modifying the XPropertySet on the resolved Context to contain the
197*cdf0e10cSrcweir         // full script info
198*cdf0e10cSrcweir         Any aResolvedScript;
199*cdf0e10cSrcweir         aResolvedScript <<= resolvedScript;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         xPropSetResolvedCtx->setPropertyValue( scriptingConstantsPool.SCRIPT_INFO,
202*cdf0e10cSrcweir                 aResolvedScript );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         Reference< runtime::XScriptInvocation > xScriptInvocation =
205*cdf0e10cSrcweir             getScriptRuntime( resolvedScript );
206*cdf0e10cSrcweir         ENSURE_OR_THROW( xScriptInvocation.is(),
207*cdf0e10cSrcweir             "ScriptRuntimeManager::invoke: cannot get instance of language specific runtime." );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         // the scriptURI is currently passed to the language-dept runtime but
210*cdf0e10cSrcweir         // is not used (may be useful in the future?). All of the script info
211*cdf0e10cSrcweir         // is contained as a property(SCRIPT_INFO) within the resolvedCtx
212*cdf0e10cSrcweir         results = xScriptInvocation->invoke( scriptURI, resolvedCtx, aParams,
213*cdf0e10cSrcweir                                              aOutParamIndex, aOutParam );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         // need to dispose of filesystem storage
216*cdf0e10cSrcweir         OUString filesysString = OUString::createFromAscii(
217*cdf0e10cSrcweir                                         "location=filesystem" );
218*cdf0e10cSrcweir         if ( scriptURI.indexOf( filesysString ) != -1 )
219*cdf0e10cSrcweir         {
220*cdf0e10cSrcweir             Any a = m_xContext->getValueByName(
221*cdf0e10cSrcweir                     scriptingConstantsPool.SCRIPTSTORAGEMANAGER_SERVICE );
222*cdf0e10cSrcweir             Reference < lang::XEventListener > xEL_ScriptStorageManager( a, UNO_QUERY_THROW );
223*cdf0e10cSrcweir             lang::EventObject event(resolvedScript);
224*cdf0e10cSrcweir             xEL_ScriptStorageManager->disposing( event );
225*cdf0e10cSrcweir         }
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir     catch ( lang::IllegalArgumentException & iae )
228*cdf0e10cSrcweir     {
229*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke IllegalArgumentException: " );
230*cdf0e10cSrcweir         throw lang::IllegalArgumentException( temp.concat( iae.Message ),
231*cdf0e10cSrcweir                                               Reference< XInterface > (),
232*cdf0e10cSrcweir                                               iae.ArgumentPosition );
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     catch ( script::CannotConvertException & cce )
235*cdf0e10cSrcweir     {
236*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke CannotConvertException: " );
237*cdf0e10cSrcweir         throw script::CannotConvertException( temp.concat( cce.Message ),
238*cdf0e10cSrcweir                                               Reference< XInterface > (),
239*cdf0e10cSrcweir                                               cce.DestinationTypeClass, cce.Reason,
240*cdf0e10cSrcweir                                               cce.ArgumentIndex );
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir     catch ( reflection::InvocationTargetException & ite )
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke InvocationTargetException: " );
245*cdf0e10cSrcweir         throw reflection::InvocationTargetException( temp.concat( ite.Message ),
246*cdf0e10cSrcweir                 Reference< XInterface > (), ite.TargetException );
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir     catch ( beans::UnknownPropertyException & e )
249*cdf0e10cSrcweir     {
250*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke UnknownPropertyException: " );
251*cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ),
252*cdf0e10cSrcweir                                 Reference< XInterface > () );
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir     catch ( lang::WrappedTargetException  & e )
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke WrappedTargetException : " );
257*cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ),
258*cdf0e10cSrcweir                                 Reference< XInterface > () );
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir     catch ( RuntimeException & re )
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke RuntimeException: " );
263*cdf0e10cSrcweir         throw RuntimeException( temp.concat( re.Message ),
264*cdf0e10cSrcweir                                 Reference< XInterface > () );
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir     catch ( Exception & e )
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::invoke Exception: " );
269*cdf0e10cSrcweir         throw RuntimeException( temp.concat( e.Message ),
270*cdf0e10cSrcweir                                 Reference< XInterface > () );
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir #ifdef _DEBUG
273*cdf0e10cSrcweir     catch ( ... )
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         throw RuntimeException( OUSTR( "ScriptRuntimeManager::invoke UnknownException: " ),
276*cdf0e10cSrcweir                                 Reference< XInterface > () );
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir     OSL_TRACE( "** ==> ScriptRuntimeManager returned from invoke: %s\n", ::rtl::OUStringToOString( results.getValueTypeName(),  RTL_TEXTENCODING_ASCII_US ).pData->buffer );
280*cdf0e10cSrcweir     return results;
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir //*************************************************************************
284*cdf0e10cSrcweir // XScriptNameResolver implementation
285*cdf0e10cSrcweir Reference< storage::XScriptInfo > SAL_CALL
286*cdf0e10cSrcweir ScriptRuntimeManager::resolve( const ::rtl::OUString& scriptURI,
287*cdf0e10cSrcweir     Any& invocationCtx )
288*cdf0e10cSrcweir throw( lang::IllegalArgumentException, script::CannotConvertException, RuntimeException )
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir     OSL_TRACE( "** ==> ScriptRuntimeManager in resolve\n" );
291*cdf0e10cSrcweir     Reference< storage::XScriptInfo > resolvedURI;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     Reference< runtime::XScriptNameResolver > xScriptNameResolver = getScriptNameResolver();
294*cdf0e10cSrcweir     ENSURE_OR_THROW( xScriptNameResolver.is(),
295*cdf0e10cSrcweir         "ScriptRuntimeManager::resolve: No ScriptNameResolver" );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     try
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         resolvedURI = xScriptNameResolver->resolve( scriptURI, invocationCtx );
300*cdf0e10cSrcweir     }
301*cdf0e10cSrcweir     catch ( lang::IllegalArgumentException & iae )
302*cdf0e10cSrcweir     {
303*cdf0e10cSrcweir         OUString temp =
304*cdf0e10cSrcweir             OUSTR( "ScriptRuntimeManager::resolve IllegalArgumentException: " );
305*cdf0e10cSrcweir         throw lang::IllegalArgumentException( temp.concat( iae.Message ),
306*cdf0e10cSrcweir                                               Reference< XInterface > (),
307*cdf0e10cSrcweir                                               iae.ArgumentPosition );
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir     catch ( script::CannotConvertException & cce )
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::resolve CannotConvertException: " );
312*cdf0e10cSrcweir         throw script::CannotConvertException( temp.concat( cce.Message ),
313*cdf0e10cSrcweir                                               Reference< XInterface > (),
314*cdf0e10cSrcweir                                               cce.DestinationTypeClass, cce.Reason,
315*cdf0e10cSrcweir                                               cce.ArgumentIndex );
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir     catch ( RuntimeException & re )
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir         OUString temp = OUSTR( "ScriptRuntimeManager::resolve RuntimeException: " );
320*cdf0e10cSrcweir         throw RuntimeException( temp.concat( re.Message ),
321*cdf0e10cSrcweir                                 Reference< XInterface > () );
322*cdf0e10cSrcweir     }
323*cdf0e10cSrcweir #ifdef _DEBUG
324*cdf0e10cSrcweir     catch ( ... )
325*cdf0e10cSrcweir     {
326*cdf0e10cSrcweir         throw RuntimeException(
327*cdf0e10cSrcweir             OUSTR( "ScriptRuntimeManager::resolve UnknownException: " ),
328*cdf0e10cSrcweir             Reference< XInterface > () );
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir #endif
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir     return resolvedURI;
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir //*************************************************************************
336*cdf0e10cSrcweir OUString SAL_CALL ScriptRuntimeManager::getImplementationName( )
337*cdf0e10cSrcweir throw( RuntimeException )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     return s_implName;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //*************************************************************************
343*cdf0e10cSrcweir sal_Bool SAL_CALL ScriptRuntimeManager::supportsService( const OUString& serviceName )
344*cdf0e10cSrcweir throw( RuntimeException )
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     OUString const * pNames = s_serviceNames.getConstArray();
347*cdf0e10cSrcweir     for ( sal_Int32 nPos = s_serviceNames.getLength(); nPos--; )
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         if ( serviceName.equals( pNames[ nPos ] ) )
350*cdf0e10cSrcweir         {
351*cdf0e10cSrcweir             return sal_True;
352*cdf0e10cSrcweir         }
353*cdf0e10cSrcweir     }
354*cdf0e10cSrcweir     return sal_False;
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir //*************************************************************************
358*cdf0e10cSrcweir Sequence<OUString> SAL_CALL ScriptRuntimeManager::getSupportedServiceNames( )
359*cdf0e10cSrcweir throw( RuntimeException )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     return s_serviceNames;
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir //*************************************************************************
365*cdf0e10cSrcweir static Reference< XInterface > SAL_CALL srm_create(
366*cdf0e10cSrcweir     const Reference< XComponentContext > & xCompC )
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir     return ( cppu::OWeakObject * ) new ScriptRuntimeManager( xCompC );
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir //*************************************************************************
372*cdf0e10cSrcweir static Sequence<OUString> srm_getSupportedServiceNames( )
373*cdf0e10cSrcweir SAL_THROW( () )
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     return s_serviceNames;
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //*************************************************************************
379*cdf0e10cSrcweir static OUString srm_getImplementationName( )
380*cdf0e10cSrcweir SAL_THROW( () )
381*cdf0e10cSrcweir {
382*cdf0e10cSrcweir     return s_implName;
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir //*************************************************************************
386*cdf0e10cSrcweir Reference< XInterface > SAL_CALL scriptnri_create(
387*cdf0e10cSrcweir     Reference< XComponentContext > const & xComponentContext )
388*cdf0e10cSrcweir SAL_THROW( ( Exception ) );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir //*************************************************************************
391*cdf0e10cSrcweir Sequence< OUString > scriptnri_getSupportedServiceNames() SAL_THROW( () );
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir //*************************************************************************
394*cdf0e10cSrcweir OUString scriptnri_getImplementationName() SAL_THROW( () );
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir //******************** ScriptStorageMangaer defines ***********************
397*cdf0e10cSrcweir Reference< XInterface > SAL_CALL ssm_create(
398*cdf0e10cSrcweir     Reference< XComponentContext > const & xComponentContext )
399*cdf0e10cSrcweir SAL_THROW( ( Exception ) );
400*cdf0e10cSrcweir //*************************************************************************
401*cdf0e10cSrcweir Sequence< OUString > ssm_getSupportedServiceNames() SAL_THROW( () );
402*cdf0e10cSrcweir //*************************************************************************
403*cdf0e10cSrcweir OUString ssm_getImplementationName() SAL_THROW( () );
404*cdf0e10cSrcweir //*************************************************************************
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir //************ Script Provider defines ************************************
407*cdf0e10cSrcweir Reference< XInterface > SAL_CALL sp_create( const Reference< XComponentContext > & xCompC );
408*cdf0e10cSrcweir //******************** ScriptProvider defines ***************************
409*cdf0e10cSrcweir Sequence< OUString > sp_getSupportedServiceNames( ) SAL_THROW( () );
410*cdf0e10cSrcweir //*************************************************************************
411*cdf0e10cSrcweir OUString sp_getImplementationName( ) SAL_THROW( () );
412*cdf0e10cSrcweir //*************************************************************************
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir //************ ScriptStorage defines **************************************
415*cdf0e10cSrcweir Reference< XInterface > SAL_CALL ss_create( const Reference< XComponentContext > & xCompC );
416*cdf0e10cSrcweir //******************** ScriptProvider defines ***************************
417*cdf0e10cSrcweir Sequence< OUString > ss_getSupportedServiceNames( ) SAL_THROW( () );
418*cdf0e10cSrcweir //*************************************************************************
419*cdf0e10cSrcweir OUString ss_getImplementationName( ) SAL_THROW( () );
420*cdf0e10cSrcweir //*************************************************************************
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir static struct cppu::ImplementationEntry s_entries [] =
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         {
426*cdf0e10cSrcweir             srm_create, srm_getImplementationName,
427*cdf0e10cSrcweir             srm_getSupportedServiceNames, cppu::createSingleComponentFactory,
428*cdf0e10cSrcweir             &s_moduleCount.modCnt, 0
429*cdf0e10cSrcweir         },
430*cdf0e10cSrcweir         {
431*cdf0e10cSrcweir             scriptnri_create, scriptnri_getImplementationName,
432*cdf0e10cSrcweir             scriptnri_getSupportedServiceNames, cppu::createSingleComponentFactory,
433*cdf0e10cSrcweir             &s_moduleCount.modCnt, 0
434*cdf0e10cSrcweir         },
435*cdf0e10cSrcweir         {
436*cdf0e10cSrcweir             ssm_create, ssm_getImplementationName,
437*cdf0e10cSrcweir             ssm_getSupportedServiceNames, cppu::createSingleComponentFactory,
438*cdf0e10cSrcweir             0, 0
439*cdf0e10cSrcweir         },
440*cdf0e10cSrcweir         {
441*cdf0e10cSrcweir             ss_create, ss_getImplementationName,
442*cdf0e10cSrcweir             ss_getSupportedServiceNames, cppu::createSingleComponentFactory,
443*cdf0e10cSrcweir             0, 0
444*cdf0e10cSrcweir         },
445*cdf0e10cSrcweir         {
446*cdf0e10cSrcweir             sp_create, sp_getImplementationName,
447*cdf0e10cSrcweir             sp_getSupportedServiceNames, cppu::createSingleComponentFactory,
448*cdf0e10cSrcweir             0, 0
449*cdf0e10cSrcweir         },
450*cdf0e10cSrcweir         { 0, 0, 0, 0, 0, 0 }
451*cdf0e10cSrcweir     };
452*cdf0e10cSrcweir } // Namespace
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir //#######################################################################################
455*cdf0e10cSrcweir //#### EXPORTED #########################################################################
456*cdf0e10cSrcweir //#######################################################################################
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir /**
459*cdf0e10cSrcweir  * Gives the environment this component belongs to.
460*cdf0e10cSrcweir  */
461*cdf0e10cSrcweir extern "C"
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir     void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName,
464*cdf0e10cSrcweir         uno_Environment ** ppEnv )
465*cdf0e10cSrcweir     {
466*cdf0e10cSrcweir         *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
467*cdf0e10cSrcweir     }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     /**
470*cdf0e10cSrcweir      * This function is called to get service factories for an implementation.
471*cdf0e10cSrcweir      *
472*cdf0e10cSrcweir      * @param pImplName       name of implementation
473*cdf0e10cSrcweir      * @param pServiceManager a service manager, need for component creation
474*cdf0e10cSrcweir      * @param pRegistryKey    the registry key for this component, need for persistent
475*cdf0e10cSrcweir      *                        data
476*cdf0e10cSrcweir      * @return a component factory
477*cdf0e10cSrcweir      */
478*cdf0e10cSrcweir     void * SAL_CALL component_getFactory( const sal_Char * pImplName,
479*cdf0e10cSrcweir         lang::XMultiServiceFactory * pServiceManager,
480*cdf0e10cSrcweir         registry::XRegistryKey * pRegistryKey )
481*cdf0e10cSrcweir     {
482*cdf0e10cSrcweir         return ::cppu::component_getFactoryHelper( pImplName, pServiceManager,
483*cdf0e10cSrcweir             pRegistryKey, ::scripting_runtimemgr::s_entries );
484*cdf0e10cSrcweir     }
485*cdf0e10cSrcweir }
486