2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* $RCSfile: Class.cxx,v $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 00:33:23 +00:00
|
|
|
* $Revision: 1.12 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 00:33:23 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2006-06-20 01:33:23 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* 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.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* 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.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:08:41 +00:00
|
|
|
* 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
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_
|
|
|
|
#include "java/lang/Class.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_
|
|
|
|
#include "java/tools.hxx"
|
|
|
|
#endif
|
2001-05-04 08:58:45 +00:00
|
|
|
#ifndef _RTL_USTRING_HXX_
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#endif
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
using namespace connectivity;
|
|
|
|
//**************************************************************
|
|
|
|
//************ Class: java.lang.Class
|
|
|
|
//**************************************************************
|
|
|
|
|
|
|
|
jclass java_lang_Class::theClass = 0;
|
|
|
|
|
|
|
|
java_lang_Class::~java_lang_Class()
|
|
|
|
{}
|
|
|
|
|
|
|
|
jclass java_lang_Class::getMyClass()
|
|
|
|
{
|
|
|
|
// die Klasse muss nur einmal geholt werden, daher statisch
|
|
|
|
if( !theClass ){
|
|
|
|
SDBThreadAttach t;
|
|
|
|
if( !t.pEnv ) return (jclass)NULL;
|
2001-03-20 16:03:18 +00:00
|
|
|
jclass tempClass = t.pEnv->FindClass("java/lang/Class"); OSL_ENSURE(tempClass,"Java : FindClass nicht erfolgreich!");
|
2000-09-18 15:18:56 +00:00
|
|
|
jclass globClass = (jclass)t.pEnv->NewGlobalRef( tempClass );
|
|
|
|
t.pEnv->DeleteLocalRef( tempClass );
|
|
|
|
saveClassRef( globClass );
|
|
|
|
}
|
|
|
|
return theClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void java_lang_Class::saveClassRef( jclass pClass )
|
|
|
|
{
|
2003-04-24 12:19:36 +00:00
|
|
|
if( pClass==NULL )
|
2000-09-18 15:18:56 +00:00
|
|
|
return;
|
|
|
|
// der uebergebe Klassen-Handle ist schon global, daher einfach speichern
|
|
|
|
theClass = pClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
java_lang_Class * java_lang_Class::forName( const ::rtl::OUString& _par0 )
|
|
|
|
{
|
|
|
|
jobject out(NULL);
|
|
|
|
SDBThreadAttach t;
|
2001-08-14 06:21:03 +00:00
|
|
|
if( t.pEnv )
|
|
|
|
{
|
2003-08-07 13:36:09 +00:00
|
|
|
::rtl::OString sClassName = ::rtl::OUStringToOString(_par0, RTL_TEXTENCODING_JAVA_UTF8);
|
2001-08-14 06:21:03 +00:00
|
|
|
sClassName = sClassName.replace('.','/');
|
|
|
|
out = t.pEnv->FindClass(sClassName);
|
|
|
|
ThrowSQLException(t.pEnv,0);
|
2000-09-18 15:18:56 +00:00
|
|
|
} //t.pEnv
|
|
|
|
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
|
|
|
|
return out==0 ? NULL : new java_lang_Class( t.pEnv, out );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool java_lang_Class::isAssignableFrom( java_lang_Class * _par0 )
|
|
|
|
{
|
2006-06-20 00:33:23 +00:00
|
|
|
jboolean out(0);
|
2000-09-18 15:18:56 +00:00
|
|
|
SDBThreadAttach t;
|
|
|
|
if( t.pEnv ){
|
2001-08-14 06:21:03 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// temporaere Variable initialisieren
|
2006-06-20 00:33:23 +00:00
|
|
|
static const char * cSignature = "(Ljava/lang/Class;)Z";
|
|
|
|
static const char * cMethodName = "isAssignableFrom";
|
2000-09-18 15:18:56 +00:00
|
|
|
// Java-Call absetzen
|
2004-11-09 11:11:35 +00:00
|
|
|
static jmethodID mID = NULL;
|
|
|
|
if ( !mID )
|
|
|
|
mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
|
2000-09-18 15:18:56 +00:00
|
|
|
if( mID ){
|
2001-08-14 06:21:03 +00:00
|
|
|
jvalue args[1];
|
|
|
|
// Parameter konvertieren
|
|
|
|
args[0].l = _par0 != NULL ? ((java_lang_Object *)_par0)->getJavaObject() : NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
out = t.pEnv->CallBooleanMethod( object, mID, args[0].l );
|
|
|
|
ThrowSQLException(t.pEnv,0);
|
|
|
|
// und aufraeumen
|
|
|
|
} //mID
|
|
|
|
} //t.pEnv
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
java_lang_Object * java_lang_Class::newInstance()
|
|
|
|
{
|
|
|
|
jobject out(NULL);
|
|
|
|
SDBThreadAttach t;
|
|
|
|
if( t.pEnv ){
|
|
|
|
// temporaere Variable initialisieren
|
2006-06-20 00:33:23 +00:00
|
|
|
static const char * cSignature = "()Ljava/lang/Object;";
|
|
|
|
static const char * cMethodName = "newInstance";
|
2000-09-18 15:18:56 +00:00
|
|
|
// Java-Call absetzen
|
2004-11-09 11:11:35 +00:00
|
|
|
static jmethodID mID = NULL;
|
|
|
|
if ( !mID )
|
|
|
|
mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
|
2000-09-18 15:18:56 +00:00
|
|
|
if( mID ){
|
|
|
|
out = t.pEnv->CallObjectMethod( object, mID);
|
|
|
|
ThrowSQLException(t.pEnv,0);
|
|
|
|
} //mID
|
|
|
|
} //t.pEnv
|
|
|
|
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
|
|
|
|
return out==0 ? NULL : new java_lang_Object( t.pEnv, out );
|
|
|
|
}
|
|
|
|
|
2000-11-22 13:44:26 +00:00
|
|
|
jobject java_lang_Class::newInstanceObject()
|
|
|
|
{
|
|
|
|
jobject out(NULL);
|
|
|
|
SDBThreadAttach t;
|
|
|
|
if( t.pEnv )
|
|
|
|
{
|
|
|
|
// temporaere Variable initialisieren
|
2006-06-20 00:33:23 +00:00
|
|
|
static const char * cSignature = "()Ljava/lang/Object;";
|
|
|
|
static const char * cMethodName = "newInstance";
|
2000-11-22 13:44:26 +00:00
|
|
|
// Java-Call absetzen
|
2004-11-09 11:11:35 +00:00
|
|
|
static jmethodID mID = NULL;
|
|
|
|
if ( !mID )
|
|
|
|
mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
|
2000-11-22 13:44:26 +00:00
|
|
|
if( mID ){
|
|
|
|
out = t.pEnv->CallObjectMethod( object, mID);
|
|
|
|
ThrowSQLException(t.pEnv,0);
|
|
|
|
} //mID
|
|
|
|
} //t.pEnv
|
|
|
|
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
::rtl::OUString java_lang_Class::getName()
|
|
|
|
{
|
|
|
|
SDBThreadAttach t;
|
|
|
|
::rtl::OUString aStr;
|
|
|
|
if( t.pEnv ){
|
|
|
|
// temporaere Variable initialisieren
|
2006-06-20 00:33:23 +00:00
|
|
|
static const char * cSignature = "()Ljava/lang/String;";
|
|
|
|
static const char * cMethodName = "getName";
|
2000-09-18 15:18:56 +00:00
|
|
|
// Java-Call absetzen
|
2004-11-09 11:11:35 +00:00
|
|
|
static jmethodID mID = NULL;
|
|
|
|
if ( !mID )
|
|
|
|
mID = t.pEnv->GetMethodID( getMyClass(), cMethodName, cSignature );OSL_ENSURE(mID,"Unknown method id!");
|
2000-09-18 15:18:56 +00:00
|
|
|
if( mID ){
|
2004-11-09 11:11:35 +00:00
|
|
|
jstring out = (jstring)t.pEnv->CallObjectMethod( object, mID);
|
2000-09-18 15:18:56 +00:00
|
|
|
ThrowSQLException(t.pEnv,0);
|
2004-11-09 11:11:35 +00:00
|
|
|
aStr = JavaString2String(t.pEnv, (jstring)out );
|
2000-09-18 15:18:56 +00:00
|
|
|
} //mID
|
|
|
|
} //t.pEnv
|
|
|
|
// ACHTUNG: der Aufrufer wird Eigentuemer des zurueckgelieferten Zeigers !!!
|
|
|
|
return aStr;
|
|
|
|
}
|
|
|
|
|