fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / stoc / test / javavm / jvm_interaction / interactionhandler.cxx
blob48ccb1e50db22e1d8acd440617f49ea1f76beece
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <jni.h>
23 #include <stdio.h>
24 #include <sal/main.h>
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/implbase1.hxx>
50 #include <uno/current_context.hxx>
52 using namespace std;
53 using namespace cppu;
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::lang;
56 using namespace com::sun::star::registry;
57 using namespace com::sun::star::java;
58 using namespace com::sun::star::task;
61 #define INTERACTION_HANDLER_NAME "java-vm.interaction-handler"
63 class Context: public WeakImplHelper1<XCurrentContext>
65 virtual Any SAL_CALL getValueByName( const OUString& Name ) throw (RuntimeException);
68 class InteractionHandler: public WeakImplHelper1<XInteractionHandler>
70 virtual void SAL_CALL handle( const Reference< XInteractionRequest >& Request )
71 throw (RuntimeException);
74 Any SAL_CALL Context::getValueByName( const OUString& Name) throw (RuntimeException)
76 Any retVal;
77 if( Name.equals( INTERACTION_HANDLER_NAME))
79 Reference<XInteractionHandler> handler( static_cast<XWeak*>(new InteractionHandler()),
80 UNO_QUERY);
81 retVal <<= handler;
83 return retVal;
86 void SAL_CALL InteractionHandler::handle( const Reference< XInteractionRequest >& Request )
87 throw (RuntimeException)
89 Any anyExc= Request->getRequest();
90 Sequence<Reference< XInteractionContinuation> >seqCont= Request->getContinuations();
92 Reference<XInteractionAbort> abort;
93 Reference<XInteractionRetry> retry;
95 for (sal_Int32 i= 0; i < seqCont.getLength(); i++)
97 abort= Reference<XInteractionAbort>::query( seqCont[i]);
98 if(abort.is())
99 break;
101 for (sal_Int32 i= 0; i < seqCont.getLength(); i++)
103 retry= Reference<XInteractionRetry>::query( seqCont[i]);
104 if(retry.is())
105 break;
108 static int cRetry= 0;
110 if( cRetry++ == 5)
112 if( abort.is())
113 abort->select();
114 return;
116 if( retry.is())
117 retry->select();
120 sal_Bool test1(const Reference< XMultiServiceFactory > & xMgr )
122 sal_Bool retVal= sal_True;
123 setCurrentContext( Reference<XCurrentContext>( static_cast<XWeak*>(new Context()), UNO_QUERY));
125 OUString sVMService("com.sun.star.java.JavaVirtualMachine");
126 Reference<XInterface> xXInt= xMgr->createInstance(sVMService);
127 if( ! xXInt.is())
128 return sal_False;
129 Reference<XJavaVM> xVM( xXInt, UNO_QUERY);
130 if( ! xVM.is())
131 return sal_False;
134 sal_Int8 arId[16];
135 rtl_getGlobalProcessId((sal_uInt8*) arId);
137 Any anyVM;
140 anyVM = xVM->getJavaVM( Sequence<sal_Int8>(arId, 16));
142 catch (const JavaNotConfiguredException& e)
144 OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding());
145 printf("JavaNotConfiguredException: %s\n", msg.getStr());
147 catch (const JavaVMCreationFailureException& e)
149 OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding());
150 printf("JavaVMCreationFailureException: %s\n", msg.getStr());
152 catch (const MissingJavaRuntimeException& e)
154 OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding());
155 printf("MissingJavaRuntimeException: %s\n", msg.getStr());
157 catch (const JavaDisabledException& e)
159 OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding());
160 printf("JavaDisabledException: %s\n", msg.getStr());
162 catch (const RuntimeException & e)
164 OString msg= OUStringToOString(e.Message, osl_getThreadTextEncoding());
165 printf("###RuntimeException: %s\n", msg.getStr());
166 retVal= sal_False;
168 return retVal;
171 SAL_IMPLEMENT_MAIN()
173 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
174 xreg->open( OUString("applicat.rdb"),
175 sal_False, sal_False );
177 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
178 Reference<XMultiComponentFactory> fac= context->getServiceManager();
179 Reference<XMultiServiceFactory> xMgr( fac, UNO_QUERY);
181 sal_Bool bSucc = sal_False;
182 bSucc= test1(xMgr);
183 Reference< XComponent > xCompContext( context, UNO_QUERY );
184 xCompContext->dispose();
185 return (bSucc ? 0 : -1);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */