KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: LogEnabled.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 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 (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any 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 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 GNU 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.Project;
32 import org.apache.tools.ant.ProjectComponent;
33
34 /**
35  * Any application object that supports the two standard Ant log APIs.
36  *
37  * @since JWare/AntX 0.5
38  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
39  * @version 0.5
40  * @.safety n/a
41  * @.group api,infra
42  * @.pattern GoF.Strategy
43  * @see Requester
44  * @see ProblemHandler
45  **/

46
47 public interface LogEnabled
48 {
49     /**
50      * Should do whatever service user does to record a
51      * diagnostic trace message.
52      * @param message the message (non-null)
53      **/

54     void log(String JavaDoc message);
55
56
57
58     /**
59      * Should do whatever service user does to record either a
60      * problem or a diagnostic trace message. (The type of
61      * message is indicated by the accompanying noise level.)
62      * @param message the message (non-null)
63      * @param msgLevel the <em>Ant</em> noise level
64      **/

65     void log(String JavaDoc message, int msgLevel);
66
67
68
69     /**
70      * Default {@linkplain LogEnabled} adapter for the System consoles.
71      * @since JWare/AntX 0.5
72      * @version 0.5
73      **/

74     public static final LogEnabled SYSTEM= new LogEnabled() {
75         public void log(String JavaDoc message) {
76             System.out.println(message);
77         }
78         public void log(String JavaDoc message, int msgLevel) {
79             if (msgLevel>=Project.MSG_INFO) {
80                 System.err.println(message);
81             } else {
82                 System.out.println(message);
83             }
84         }
85     };
86
87
88
89     /**
90      * Default {@linkplain LogEnabled} adapter for a generic Ant
91      * project component. Use this adapter to pass non AntX-based items
92      * into AntX APIs.
93      * @since JWare/AntX 0.5
94      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
95      * @version 0.5
96      * @.group impl,helper
97      **/

98     public static class ForComponent implements LogEnabled
99     {
100         final ProjectComponent m_PC;
101
102         /**
103          * Initializes a new adapter for given project component.
104          * @param pc the component being wrapped (non-null)
105          */

106         public ForComponent(ProjectComponent pc) {
107             if (pc==null) {
108                 throw new IllegalArgumentException JavaDoc();
109             }
110             this.m_PC = pc;
111         }
112
113         public void log(String JavaDoc message) {
114             m_PC.log(message);
115         }
116
117         public void log(String JavaDoc message, int msgLevel) {
118             m_PC.log(message,msgLevel);
119         }
120         /** Returns the underlying component for this adapter. **/
121         public final ProjectComponent getImpl() {
122             return m_PC;
123         }
124     }
125
126
127
128
129     /**
130      * Default {@linkplain LogEnabled} adapter for a utility class. If
131      * at call time the utility's project is <i>null</i> this adapter will
132      * delegate to one of the two {@linkplain #SYSTEM system} consoles.
133      * @since JWare/AntX 0.5
134      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
135      * @version 0.5
136      * @.group impl,helper
137      **/

138     public static class ForUtility implements LogEnabled
139     {
140         final ProjectDependent m_utility;
141
142         /**
143          * Initializes a new adapter for given project component.
144          * @param utility the utility object being wrapped (non-null)
145          */

146         public ForUtility(ProjectDependent utility) {
147             if (utility==null) {
148                 throw new IllegalArgumentException JavaDoc();
149             }
150             this.m_utility = utility;
151         }
152
153         public void log(String JavaDoc message) {
154             if (m_utility.getProject()!=null) {
155                 m_utility.getProject().log(message);
156             } else {
157                 SYSTEM.log(message);
158             }
159         }
160
161         public void log(String JavaDoc message, int msgLevel) {
162             if (m_utility.getProject()!=null) {
163                 m_utility.getProject().log(message,msgLevel);
164             } else {
165                 SYSTEM.log(message,msgLevel);
166             }
167         }
168         /** Returns the underlying utility for this adapter. **/
169         public final ProjectDependent getImpl() {
170             return m_utility;
171         }
172     }
173
174
175
176     /**
177      * Default {@linkplain LogEnabled} adapter for a generic Ant
178      * project. Use this adapter to pass request-based project references
179      * into AntX APIs. To facilitate utilities that allow <i>null</i>
180      * projects, this adapter will use one of the two
181      * {@linkplain #SYSTEM system} consoles if incoming project is <i>null</i>.
182      * @since JWare/AntX 0.5
183      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
184      * @version 0.5
185      * @.group impl,helper
186      **/

187     public static class ForProject implements LogEnabled
188     {
189         final Project m_project;
190
191         /**
192          * Initializes a new adapter for given project.
193          * @param project the project being wrapped
194          */

195         public ForProject(Project project) {
196             this.m_project = project;
197         }
198
199         public void log(String JavaDoc message) {
200             if (m_project!=null) {
201                 m_project.log(message);
202             } else {
203                 SYSTEM.log(message);
204             }
205         }
206
207         public void log(String JavaDoc message, int msgLevel) {
208             if (m_project!=null) {
209                 m_project.log(message,msgLevel);
210             } else {
211                 SYSTEM.log(message,msgLevel);
212             }
213         }
214         /** Returns the underlying project for this adapter. **/
215         public final Project getImpl() {
216             return m_project;
217         }
218     }
219
220
221
222     /**
223      * Default {@linkplain LogEnabled} adapter for a compound requester.
224      * Use this adapter when creating {@linkplain Requester requesters}
225      * comprised of multiple sources.
226      * @since JWare/AntX 0.5
227      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
228      * @version 0.5
229      * @.group impl,helper
230      **/

231 // public static class ForComposite implements LogEnabled
232
// {
233
// private final LogEnabled m_singularity;
234
//
235
// /**
236
// * Initializes a new adapter for given source.
237
// * @param original the original source of request (non-null)
238
// */
239
// public ForComposite(LogEnabled original) {
240
// if (original==null) {
241
// throw new IllegalArgumentException();
242
// }
243
// this.m_singularity = original;
244
// }
245
//
246
// public void log(String message) {
247
// m_singularity.log(message);
248
// }
249
//
250
// public void log(String message, int msgLevel) {
251
// m_singularity.log(message,msgLevel);
252
// }
253
// /** Returns the underlying source for this adapter. **/
254
// public final LogEnabled getLogImpl() {
255
// return m_singularity;
256
// }
257
// }
258
}
259
260 /* end-of-LogEnabled.java */
261
Popular Tags