#i18767# integration of Starbasic runtime to ScriptingFramework provider
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
tc scripting : bridges rdbmaker vcl NULL
|
||||
tc scripting : bridges rdbmaker vcl basic sfx2 NULL
|
||||
tc scripting usr1 - all tc_mkout NULL
|
||||
tc scripting\source\storage nmake - all tc_scriptingstorage NULL
|
||||
tc scripting\source\provider nmake - all tc_scriptingprovider tc_scriptingstorage NULL
|
||||
tc scripting\source\basprov nmake - all tc_scriptingbasprov NULL
|
||||
tc scripting\source\protocolhandler nmake - all tc_scriptingprotocolhandler tc_scriptingstorage tc_scriptingprovider NULL
|
||||
tc scripting\java nmake - all tc_scriptingjava tc_scriptingstorage tc_scriptingprovider tc_scriptingprotocolhandler NULL
|
||||
tc scripting\examples\java nmake - all tc_scriptingexamplesjava tc_scriptingjava NULL
|
||||
|
373
scripting/source/basprov/basprov.cxx
Normal file
373
scripting/source/basprov/basprov.cxx
Normal file
@@ -0,0 +1,373 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* $RCSfile: basprov.cxx,v $
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
* last change: $Author: tbe $ $Date: 2003-09-16 15:21:52 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
* - Sun Industry Standards Source License Version 1.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* Sun Industry Standards Source License Version 1.1
|
||||
* =================================================
|
||||
* The contents of this file are subject to the Sun Industry Standards
|
||||
* Source License Version 1.1 (the "License"); You may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the
|
||||
* License at http://www.openoffice.org/license.html.
|
||||
*
|
||||
* Software provided under this License is provided on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
||||
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
||||
* See the License for the specific provisions governing your rights and
|
||||
* obligations concerning the Software.
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef SCRIPTING_BASPROV_HXX
|
||||
#include "basprov.hxx"
|
||||
#endif
|
||||
|
||||
#ifndef SCRIPTING_BASSCRIPT_HXX
|
||||
#include "basscript.hxx"
|
||||
#endif
|
||||
|
||||
#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
|
||||
#include <com/sun/star/frame/XModel.hpp>
|
||||
#endif
|
||||
#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
|
||||
#include <cppuhelper/implementationentry.hxx>
|
||||
#endif
|
||||
|
||||
#ifndef _SBXCLASS_HXX
|
||||
#include <svtools/sbx.hxx>
|
||||
#endif
|
||||
#ifndef _BASMGR_HXX
|
||||
#include <basic/basmgr.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBSTAR_HXX
|
||||
#include <basic/sbstar.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBMOD_HXX
|
||||
#include <basic/sbmod.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBMETH_HXX
|
||||
#include <basic/sbmeth.hxx>
|
||||
#endif
|
||||
#ifndef _SFXAPP_HXX
|
||||
#include <sfx2/app.hxx>
|
||||
#endif
|
||||
#ifndef _SFX_OBJSH_HXX
|
||||
#include <sfx2/objsh.hxx>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
using namespace ::com::sun::star::lang;
|
||||
using namespace ::com::sun::star::uno;
|
||||
using namespace ::drafts::com::sun::star::script::framework;
|
||||
|
||||
|
||||
//.........................................................................
|
||||
namespace basprov
|
||||
{
|
||||
//.........................................................................
|
||||
|
||||
// =============================================================================
|
||||
// component operations
|
||||
// =============================================================================
|
||||
|
||||
static ::rtl::OUString getImplementationName_BasicProviderImpl()
|
||||
{
|
||||
static ::rtl::OUString* pImplName = 0;
|
||||
if ( !pImplName )
|
||||
{
|
||||
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
||||
if ( !pImplName )
|
||||
{
|
||||
static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.ScriptProviderForBasic" ) );
|
||||
pImplName = &aImplName;
|
||||
}
|
||||
}
|
||||
return *pImplName;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static Sequence< ::rtl::OUString > getSupportedServiceNames_BasicProviderImpl()
|
||||
{
|
||||
static Sequence< ::rtl::OUString >* pNames = 0;
|
||||
if ( !pNames )
|
||||
{
|
||||
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
||||
if ( !pNames )
|
||||
{
|
||||
static Sequence< ::rtl::OUString > aNames(1);
|
||||
aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "drafts.com.sun.star.script.framework.provider.ScriptProviderForBasic" ) );
|
||||
pNames = &aNames;
|
||||
}
|
||||
}
|
||||
return *pNames;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// BasicProviderImpl
|
||||
// =============================================================================
|
||||
|
||||
BasicProviderImpl::BasicProviderImpl( const Reference< XComponentContext >& xContext )
|
||||
:m_pBasicManager( 0 )
|
||||
,m_xContext( xContext )
|
||||
,m_xScriptingContext( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BasicProviderImpl::~BasicProviderImpl()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// XServiceInfo
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
::rtl::OUString BasicProviderImpl::getImplementationName( ) throw (RuntimeException)
|
||||
{
|
||||
return getImplementationName_BasicProviderImpl();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
sal_Bool BasicProviderImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
|
||||
{
|
||||
Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
|
||||
const ::rtl::OUString* pNames = aNames.getConstArray();
|
||||
const ::rtl::OUString* pEnd = pNames + aNames.getLength();
|
||||
for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
|
||||
;
|
||||
|
||||
return pNames != pEnd;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Sequence< ::rtl::OUString > BasicProviderImpl::getSupportedServiceNames( ) throw (RuntimeException)
|
||||
{
|
||||
return getSupportedServiceNames_BasicProviderImpl();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// XInitialization
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void BasicProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
|
||||
{
|
||||
// TODO
|
||||
|
||||
::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() );
|
||||
|
||||
if ( aArguments.getLength() == 1 )
|
||||
{
|
||||
aArguments[0] >>= m_xScriptingContext;
|
||||
|
||||
if ( m_xScriptingContext.is() )
|
||||
{
|
||||
Reference< frame::XModel > xModel;
|
||||
// TODO: use ScriptingContantsPool for SCRIPTING_DOC_REF
|
||||
m_xScriptingContext->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SCRIPTING_DOC_REF" ) ) ) >>= xModel;
|
||||
|
||||
if ( xModel.is() )
|
||||
{
|
||||
for ( SfxObjectShell* pObjShell = SfxObjectShell::GetFirst(); pObjShell; pObjShell = SfxObjectShell::GetNext( *pObjShell ) )
|
||||
{
|
||||
if ( xModel == pObjShell->GetModel() )
|
||||
{
|
||||
m_pBasicManager = pObjShell->GetBasicManager();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
throw RuntimeException(
|
||||
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: no scripting context!" ) ),
|
||||
Reference< XInterface >() );
|
||||
*/
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
throw RuntimeException(
|
||||
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::initialize: incorrect number of arguments!" ) ),
|
||||
Reference< XInterface >() );
|
||||
*/
|
||||
}
|
||||
|
||||
// TODO
|
||||
if ( !m_pBasicManager )
|
||||
m_pBasicManager = SFX_APP()->GetBasicManager();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// XScriptProvider
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference < provider::XScript > BasicProviderImpl::getScript( const ::rtl::OUString& scriptURI )
|
||||
throw (IllegalArgumentException, RuntimeException)
|
||||
{
|
||||
// TODO
|
||||
|
||||
::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() );
|
||||
|
||||
Reference< provider::XScript > xScript;
|
||||
|
||||
// parse scriptURI
|
||||
// TODO: use URI parsing class
|
||||
::rtl::OUString aSchema( ::rtl::OUString::createFromAscii( "script://" ) );
|
||||
sal_Int32 nSchemaLen = aSchema.getLength();
|
||||
sal_Int32 nLen = scriptURI.indexOf( '?' );
|
||||
::rtl::OUString aDescription;
|
||||
if ( nLen - nSchemaLen > 0 )
|
||||
aDescription = scriptURI.copy( nSchemaLen, nLen - nSchemaLen );
|
||||
sal_Int32 nIndex = 0;
|
||||
::rtl::OUString aLibrary = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
|
||||
::rtl::OUString aModule;
|
||||
if ( nIndex != -1 )
|
||||
aModule = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
|
||||
::rtl::OUString aMethod;
|
||||
if ( nIndex != -1 )
|
||||
aMethod = aDescription.getToken( 0, (sal_Unicode)'.', nIndex );
|
||||
|
||||
if ( aLibrary.getLength() != 0 && aModule.getLength() != 0 && aMethod.getLength() != 0 )
|
||||
{
|
||||
if ( m_pBasicManager )
|
||||
{
|
||||
StarBASIC* pBasic = m_pBasicManager->GetLib( aLibrary );
|
||||
if ( !pBasic )
|
||||
{
|
||||
USHORT nId = m_pBasicManager->GetLibId( aLibrary );
|
||||
m_pBasicManager->LoadLib( nId );
|
||||
pBasic = m_pBasicManager->GetLib( aLibrary );
|
||||
}
|
||||
if ( pBasic )
|
||||
{
|
||||
SbModule* pModule = pBasic->FindModule( aModule );
|
||||
if ( pModule )
|
||||
{
|
||||
SbxArray* pMethods = pModule->GetMethods();
|
||||
if ( pMethods )
|
||||
{
|
||||
SbMethod* pMethod = (SbMethod*)pMethods->Find( aMethod, SbxCLASS_METHOD );
|
||||
if ( pMethod )
|
||||
xScript = (provider::XScript*) new BasicScriptImpl( pMethod );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !xScript.is() )
|
||||
{
|
||||
throw IllegalArgumentException(
|
||||
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicProviderImpl::getScript: no script!" ) ),
|
||||
Reference< XInterface >(), 1 );
|
||||
}
|
||||
|
||||
return xScript;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// component operations
|
||||
// =============================================================================
|
||||
|
||||
static Reference< XInterface > SAL_CALL create_BasicProviderImpl(
|
||||
Reference< XComponentContext > const & xContext )
|
||||
SAL_THROW( () )
|
||||
{
|
||||
return static_cast< lang::XTypeProvider * >( new BasicProviderImpl( xContext ) );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static struct ::cppu::ImplementationEntry s_component_entries [] =
|
||||
{
|
||||
{
|
||||
create_BasicProviderImpl, getImplementationName_BasicProviderImpl,
|
||||
getSupportedServiceNames_BasicProviderImpl, ::cppu::createSingleComponentFactory,
|
||||
0, 0
|
||||
},
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//.........................................................................
|
||||
} // namespace basprov
|
||||
//.........................................................................
|
||||
|
||||
|
||||
// =============================================================================
|
||||
// component exports
|
||||
// =============================================================================
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void SAL_CALL component_getImplementationEnvironment(
|
||||
const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
|
||||
{
|
||||
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
|
||||
}
|
||||
|
||||
sal_Bool SAL_CALL component_writeInfo(
|
||||
lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey )
|
||||
{
|
||||
return ::cppu::component_writeInfoHelper(
|
||||
pServiceManager, pRegistryKey, ::basprov::s_component_entries );
|
||||
}
|
||||
|
||||
void * SAL_CALL component_getFactory(
|
||||
const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
|
||||
registry::XRegistryKey * pRegistryKey )
|
||||
{
|
||||
return ::cppu::component_getFactoryHelper(
|
||||
pImplName, pServiceManager, pRegistryKey, ::basprov::s_component_entries );
|
||||
}
|
||||
}
|
137
scripting/source/basprov/basprov.hxx
Normal file
137
scripting/source/basprov/basprov.hxx
Normal file
@@ -0,0 +1,137 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* $RCSfile: basprov.hxx,v $
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
* last change: $Author: tbe $ $Date: 2003-09-16 15:21:18 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
* - Sun Industry Standards Source License Version 1.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* Sun Industry Standards Source License Version 1.1
|
||||
* =================================================
|
||||
* The contents of this file are subject to the Sun Industry Standards
|
||||
* Source License Version 1.1 (the "License"); You may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the
|
||||
* License at http://www.openoffice.org/license.html.
|
||||
*
|
||||
* Software provided under this License is provided on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
||||
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
||||
* See the License for the specific provisions governing your rights and
|
||||
* obligations concerning the Software.
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef SCRIPTING_BASPROV_HXX
|
||||
#define SCRIPTING_BASPROV_HXX
|
||||
|
||||
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
|
||||
#include <com/sun/star/beans/XPropertySet.hpp>
|
||||
#endif
|
||||
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
#endif
|
||||
#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
|
||||
#include <com/sun/star/lang/XInitialization.hpp>
|
||||
#endif
|
||||
#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_PROVIDER_XSCRIPTPROVIDER_HPP_
|
||||
#include <drafts/com/sun/star/script/framework/provider/XScriptProvider.hpp>
|
||||
#endif
|
||||
#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
|
||||
#include <com/sun/star/uno/XComponentContext.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef _CPPUHELPER_IMPLBASE3_HXX_
|
||||
#include <cppuhelper/implbase3.hxx>
|
||||
#endif
|
||||
|
||||
class BasicManager;
|
||||
|
||||
|
||||
//.........................................................................
|
||||
namespace basprov
|
||||
{
|
||||
//.........................................................................
|
||||
|
||||
// ----------------------------------------------------
|
||||
// class BasicProviderImpl
|
||||
// ----------------------------------------------------
|
||||
|
||||
typedef ::cppu::WeakImplHelper3<
|
||||
::com::sun::star::lang::XServiceInfo,
|
||||
::com::sun::star::lang::XInitialization,
|
||||
::drafts::com::sun::star::script::framework::provider::XScriptProvider > BasicProviderImpl_BASE;
|
||||
|
||||
|
||||
class BasicProviderImpl : public BasicProviderImpl_BASE
|
||||
{
|
||||
private:
|
||||
BasicManager* m_pBasicManager;
|
||||
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
|
||||
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xScriptingContext;
|
||||
|
||||
public:
|
||||
BasicProviderImpl(
|
||||
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext );
|
||||
virtual ~BasicProviderImpl();
|
||||
|
||||
// XServiceInfo
|
||||
virtual ::rtl::OUString SAL_CALL getImplementationName( )
|
||||
throw (::com::sun::star::uno::RuntimeException);
|
||||
virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
|
||||
throw (::com::sun::star::uno::RuntimeException);
|
||||
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
|
||||
throw (::com::sun::star::uno::RuntimeException);
|
||||
|
||||
// XInitialization
|
||||
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
|
||||
throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
|
||||
|
||||
// XScriptProvider
|
||||
virtual ::com::sun::star::uno::Reference < ::drafts::com::sun::star::script::framework::provider::XScript > SAL_CALL getScript(
|
||||
const ::rtl::OUString& scriptURI )
|
||||
throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
|
||||
};
|
||||
|
||||
//.........................................................................
|
||||
} // namespace basprov
|
||||
//.........................................................................
|
||||
|
||||
#endif // SCRIPTING_BASPROV_HXX
|
10
scripting/source/basprov/basprov.map
Normal file
10
scripting/source/basprov/basprov.map
Normal file
@@ -0,0 +1,10 @@
|
||||
OOO_1.1 {
|
||||
global:
|
||||
component_getDescriptionFunc;
|
||||
component_getImplementationEnvironment;
|
||||
component_getFactory;
|
||||
component_writeInfo;
|
||||
|
||||
local:
|
||||
*;
|
||||
};
|
45
scripting/source/basprov/basprov.xml
Normal file
45
scripting/source/basprov/basprov.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
|
||||
<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<module-name>basprov</module-name>
|
||||
|
||||
<component-description>
|
||||
<author>Thomas Benisch</author>
|
||||
<name>com.sun.star.comp.scripting.ScriptProviderForBasic</name>
|
||||
<description>script provider for Basic</description>
|
||||
<loader-name>com.sun.star.loader.SharedLibrary</loader-name>
|
||||
<language>c++</language>
|
||||
<status value="drafts"/>
|
||||
<supported-service>drafts.com.sun.star.script.framework.provider.ScriptProviderForBasic</supported-service>
|
||||
<type>com.sun.star.beans.XPropertySet</type>
|
||||
<type>com.sun.star.frame.XModel</type>
|
||||
<type>com.sun.star.lang.IllegalArgumentException</type>
|
||||
<type>com.sun.star.lang.XInitialization</type>
|
||||
<type>com.sun.star.lang.XServiceInfo</type>
|
||||
<type>com.sun.star.reflection.InvocationTargetException</type>
|
||||
<type>com.sun.star.script.CannotConvertException</type>
|
||||
<type>com.sun.star.uno.Exception</type>
|
||||
<type>com.sun.star.uno.RuntimeException</type>
|
||||
<type>com.sun.star.uno.XComponentContext</type>
|
||||
<type>drafts.com.sun.star.script.framework.provider.XScript</type>
|
||||
<type>drafts.com.sun.star.script.framework.provider.XScriptProvider</type>
|
||||
</component-description>
|
||||
|
||||
<project-build-dependency>sfx2</project-build-dependency>
|
||||
<project-build-dependency>basic</project-build-dependency>
|
||||
<project-build-dependency>svtools</project-build-dependency>
|
||||
<project-build-dependency>tools</project-build-dependency>
|
||||
<project-build-dependency>cppuhelper</project-build-dependency>
|
||||
<project-build-dependency>cppu</project-build-dependency>
|
||||
<project-build-dependency>sal</project-build-dependency>
|
||||
|
||||
<runtime-module-dependency>sfx2</runtime-module-dependency>
|
||||
<runtime-module-dependency>sb</runtime-module-dependency>
|
||||
<runtime-module-dependency>svt</runtime-module-dependency>
|
||||
<runtime-module-dependency>tl</runtime-module-dependency>
|
||||
<runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency>
|
||||
<runtime-module-dependency>cppu3</runtime-module-dependency>
|
||||
<runtime-module-dependency>sal3</runtime-module-dependency>
|
||||
|
||||
</module-description>
|
229
scripting/source/basprov/basscript.cxx
Normal file
229
scripting/source/basprov/basscript.cxx
Normal file
@@ -0,0 +1,229 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* $RCSfile: basscript.cxx,v $
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
* last change: $Author: tbe $ $Date: 2003-09-16 15:23:11 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
* - Sun Industry Standards Source License Version 1.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* Sun Industry Standards Source License Version 1.1
|
||||
* =================================================
|
||||
* The contents of this file are subject to the Sun Industry Standards
|
||||
* Source License Version 1.1 (the "License"); You may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the
|
||||
* License at http://www.openoffice.org/license.html.
|
||||
*
|
||||
* Software provided under this License is provided on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
||||
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
||||
* See the License for the specific provisions governing your rights and
|
||||
* obligations concerning the Software.
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef SCRIPTING_BASSCRIPT_HXX
|
||||
#include "basscript.hxx"
|
||||
#endif
|
||||
|
||||
#ifndef _SBXCLASS_HXX
|
||||
#include <svtools/sbx.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBSTAR_HXX
|
||||
#include <basic/sbstar.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBMOD_HXX
|
||||
#include <basic/sbmod.hxx>
|
||||
#endif
|
||||
#ifndef _SB_SBMETH_HXX
|
||||
#include <basic/sbmeth.hxx>
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
using namespace ::com::sun::star::lang;
|
||||
using namespace ::com::sun::star::uno;
|
||||
using namespace ::drafts::com::sun::star::script::framework;
|
||||
|
||||
|
||||
extern ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar );
|
||||
extern void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue );
|
||||
|
||||
|
||||
//.........................................................................
|
||||
namespace basprov
|
||||
{
|
||||
//.........................................................................
|
||||
|
||||
typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap;
|
||||
|
||||
// =============================================================================
|
||||
// BasicScriptImpl
|
||||
// =============================================================================
|
||||
|
||||
BasicScriptImpl::BasicScriptImpl( SbMethod* pMethod )
|
||||
:m_pMethod( pMethod )
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BasicScriptImpl::~BasicScriptImpl()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// XScript
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Any BasicScriptImpl::invoke( const Sequence< Any >& aParams, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
|
||||
throw (IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
|
||||
{
|
||||
// TODO: throw CannotConvertException
|
||||
// TODO: check length of aOutParamIndex, aOutParam
|
||||
|
||||
::osl::MutexGuard aGuard( StarBASIC::GetGlobalMutex() );
|
||||
|
||||
Any aReturn;
|
||||
|
||||
if ( m_pMethod )
|
||||
{
|
||||
// check if compiled
|
||||
SbModule* pModule = (SbModule*)m_pMethod->GetParent();
|
||||
if ( pModule && !pModule->IsCompiled() )
|
||||
pModule->Compile();
|
||||
|
||||
// check number of parameters
|
||||
sal_Int32 nParamsCount = aParams.getLength();
|
||||
SbxInfo* pInfo = m_pMethod->GetInfo();
|
||||
if ( pInfo )
|
||||
{
|
||||
sal_Int32 nSbxOptional = 0;
|
||||
USHORT n = 1;
|
||||
for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) )
|
||||
{
|
||||
if ( ( pParamInfo->nFlags & SBX_OPTIONAL ) != 0 )
|
||||
++nSbxOptional;
|
||||
else
|
||||
nSbxOptional = 0;
|
||||
}
|
||||
sal_Int32 nSbxCount = n - 1;
|
||||
if ( ( nParamsCount < nSbxCount - nSbxOptional ) || ( nParamsCount > nSbxCount ) )
|
||||
{
|
||||
throw IllegalArgumentException(
|
||||
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicScriptImpl::invoke: wrong number of paramters!" ) ),
|
||||
Reference< XInterface >(), 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// set parameters
|
||||
SbxArrayRef xSbxParams;
|
||||
if ( nParamsCount > 0 )
|
||||
{
|
||||
xSbxParams = new SbxArray;
|
||||
const Any* pParams = aParams.getConstArray();
|
||||
for ( sal_Int32 i = 0; i < nParamsCount; ++i )
|
||||
{
|
||||
SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT );
|
||||
unoToSbxValue( (SbxVariable*)xSbxVar, pParams[i] );
|
||||
xSbxParams->Put( xSbxVar, (USHORT)i + 1 );
|
||||
}
|
||||
}
|
||||
if ( xSbxParams.Is() )
|
||||
m_pMethod->SetParameters( xSbxParams );
|
||||
|
||||
// call method
|
||||
SbxVariableRef xReturn = new SbxVariable;
|
||||
ErrCode nErr = m_pMethod->Call( xReturn );
|
||||
if ( nErr != SbxERR_OK )
|
||||
{
|
||||
// TODO: throw InvocationTargetException ?
|
||||
}
|
||||
|
||||
// get output parameters
|
||||
if ( xSbxParams.Is() )
|
||||
{
|
||||
SbxInfo* pInfo = m_pMethod->GetInfo();
|
||||
if ( pInfo )
|
||||
{
|
||||
OutParamMap aOutParamMap;
|
||||
for ( USHORT n = 1, nCount = xSbxParams->Count(); n < nCount; ++n )
|
||||
{
|
||||
const SbxParamInfo* pParamInfo = pInfo->GetParam( n );
|
||||
if ( pParamInfo && ( pParamInfo->eType & SbxBYREF ) != 0 )
|
||||
{
|
||||
SbxVariable* pVar = xSbxParams->Get( n );
|
||||
if ( pVar )
|
||||
{
|
||||
SbxVariableRef xVar = pVar;
|
||||
aOutParamMap.insert( OutParamMap::value_type( n - 1, sbxToUnoValue( xVar ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
sal_Int32 nOutParamCount = aOutParamMap.size();
|
||||
aOutParamIndex.realloc( nOutParamCount );
|
||||
aOutParam.realloc( nOutParamCount );
|
||||
sal_Int16* pOutParamIndex = aOutParamIndex.getArray();
|
||||
Any* pOutParam = aOutParam.getArray();
|
||||
for ( OutParamMap::iterator aIt = aOutParamMap.begin(); aIt != aOutParamMap.end(); ++aIt, ++pOutParamIndex, ++pOutParam )
|
||||
{
|
||||
*pOutParamIndex = aIt->first;
|
||||
*pOutParam = aIt->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get return value
|
||||
aReturn = sbxToUnoValue( xReturn );
|
||||
|
||||
// reset parameters
|
||||
m_pMethod->SetParameters( NULL );
|
||||
}
|
||||
|
||||
return aReturn;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
//.........................................................................
|
||||
} // namespace basprov
|
||||
//.........................................................................
|
112
scripting/source/basprov/basscript.hxx
Normal file
112
scripting/source/basprov/basscript.hxx
Normal file
@@ -0,0 +1,112 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* $RCSfile: basscript.hxx,v $
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
* last change: $Author: tbe $ $Date: 2003-09-16 15:22:58 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
* - Sun Industry Standards Source License Version 1.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
*
|
||||
* Sun Industry Standards Source License Version 1.1
|
||||
* =================================================
|
||||
* The contents of this file are subject to the Sun Industry Standards
|
||||
* Source License Version 1.1 (the "License"); You may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of the
|
||||
* License at http://www.openoffice.org/license.html.
|
||||
*
|
||||
* Software provided under this License is provided on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
||||
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
||||
* See the License for the specific provisions governing your rights and
|
||||
* obligations concerning the Software.
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#ifndef SCRIPTING_BASSCRIPT_HXX
|
||||
#define SCRIPTING_BASSCRIPT_HXX
|
||||
|
||||
#ifndef _DRAFTS_COM_SUN_STAR_SCRIPT_FRAMEWORK_PROVIDER_XSCRIPT_HPP_
|
||||
#include <drafts/com/sun/star/script/framework/provider/XScript.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef _CPPUHELPER_IMPLBASE1_HXX_
|
||||
#include <cppuhelper/implbase1.hxx>
|
||||
#endif
|
||||
|
||||
class SbMethod;
|
||||
|
||||
//.........................................................................
|
||||
namespace basprov
|
||||
{
|
||||
//.........................................................................
|
||||
|
||||
// ----------------------------------------------------
|
||||
// class BasicScriptImpl
|
||||
// ----------------------------------------------------
|
||||
|
||||
typedef ::cppu::WeakImplHelper1<
|
||||
::drafts::com::sun::star::script::framework::provider::XScript > BasicScriptImpl_BASE;
|
||||
|
||||
|
||||
class BasicScriptImpl : public BasicScriptImpl_BASE
|
||||
{
|
||||
private:
|
||||
SbMethod* m_pMethod;
|
||||
|
||||
public:
|
||||
BasicScriptImpl( SbMethod* pMethod );
|
||||
virtual ~BasicScriptImpl();
|
||||
|
||||
// XScript
|
||||
virtual ::com::sun::star::uno::Any SAL_CALL invoke(
|
||||
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams,
|
||||
::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
|
||||
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam )
|
||||
throw ( ::com::sun::star::lang::IllegalArgumentException,
|
||||
::com::sun::star::script::CannotConvertException,
|
||||
::com::sun::star::reflection::InvocationTargetException,
|
||||
::com::sun::star::uno::RuntimeException );
|
||||
};
|
||||
|
||||
//.........................................................................
|
||||
} // namespace basprov
|
||||
//.........................................................................
|
||||
|
||||
#endif // SCRIPTING_BASSCRIPT_HXX
|
108
scripting/source/basprov/makefile.mk
Normal file
108
scripting/source/basprov/makefile.mk
Normal file
@@ -0,0 +1,108 @@
|
||||
#*************************************************************************
|
||||
#
|
||||
# $RCSfile: makefile.mk,v $
|
||||
#
|
||||
# $Revision: 1.1 $
|
||||
#
|
||||
# last change: $Author: tbe $ $Date: 2003-09-16 15:23:32 $
|
||||
#
|
||||
# The Contents of this file are made available subject to the terms of
|
||||
# either of the following licenses
|
||||
#
|
||||
# - GNU Lesser General Public License Version 2.1
|
||||
# - Sun Industry Standards Source License Version 1.1
|
||||
#
|
||||
# Sun Microsystems Inc., October, 2000
|
||||
#
|
||||
# GNU Lesser General Public License Version 2.1
|
||||
# =============================================
|
||||
# Copyright 2000 by Sun Microsystems, Inc.
|
||||
# 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License version 2.1, as published by the Free Software Foundation.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
# MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Sun Industry Standards Source License Version 1.1
|
||||
# =================================================
|
||||
# The contents of this file are subject to the Sun Industry Standards
|
||||
# Source License Version 1.1 (the "License"); You may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of the
|
||||
# License at http://www.openoffice.org/license.html.
|
||||
#
|
||||
# Software provided under this License is provided on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
||||
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
||||
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
||||
# See the License for the specific provisions governing your rights and
|
||||
# obligations concerning the Software.
|
||||
#
|
||||
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
#
|
||||
# Copyright: 2000 by Sun Microsystems, Inc.
|
||||
#
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): _______________________________________
|
||||
#
|
||||
#
|
||||
#
|
||||
#*************************************************************************
|
||||
|
||||
PRJ=..$/..
|
||||
|
||||
PRJNAME=scripting
|
||||
TARGET=basprov
|
||||
NO_BSYMBOLIC= TRUE
|
||||
ENABLE_EXCEPTIONS=TRUE
|
||||
COMP1TYPELIST=$(TARGET)
|
||||
COMPRDB=$(SOLARBINDIR)$/types.rdb
|
||||
|
||||
# --- Settings -----------------------------------------------------
|
||||
|
||||
.INCLUDE : svpre.mk
|
||||
.INCLUDE : settings.mk
|
||||
.INCLUDE : sv.mk
|
||||
DLLPRE =
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
.INCLUDE : ..$/cppumaker.mk
|
||||
|
||||
SLOFILES= \
|
||||
$(SLO)$/basprov.obj \
|
||||
$(SLO)$/basscript.obj
|
||||
|
||||
SHL1TARGET= $(TARGET)$(UPD)$(DLLPOSTFIX).uno
|
||||
SHL1IMPLIB= i$(TARGET)
|
||||
|
||||
SHL1VERSIONMAP=$(TARGET).map
|
||||
SHL1DEF=$(MISC)$/$(SHL1TARGET).def
|
||||
DEF1NAME=$(SHL1TARGET)
|
||||
|
||||
SHL1STDLIBS= \
|
||||
$(SFX2LIB) \
|
||||
$(BASICLIB) \
|
||||
$(SVTOOLLIB) \
|
||||
$(TOOLSLIB) \
|
||||
$(CPPUHELPERLIB) \
|
||||
$(CPPULIB) \
|
||||
$(SALLIB)
|
||||
|
||||
SHL1DEPN=
|
||||
SHL1LIBS=$(SLB)$/$(TARGET).lib
|
||||
|
||||
# --- Targets ------------------------------------------------------
|
||||
|
||||
.INCLUDE : target.mk
|
Reference in New Issue
Block a user