1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <rtl/process.h>
27 #include <cppuhelper/servicefactory.hxx>
28 #include <cppuhelper/weak.hxx>
29 #include <cppuhelper/bootstrap.hxx>
30 #include <osl/thread.h>
32 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
35 #include <com/sun/star/java/XJavaVM.hpp>
36 #include <com/sun/star/registry/XImplementationRegistration.hpp>
37 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
39 #include <com/sun/star/uno/XCurrentContext.hpp>
40 #include <com/sun/star/task/XInteractionHandler.hpp>
41 #include <com/sun/star/task/XInteractionRequest.hpp>
42 #include <com/sun/star/task/XInteractionContinuation.hpp>
43 #include <com/sun/star/task/XInteractionAbort.hpp>
44 #include <com/sun/star/task/XInteractionRetry.hpp>
45 #include <com/sun/star/java/JavaNotConfiguredException.hpp>
46 #include <com/sun/star/java/MissingJavaRuntimeException.hpp>
47 #include <com/sun/star/java/JavaDisabledException.hpp>
48 #include <com/sun/star/java/JavaVMCreationFailureException.hpp>
49 #include <cppuhelper/implbase.hxx>
50 #include <uno/current_context.hxx>
53 using namespace css::uno
;
54 using namespace css::lang
;
55 using namespace css::registry
;
56 using namespace css::java
;
57 using namespace css::task
;
60 #define INTERACTION_HANDLER_NAME "java-vm.interaction-handler"
62 class Context
: public WeakImplHelper
<XCurrentContext
>
64 virtual Any SAL_CALL
getValueByName( const OUString
& Name
) throw (RuntimeException
);
67 class InteractionHandler
: public WeakImplHelper
<XInteractionHandler
>
69 virtual void SAL_CALL
handle( const Reference
< XInteractionRequest
>& Request
)
70 throw (RuntimeException
);
73 Any SAL_CALL
Context::getValueByName( const OUString
& Name
) throw (RuntimeException
)
76 if( Name
.equals( INTERACTION_HANDLER_NAME
))
78 Reference
<XInteractionHandler
> handler( static_cast<XWeak
*>(new InteractionHandler()),
85 void SAL_CALL
InteractionHandler::handle( const Reference
< XInteractionRequest
>& Request
)
86 throw (RuntimeException
)
88 Any anyExc
= Request
->getRequest();
89 Sequence
<Reference
< XInteractionContinuation
> >seqCont
= Request
->getContinuations();
91 Reference
<XInteractionAbort
> abort
;
92 Reference
<XInteractionRetry
> retry
;
94 for (sal_Int32 i
= 0; i
< seqCont
.getLength(); i
++)
96 abort
.set( seqCont
[i
], UNO_QUERY
);
100 for (sal_Int32 i
= 0; i
< seqCont
.getLength(); i
++)
102 retry
.set( seqCont
[i
], UNO_QUERY
);
107 static int cRetry
= 0;
119 sal_Bool
test1(const Reference
< XMultiServiceFactory
> & xMgr
)
121 sal_Bool retVal
= sal_True
;
122 setCurrentContext( Reference
<XCurrentContext
>( static_cast<XWeak
*>(new Context()), UNO_QUERY
));
124 OUString
sVMService("com.sun.star.java.JavaVirtualMachine");
125 Reference
<XInterface
> xXInt
= xMgr
->createInstance(sVMService
);
128 Reference
<XJavaVM
> xVM( xXInt
, UNO_QUERY
);
134 rtl_getGlobalProcessId((sal_uInt8
*) arId
);
139 anyVM
= xVM
->getJavaVM( Sequence
<sal_Int8
>(arId
, 16));
141 catch (const JavaNotConfiguredException
& e
)
143 OString msg
= OUStringToOString(e
.Message
, osl_getThreadTextEncoding());
144 printf("JavaNotConfiguredException: %s\n", msg
.getStr());
146 catch (const JavaVMCreationFailureException
& e
)
148 OString msg
= OUStringToOString(e
.Message
, osl_getThreadTextEncoding());
149 printf("JavaVMCreationFailureException: %s\n", msg
.getStr());
151 catch (const MissingJavaRuntimeException
& e
)
153 OString msg
= OUStringToOString(e
.Message
, osl_getThreadTextEncoding());
154 printf("MissingJavaRuntimeException: %s\n", msg
.getStr());
156 catch (const JavaDisabledException
& e
)
158 OString msg
= OUStringToOString(e
.Message
, osl_getThreadTextEncoding());
159 printf("JavaDisabledException: %s\n", msg
.getStr());
161 catch (const RuntimeException
& e
)
163 OString msg
= OUStringToOString(e
.Message
, osl_getThreadTextEncoding());
164 printf("###RuntimeException: %s\n", msg
.getStr());
172 Reference
<XSimpleRegistry
> xreg
= createSimpleRegistry();
173 xreg
->open( OUString("applicat.rdb"),
174 sal_False
, sal_False
);
176 Reference
< XComponentContext
> context
= bootstrap_InitialComponentContext(xreg
);
177 Reference
<XMultiComponentFactory
> fac
= context
->getServiceManager();
178 Reference
<XMultiServiceFactory
> xMgr( fac
, UNO_QUERY
);
180 sal_Bool bSucc
= test1(xMgr
);
181 Reference
< XComponent
> xCompContext( context
, UNO_QUERY
);
182 xCompContext
->dispose();
183 return (bSucc
? 0 : -1);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */