INTEGRATION: CWS jl3 (1.18.44); FILE MERGED

2003/11/21 14:23:24 jl 1.18.44.1: #i22146# Everytime a component is activated it is tried to load the java java loader. If the office is not configured to run java, then every time the message box pops up asking the user to install one
This commit is contained in:
Kurt Zenker 2004-03-25 13:46:54 +00:00
parent 0e4ef0f874
commit 3be2ca2617

View file

@ -2,9 +2,9 @@
*
* $RCSfile: javaloader.cxx,v $
*
* $Revision: 1.18 $
* $Revision: 1.19 $
*
* last change: $Author: rt $ $Date: 2003-04-23 16:09:48 $
* last change: $Author: kz $ $Date: 2004-03-25 14:46:54 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -110,6 +110,9 @@ using namespace ::rtl;
using namespace ::osl;
namespace stoc_javaloader {
static Mutex & getInitMutex();
static Sequence< OUString > loader_getSupportedServiceNames()
{
static Sequence < OUString > *pNames = 0;
@ -145,26 +148,53 @@ namespace stoc_javaloader {
return *pImplName;
}
class JavaComponentLoader : public WeakImplHelper2<XImplementationLoader, XServiceInfo> {
css::uno::Reference<XImplementationLoader> _javaLoader;
class JavaComponentLoader : public WeakImplHelper2<XImplementationLoader, XServiceInfo>
{
css::uno::Reference<XComponentContext> m_xComponentContext;
/** Do not use m_javaLoader directly. Instead use getJavaLoader.
*/
css::uno::Reference<XImplementationLoader> m_javaLoader;
/** The retured Reference contains a null pointer if the office is not configured
to run java.
@exception com::sun::star::uno::RuntimeException
If the Java implementation of the loader could not be obtained, for reasons other
then that java was not configured the RuntimeException is thrown.
*/
const css::uno::Reference<XImplementationLoader> & getJavaLoader();
public:
JavaComponentLoader(const css::uno::Reference<XComponentContext> & xCtx) throw(RuntimeException);
JavaComponentLoader(const css::uno::Reference<XComponentContext> & xCtx)
throw(RuntimeException);
virtual ~JavaComponentLoader() throw();
public:
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException);
virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(RuntimeException);
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
throw(RuntimeException);
virtual Sequence<OUString> SAL_CALL getSupportedServiceNames()
throw(RuntimeException);
// XImplementationLoader
virtual css::uno::Reference<XInterface> SAL_CALL activate(const OUString& implementationName, const OUString& implementationLoaderUrl, const OUString& locationUrl, const css::uno::Reference<XRegistryKey>& xKey) throw(CannotActivateFactoryException, RuntimeException);
virtual sal_Bool SAL_CALL writeRegistryInfo(const css::uno::Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl) throw(CannotRegisterImplementationException, RuntimeException);
virtual css::uno::Reference<XInterface> SAL_CALL activate(
const OUString& implementationName, const OUString& implementationLoaderUrl,
const OUString& locationUrl, const css::uno::Reference<XRegistryKey>& xKey)
throw(CannotActivateFactoryException, RuntimeException);
virtual sal_Bool SAL_CALL writeRegistryInfo(
const css::uno::Reference<XRegistryKey>& xKey,
const OUString& implementationLoaderUrl, const OUString& locationUrl)
throw(CannotRegisterImplementationException, RuntimeException);
};
JavaComponentLoader::JavaComponentLoader(const css::uno::Reference<XComponentContext> & xCtx) throw(RuntimeException)
const css::uno::Reference<XImplementationLoader> & JavaComponentLoader::getJavaLoader()
{
MutexGuard aGuard(getInitMutex());
if (m_javaLoader.is())
return m_javaLoader;
sal_Int32 size = 0;
uno_Environment * pJava_environment = NULL;
uno_Environment * pUno_environment = NULL;
@ -173,7 +203,7 @@ namespace stoc_javaloader {
try {
// get a java vm, where we can create a loader
css::uno::Reference<XJavaVM> javaVM_xJavaVM(
xCtx->getValueByName(
m_xComponentContext->getValueByName(
OUString(RTL_CONSTASCII_USTRINGPARAM(
"/singletons/"
"com.sun.star.java.theJavaVirtualMachine"))),
@ -202,10 +232,12 @@ namespace stoc_javaloader {
reinterpret_cast< jvmaccess::VirtualMachine * >(nPointer));
if (!xVirtualMachine.is())
//throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
// "javaloader error - JavaVirtualMachine service could not provide a VM")), css::uno::Reference<XInterface>());
// We must not throw a RuntimeException, because this might end the applications. It is ok if java components
// "javaloader error - JavaVirtualMachine service could not provide a VM")),
// css::uno::Reference<XInterface>());
// We must not throw a RuntimeException, because this might end the applications.
// It is ok if java components
// are not working because the office can be installed without Java support.
return;
return css::uno::Reference<XImplementationLoader>();
try
{
@ -216,15 +248,18 @@ namespace stoc_javaloader {
jclass jcJavaLoader = pJNIEnv->FindClass("com/sun/star/comp/loader/JavaLoader");
if(pJNIEnv->ExceptionOccurred())
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - could not find class com/sun/star/comp/loader/JavaLoader")), css::uno::Reference<XInterface>());
"javaloader error - could not find class com/sun/star/comp/loader/JavaLoader")),
css::uno::Reference<XInterface>());
jmethodID jmJavaLoader_init = pJNIEnv->GetMethodID(jcJavaLoader, "<init>", "()V");
if(pJNIEnv->ExceptionOccurred())
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - instantiation of com.sun.star.comp.loader.JavaLoader failed")), css::uno::Reference<XInterface>());
"javaloader error - instantiation of com.sun.star.comp.loader.JavaLoader failed")),
css::uno::Reference<XInterface>());
jobject joJavaLoader = pJNIEnv->NewObject(jcJavaLoader, jmJavaLoader_init);
if(pJNIEnv->ExceptionOccurred())
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - instantiation of com.sun.star.comp.loader.JavaLoader failed")), css::uno::Reference<XInterface>());
"javaloader error - instantiation of com.sun.star.comp.loader.JavaLoader failed")),
css::uno::Reference<XInterface>());
// map the java JavaLoader to this environment
OUString sJava(RTL_CONSTASCII_USTRINGPARAM("java"));
@ -254,17 +289,20 @@ namespace stoc_javaloader {
pUno_environment->release(pUno_environment);
pUno_environment = NULL;
getCppuType((css::uno::Reference<XImplementationLoader> *) 0).getDescription((typelib_TypeDescription **) & pType_XImplementationLoader);
getCppuType((css::uno::Reference<XImplementationLoader> *) 0).
getDescription((typelib_TypeDescription **) & pType_XImplementationLoader);
if(!pType_XImplementationLoader)
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - no type information for XImplementationLoader")), css::uno::Reference<XInterface>());
"javaloader error - no type information for XImplementationLoader")),
css::uno::Reference<XInterface>());
_javaLoader = css::uno::Reference<XImplementationLoader>(reinterpret_cast<XImplementationLoader *>(
m_javaLoader = css::uno::Reference<XImplementationLoader>(reinterpret_cast<XImplementationLoader *>(
java_curr.mapInterface(joJavaLoader, pType_XImplementationLoader)));
pJNIEnv->DeleteLocalRef( joJavaLoader );
if(!_javaLoader.is())
if(!m_javaLoader.is())
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - mapping of java XImplementationLoader to c++ failed")), css::uno::Reference<XInterface>());
"javaloader error - mapping of java XImplementationLoader to c++ failed")),
css::uno::Reference<XInterface>());
typelib_typedescription_release(reinterpret_cast<typelib_TypeDescription *>(pType_XImplementationLoader));
pType_XImplementationLoader = NULL;
@ -274,19 +312,19 @@ namespace stoc_javaloader {
throw RuntimeException(
OUString(RTL_CONSTASCII_USTRINGPARAM(
"jvmaccess::VirtualMachine::AttachGuard"
"::CreationException")),
0);
"::CreationException")),0);
}
// set the service manager at the javaloader
css::uno::Reference<XInitialization> javaLoader_XInitialization(_javaLoader, UNO_QUERY);
css::uno::Reference<XInitialization> javaLoader_XInitialization(m_javaLoader, UNO_QUERY);
if(!javaLoader_XInitialization.is())
throw RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"javaloader error - initialization of java javaloader failed, no XInitialization")), css::uno::Reference<XInterface>());
"javaloader error - initialization of java javaloader failed, no XInitialization")),
css::uno::Reference<XInterface>());
Any any;
any <<= css::uno::Reference<XMultiComponentFactory>(
xCtx->getServiceManager());
m_xComponentContext->getServiceManager());
javaLoader_XInitialization->initialize(Sequence<Any>(&any, 1));
}
@ -298,24 +336,35 @@ namespace stoc_javaloader {
pUno_environment->release(pUno_environment);
if(pType_XImplementationLoader)
typelib_typedescription_release(reinterpret_cast<typelib_TypeDescription *>(pType_XImplementationLoader));
typelib_typedescription_release(
reinterpret_cast<typelib_TypeDescription *>(pType_XImplementationLoader));
throw;
}
OSL_TRACE("javaloader.cxx: mapped javaloader - 0x%x", _javaLoader.get());
OSL_TRACE("javaloader.cxx: mapped javaloader - 0x%x", m_javaLoader.get());
return m_javaLoader;
}
JavaComponentLoader::JavaComponentLoader(const css::uno::Reference<XComponentContext> & xCtx) throw(RuntimeException) :
m_xComponentContext(xCtx)
JavaComponentLoader::~JavaComponentLoader() throw() {
{
}
JavaComponentLoader::~JavaComponentLoader() throw()
{
}
// XServiceInfo
OUString SAL_CALL JavaComponentLoader::getImplementationName() throw(::com::sun::star::uno::RuntimeException)
OUString SAL_CALL JavaComponentLoader::getImplementationName()
throw(::com::sun::star::uno::RuntimeException)
{
return loader_getImplementationName();
}
sal_Bool SAL_CALL JavaComponentLoader::supportsService(const OUString & ServiceName) throw(::com::sun::star::uno::RuntimeException) {
sal_Bool SAL_CALL JavaComponentLoader::supportsService(const OUString & ServiceName)
throw(::com::sun::star::uno::RuntimeException)
{
sal_Bool bSupport = sal_False;
Sequence<OUString> aSNL = getSupportedServiceNames();
@ -326,7 +375,8 @@ namespace stoc_javaloader {
return bSupport;
}
Sequence<OUString> SAL_CALL JavaComponentLoader::getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException)
Sequence<OUString> SAL_CALL JavaComponentLoader::getSupportedServiceNames()
throw(::com::sun::star::uno::RuntimeException)
{
return loader_getSupportedServiceNames();
}
@ -334,25 +384,28 @@ namespace stoc_javaloader {
// XImplementationLoader
sal_Bool SAL_CALL JavaComponentLoader::writeRegistryInfo(const css::uno::Reference<XRegistryKey> & xKey, const OUString & blabla, const OUString & rLibName)
sal_Bool SAL_CALL JavaComponentLoader::writeRegistryInfo(
const css::uno::Reference<XRegistryKey> & xKey, const OUString & blabla,
const OUString & rLibName)
throw(CannotRegisterImplementationException, RuntimeException)
{
if (_javaLoader.is())
return _javaLoader->writeRegistryInfo(xKey, blabla, rLibName);
const css::uno::Reference<XImplementationLoader> & loader = getJavaLoader();
if (loader.is())
return loader->writeRegistryInfo(xKey, blabla, rLibName);
else
throw CannotRegisterImplementationException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Could not create Java implementation loader")), NULL);
}
css::uno::Reference<XInterface> SAL_CALL JavaComponentLoader::activate(const OUString & rImplName,
const OUString & blabla,
const OUString & rLibName,
css::uno::Reference<XInterface> SAL_CALL JavaComponentLoader::activate(
const OUString & rImplName, const OUString & blabla, const OUString & rLibName,
const css::uno::Reference<XRegistryKey> & xKey)
throw(CannotActivateFactoryException, RuntimeException)
{
if (_javaLoader.is())
return _javaLoader->activate(rImplName, blabla, rLibName, xKey);
const css::uno::Reference<XImplementationLoader> & loader = getJavaLoader();
if (loader.is())
return loader->activate(rImplName, blabla, rLibName, xKey);
else
throw CannotActivateFactoryException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Could not create Java implementation loader")), NULL);
@ -372,6 +425,7 @@ namespace stoc_javaloader {
}
return *pMutex;
}
css::uno::Reference<XInterface> SAL_CALL JavaComponentLoader_CreateInstance(const css::uno::Reference<XComponentContext> & xCtx) throw(Exception)
{
css::uno::Reference<XInterface> xRet;
@ -399,7 +453,8 @@ namespace stoc_javaloader {
return xRet;
}
}
} //end namespace
using namespace stoc_javaloader;