Source code: com/dghda/kent/ReportAction.java
1 /* Copyright (C) 2001 Duane Griffin <duanegriffin@users.sourceforge.net>
2 This file is part of Kent.
3
4 Kent is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 Kent is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with Kent; see the file COPYING. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20 package com.dghda.kent;
21
22 /**
23 An interface used to output a report's results.
24 For example, an implementing class might send the results in an email.
25 */
26 public interface ReportAction extends KentModule {
27
28 /** A class that encapsulates the result of performing an action. */
29 public static final class ActionResult {
30
31 /** A success, with no status message. */
32 public ActionResult() {
33 m_Success = true;
34 m_Status = "";
35 }
36
37 /** Success/failure, with a status message. */
38 public ActionResult (boolean suc, String msg) {
39 m_Success = suc;
40 m_Status = msg;
41 }
42
43 /** Failure, with a status message and an exception. */
44 public ActionResult (String msg, Throwable exc) {
45 m_Success = false;
46 m_Status = msg;
47 m_Error = exc;
48 }
49
50 /** Failure, with an exception. */
51 public ActionResult (Throwable exc) {
52 m_Success = false;
53 m_Status = exc.getMessage();
54 m_Error = exc;
55 }
56
57 /** True if the action was completed successfully. */
58 public boolean getSuccess() {
59 return m_Success;
60 }
61
62 public void setSuccess (boolean success) {
63 m_Success = success;
64 }
65
66 /** Set the result to failed with the given status & error. */
67 public void failed (String status, Throwable error) {
68 m_Success = false;
69 m_Status = status;
70 m_Error = error;
71 }
72
73 /** Additional status information. */
74 public String getStatus() {
75 return m_Status;
76 }
77
78 public void setStatus (String status) {
79 m_Status = status;
80 }
81
82 /** The exception causing the action to fail, if applicable. */
83 public Throwable getError() {
84 return m_Error;
85 }
86
87 public void setError (Throwable error) {
88 m_Error = error;
89 }
90
91 private boolean m_Success;
92 private String m_Status;
93 private Throwable m_Error;
94 }
95
96 /** Take some action with the results of a report. */
97 public ActionResult performAction (String template, String data, java.util.Properties config);
98 }