Kaydet (Commit) 37cbbb4b authored tarafından Stephan Bergmann's avatar Stephan Bergmann

jvmaccess doesn't have a stable interface anyway

Change-Id: I681443981a2da8bd3ca0c40965cfee300845c0e9
üst eccbc97c
......@@ -20,11 +20,14 @@
#ifndef INCLUDED_JVMACCESS_CLASSPATH_HXX
#define INCLUDED_JVMACCESS_CLASSPATH_HXX
#include <jvmaccess/jvmaccessdllapi.h>
#include <sal/config.h>
#include <com/sun/star/uno/Reference.hxx>
#include "jni.h"
#include <jni.h>
#include <com/sun/star/uno/Reference.hxx>
#include <jvmaccess/jvmaccessdllapi.h>
#include <rtl/ustring.hxx>
#include <sal/types.h>
namespace com { namespace sun { namespace star { namespace uno {
class XComponentContext;
......@@ -34,10 +37,10 @@ namespace jvmaccess {
/**
Helper functions for class path handling.
*/
class JVMACCESS_DLLPUBLIC ClassPath {
public:
/**
*/
namespace ClassPath {
/**
translates a class path into a java.net.URL[] instance.
@param context
......@@ -49,31 +52,24 @@ public:
@param classPath
a list of zero or more internal (see the
com.sun.star.uri.ExternalUriReferenceTranslator service) URI references,
where any space characters (U+0020) are ignored (and, in particular,
separate adjacent URI references). Any vnd.sun.star.expand URL
references in the list are expanded using the
com.sun.star.util.theMacroExpander singleton of the given context.
where any space characters (U+0020) are ignored (and, in particular, separate
adjacent URI references). Any vnd.sun.star.expand URL references in the list
are expanded using the com.sun.star.util.theMacroExpander singleton of the
given context.
@returns
a local reference to a java.net.URL[] instance containing the external
(see the com.sun.star.uri.ExternalUriReferenceTranslator service)
equivalents of all the URI references in the given classPath. If null, a
(still pending) JNI exception occurred.
a local reference to a java.net.URL[] instance containing the external (see
the com.sun.star.uri.ExternalUriReferenceTranslator service) equivalents of
all the URI references in the given classPath. If null, a (still pending)
JNI exception occurred.
@throws com::sun::star::uno::RuntimeException
*/
static inline ::jobjectArray
translateToUrls(
::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext > const & context,
::JNIEnv * environment, OUString const & classPath)
{
return
static_cast< ::jobjectArray >(
doTranslateToUrls(context, environment, classPath));
}
/**
JVMACCESS_DLLPUBLIC jobjectArray translateToUrls(
css::uno::Reference<css::uno::XComponentContext> const & context,
JNIEnv * environment, OUString const & classPath);
/**
loads a class via a java.net.URLClassLoader.
@param context
......@@ -85,52 +81,25 @@ public:
@param classPath
a list of zero or more internal (see the
com.sun.star.uri.ExternalUriReferenceTranslator service) URI references,
where any space characters (U+0020) are ignored (and, in particular,
separate adjacent URI references). Any vnd.sun.star.expand URL
references in the list are expanded using the
com.sun.star.util.theMacroExpander singleton of the given context.
where any space characters (U+0020) are ignored (and, in particular, separate
adjacent URI references). Any vnd.sun.star.expand URL references in the list
are expanded using the com.sun.star.util.theMacroExpander singleton of the
given context.
@param name
the Java binary name of the class to load.
@returns
a local reference to a java.lang.Class instance. If null, a (still
pending) JNI exception occurred.
a local reference to a java.lang.Class instance. If null, a (still pending)
JNI exception occurred.
@throws com::sun::star::uno::RuntimeException
*/
static inline ::jclass loadClass(
::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext > const & context,
::JNIEnv * environment, OUString const & classPath,
OUString const & name)
{
return
static_cast< ::jclass >(
doLoadClass(context, environment, classPath, name));
}
private:
ClassPath() SAL_DELETED_FUNCTION; //TODO: get rid of this class
ClassPath(ClassPath &) SAL_DELETED_FUNCTION;
~ClassPath() SAL_DELETED_FUNCTION;
void operator =(ClassPath &) SAL_DELETED_FUNCTION;
// Functions that replace JNIEnv, jobjectArray, and jclass with void *, so
// that their mangled C++ names do not depend on the JDK version used at
// compile time:
static void * doTranslateToUrls(
::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext > const & context,
void * environment, OUString const & classPath);
static void * doLoadClass(
::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext > const & context,
void * environment, OUString const & classPath,
OUString const & name);
};
JVMACCESS_DLLPUBLIC jclass loadClass(
css::uno::Reference<css::uno::XComponentContext> const & context,
JNIEnv * environment, OUString const & classPath, OUString const & name);
}
}
......
......@@ -38,18 +38,17 @@
#include "jni.h"
void * ::jvmaccess::ClassPath::doTranslateToUrls(
jobjectArray jvmaccess::ClassPath::translateToUrls(
css::uno::Reference< css::uno::XComponentContext > const & context,
void * environment, OUString const & classPath)
JNIEnv * environment, OUString const & classPath)
{
OSL_ASSERT(context.is() && environment != 0);
::JNIEnv * const env = static_cast< ::JNIEnv * >(environment);
jclass classUrl(env->FindClass("java/net/URL"));
jclass classUrl(environment->FindClass("java/net/URL"));
if (classUrl == 0) {
return 0;
}
jmethodID ctorUrl(
env->GetMethodID(classUrl, "<init>", "(Ljava/lang/String;)V"));
environment->GetMethodID(classUrl, "<init>", "(Ljava/lang/String;)V"));
if (ctorUrl == 0) {
return 0;
}
......@@ -73,20 +72,20 @@ void * ::jvmaccess::ClassPath::doTranslateToUrls(
}
}
jvalue arg;
arg.l = env->NewString(
arg.l = environment->NewString(
static_cast< jchar const * >(url.getStr()),
static_cast< jsize >(url.getLength()));
if (arg.l == 0) {
return 0;
}
jobject o(env->NewObjectA(classUrl, ctorUrl, &arg));
jobject o(environment->NewObjectA(classUrl, ctorUrl, &arg));
if (o == 0) {
return 0;
}
urls.push_back(o);
}
}
jobjectArray result = env->NewObjectArray(
jobjectArray result = environment->NewObjectArray(
static_cast< jsize >(urls.size()), classUrl, 0);
// static_cast is ok, as each element of urls occupied at least one
// character of the OUString classPath
......@@ -96,49 +95,48 @@ void * ::jvmaccess::ClassPath::doTranslateToUrls(
jsize idx = 0;
for (std::vector< jobject >::iterator i(urls.begin()); i != urls.end(); ++i)
{
env->SetObjectArrayElement(result, idx++, *i);
environment->SetObjectArrayElement(result, idx++, *i);
}
return result;
}
void * ::jvmaccess::ClassPath::doLoadClass(
jclass jvmaccess::ClassPath::loadClass(
css::uno::Reference< css::uno::XComponentContext > const & context,
void * environment, OUString const & classPath,
OUString const & name)
JNIEnv * environment, OUString const & classPath, OUString const & name)
{
OSL_ASSERT(context.is() && environment != 0);
::JNIEnv * const env = static_cast< ::JNIEnv * >(environment);
jclass classLoader(env->FindClass("java/net/URLClassLoader"));
jclass classLoader(environment->FindClass("java/net/URLClassLoader"));
if (classLoader == 0) {
return 0;
}
jmethodID ctorLoader(
env->GetMethodID(classLoader, "<init>", "([Ljava/net/URL;)V"));
environment->GetMethodID(classLoader, "<init>", "([Ljava/net/URL;)V"));
if (ctorLoader == 0) {
return 0;
}
jvalue arg;
arg.l = translateToUrls(context, env, classPath);
arg.l = translateToUrls(context, environment, classPath);
if (arg.l == 0) {
return 0;
}
jobject cl = env->NewObjectA(classLoader, ctorLoader, &arg);
jobject cl = environment->NewObjectA(classLoader, ctorLoader, &arg);
if (cl == 0) {
return 0;
}
jmethodID methLoadClass(
env->GetMethodID(
environment->GetMethodID(
classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"));
if (methLoadClass == 0) {
return 0;
}
arg.l = env->NewString(
arg.l = environment->NewString(
static_cast< jchar const * >(name.getStr()),
static_cast< jsize >(name.getLength()));
if (arg.l == 0) {
return 0;
}
return env->CallObjectMethodA(cl, methLoadClass, &arg);
return static_cast<jclass>(
environment->CallObjectMethodA(cl, methLoadClass, &arg));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment