Branch libreoffice-5-0-4
[LibreOffice.git] / framework / qa / complex / loadAllDocuments / InteractionHandler.java
blobd8e5091de55e2ee0838c76f7a79772d873b8de4b
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package complex.loadAllDocuments;
20 import com.sun.star.task.XInteractionHandler;
21 import com.sun.star.uno.AnyConverter;
24 /**
25 * Implemets a simple interaction handler,
26 * which can abort all incoming interactions only ... but make it possible to
27 * log it. So it can be used for debug and test purposes.
29 public class InteractionHandler implements XInteractionHandler
33 /**
34 * @const RETRY_COUNT it defines the max count of
35 * retrying of an interaction
37 private static final int RETRY_COUNT = 3;
41 /**
42 * count using of RETRY continuations
44 private int m_nTry ;
45 /** true if the interaction handler was used */
46 private boolean m_bWasUsed ;
49 /**
50 * ctor
51 * It's initialize an object of this class with default values
52 * and set the protocol stack. So the outside code can check
53 * if this handler was used or not.
55 public InteractionHandler()
57 m_nTry = 0 ;
58 m_bWasUsed = false;
61 /**
62 * Called to start the interaction, because the outside code wish to solve
63 * a detected problem or to inform the user about something.
64 * We save the information here and can handle two well known continuations
65 * only.
66 * [abort and retry].
68 * @param xRequest
69 * describe the interaction
71 public void handle(com.sun.star.task.XInteractionRequest xRequest)
73 m_bWasUsed = true;
75 // analyze the possible continuations.
76 // We can abort all incoming interactions only.
77 // But additional we can try to continue it several times too.
78 // Of course after e.g. three loops we have to stop and abort it.
79 com.sun.star.task.XInteractionContinuation[] lContinuations = xRequest.getContinuations();
81 com.sun.star.task.XInteractionAbort xAbort = null;
82 com.sun.star.task.XInteractionRetry xRetry = null;
83 com.sun.star.uno.Type xAbortType = new com.sun.star.uno.Type(com.sun.star.task.XInteractionAbort.class);
84 com.sun.star.uno.Type xRetryType = new com.sun.star.uno.Type(com.sun.star.task.XInteractionRetry.class);
86 for (int i=0; i<lContinuations.length; ++i)
88 try
90 if (xAbort == null)
91 xAbort = (com.sun.star.task.XInteractionAbort)AnyConverter.toObject(xAbortType, lContinuations[i]);
92 if (xRetry == null)
93 xRetry = (com.sun.star.task.XInteractionRetry)AnyConverter.toObject(xRetryType, lContinuations[i]);
95 catch(com.sun.star.lang.IllegalArgumentException exArg) {}
98 // try it again, but only if it wasn't tried to much before.
99 if (xRetry != null)
101 synchronized(this)
103 if (m_nTry < RETRY_COUNT)
105 ++m_nTry;
106 xRetry.select();
107 return;
112 // otherwise we can abort this interaction only
113 if (xAbort != null)
115 xAbort.select();
119 public boolean wasUsed() {
120 return m_bWasUsed;