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