KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > apis > Responses


1 /**
2  * $Id: Responses.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2003-2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.apis;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.ProjectComponent;
33
34 /**
35  * Collection of predefined problem handlers.
36  *
37  * @since JWare/AntX 0.3
38  * @author ssmc, &copy;2003-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
39  * @version 0.5
40  * @.safety multiple
41  * @.group impl,helper
42  **/

43
44 public final class Responses
45 {
46     /**
47      * Stops the build-iteration with a build error.
48      * @version 0.5
49      * @since JWare/AntX 0.3
50      **/

51     public static final ProblemHandler DEATH=
52         new ProblemHandler() {
53                 public void problem(Object JavaDoc nugget, int nl) {
54                     throw new BuildError(String.valueOf(nugget));
55                 }
56             };
57
58
59
60     /**
61      * Generates a build-iteration exception.
62      * @version 0.5
63      * @since JWare/AntX 0.3
64      **/

65     public static final ProblemHandler ERROR=
66         new ProblemHandler() {
67                 public void problem(Object JavaDoc nugget, int nl) {
68                     throw new BuildException(String.valueOf(nugget));
69                 }
70             };
71
72
73
74     /**
75      * Silently ignores the problem; no-op.
76      * @version 0.5
77      * @since JWare/AntX 0.3
78      **/

79     public static final ProblemHandler SILENCE=
80         new ProblemHandler() {
81                 public void problem(Object JavaDoc nugget, int nl) {
82                     //nada
83
}
84             };
85
86
87
88     /**
89      * Simple problem handler that just records whether a problem was
90      * reported back to the original caller as a boolean.
91      * @since JWare/AntX 0.4
92      * @author ssmc
93      * @.safety single
94      * @.group impl,helper
95      **/

96     public static final class LitmusResult implements ProblemHandler {
97         /** Reflects the result of the operation. True means a
98             problem occured. **/

99         public boolean hadProblem;
100
101         /** Reflects the details of the encountered problem. **/
102         public String JavaDoc what="";
103
104         /** Initializes a new "no" problem result. **/
105         public LitmusResult() {
106         }
107
108         /** Records operation has had some kind of problem. **/
109         public void problem(Object JavaDoc nugget, int nl) {
110             this.hadProblem = true;
111             this.what = Tk.stringFrom(nugget,null);
112         }
113         /** Resets this response object for reuse. **/
114         public void reset() {
115             hadProblem = false;
116             what = "";
117         }
118     }
119
120
121
122     /**
123      * Logs problem via its controlling log enabled component.
124      * @version 0.5
125      * @since JWare/AntX 0.3
126      * @.group impl,helper
127      **/

128     public static class LogUsing implements ProblemHandler {
129         /** Initializes new handler that logs to standard Ant component.
130          * @see com.idaremedia.antx.apis.LogEnabled.ForComponent
131          **/

132         public LogUsing(ProjectComponent pc) {
133             logSpi = new LogEnabled.ForComponent(pc);
134         }
135         /** Initializes new handler that delegates to log enabled component.
136          * @since JWare/AntX 0.5
137          **/

138         public LogUsing(LogEnabled impl) {
139             if (impl==null) {
140                 throw new IllegalArgumentException JavaDoc();
141             }
142             logSpi = impl;
143         }
144         /** Logs problem via this response's component. **/
145         public void problem(Object JavaDoc nugget, int nl) {
146             logSpi.log(Tk.stringFrom(nugget,null),nl);
147         }
148         final LogEnabled logSpi;
149     }
150
151
152
153     /**
154      * Logs problem via its controlling project component and
155      * remember whether a problem was recorded.
156      * @version 0.5
157      * @since JWare/AntX 0.4
158      * @.group impl,helper
159      **/

160     public static class LogAndRemember extends LogUsing {
161         /** Reflects the result of the operation. True means a
162             problem occured. **/

163         public boolean hadProblem;
164
165         /** Reflects the details of the encountered problem. **/
166         public String JavaDoc what="";
167
168         /** Initializes new handler that logs to standard Ant component and
169          * remembers whether had problem.
170          **/

171         public LogAndRemember(ProjectComponent pc) {
172             super(pc);
173         }
174         /** Initializes new handler that delegates to log enabled component
175          * and remembers problem occured.
176          * @since JWare/AntX 0.5
177          **/

178         public LogAndRemember(LogEnabled impl) {
179             super(impl);
180         }
181         /** Records there was a problem and logs problem via this
182          * handler's log enabled component.
183          **/

184         public void problem(Object JavaDoc nugget, int nl) {
185             this.hadProblem = true;
186             this.what = Tk.stringFrom(nugget,null);
187             logSpi.log(this.what,nl);
188         }
189         /** Resets this response object for reuse. **/
190         public void reset() {
191             hadProblem = false;
192             what = "";
193         }
194     }
195
196
197     /** Prevent; only static APIs and classes. **/
198     private Responses()
199     {}
200 }
201
202 /* end-of-Responses.java */
203
Popular Tags