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
;
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
34 * @const RETRY_COUNT it defines the max count of
35 * retrying of an interaction
37 private static final int RETRY_COUNT
= 3;
42 * count using of RETRY continuations
45 /** true if the interaction handler was used */
46 private boolean m_bWasUsed
;
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()
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
69 * describe the interaction
71 public void handle(com
.sun
.star
.task
.XInteractionRequest xRequest
)
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
)
91 xAbort
= (com
.sun
.star
.task
.XInteractionAbort
)AnyConverter
.toObject(xAbortType
, lContinuations
[i
]);
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.
103 if (m_nTry
< RETRY_COUNT
)
112 // otherwise we can abort this interaction only
119 public boolean wasUsed() {