001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 1999 The Apache Software Foundation. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by the
022: * Apache Software Foundation (http://www.apache.org/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
027: * Foundation" must not be used to endorse or promote products derived
028: * from this software without prior written permission. For written
029: * permission, please contact apache@apache.org.
030: *
031: * 5. Products derived from this software may not be called "Apache"
032: * nor may "Apache" appear in their names without prior written
033: * permission of the Apache Group.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: *
049: * This software consists of voluntary contributions made by many
050: * individuals on behalf of the Apache Software Foundation. For more
051: * information on the Apache Software Foundation, please see
052: * <http://www.apache.org/>.
053: *
054: */
055:
056: package org.jbpm.jpdl.el.impl;
057:
058: import java.io.PrintStream;
059: import java.text.MessageFormat;
060:
061: import org.jbpm.jpdl.el.ELException;
062:
063: /**
064: *
065: * <p>The evaluator may pass an instance of this class to operators
066: * and expressions during evaluation. They should use this to log any
067: * warning or error messages that might come up. This allows all of
068: * our logging policies to be concentrated in one class.
069: *
070: * <p>Errors are conditions that are severe enough to abort operation.
071: * Warnings are conditions through which the operation may continue,
072: * but which should be reported to the developer.
073: *
074: * @author Nathan Abramson - Art Technology Group
075: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
076: **/
077:
078: public class Logger {
079: //-------------------------------------
080: // Member variables
081: //-------------------------------------
082:
083: PrintStream mOut;
084:
085: //-------------------------------------
086: /**
087: *
088: * Constructor
089: *
090: * @param pOut the PrintStream to which warnings should be printed
091: **/
092: public Logger(PrintStream pOut) {
093: mOut = pOut;
094: }
095:
096: //-------------------------------------
097: /**
098: *
099: * Returns true if the application should even bother to try logging
100: * a warning.
101: **/
102: public boolean isLoggingWarning() {
103: return false;
104: }
105:
106: //-------------------------------------
107: /**
108: *
109: * Logs a warning
110: **/
111: public void logWarning(String pMessage, Throwable pRootCause)
112: throws ELException {
113: if (isLoggingWarning()) {
114: if (pMessage == null) {
115: System.out.println(pRootCause);
116: } else if (pRootCause == null) {
117: System.out.println(pMessage);
118: } else {
119: System.out.println(pMessage + ": " + pRootCause);
120: }
121: }
122: }
123:
124: //-------------------------------------
125: /**
126: *
127: * Logs a warning
128: **/
129: public void logWarning(String pTemplate) throws ELException {
130: if (isLoggingWarning()) {
131: logWarning(pTemplate, null);
132: }
133: }
134:
135: //-------------------------------------
136: /**
137: *
138: * Logs a warning
139: **/
140: public void logWarning(Throwable pRootCause) throws ELException {
141: if (isLoggingWarning()) {
142: logWarning(null, pRootCause);
143: }
144: }
145:
146: //-------------------------------------
147: /**
148: *
149: * Logs a warning
150: **/
151: public void logWarning(String pTemplate, Object pArg0)
152: throws ELException {
153: if (isLoggingWarning()) {
154: logWarning(MessageFormat.format(pTemplate,
155: new Object[] { "" + pArg0, }));
156: }
157: }
158:
159: //-------------------------------------
160: /**
161: *
162: * Logs a warning
163: **/
164: public void logWarning(String pTemplate, Throwable pRootCause,
165: Object pArg0) throws ELException {
166: if (isLoggingWarning()) {
167: logWarning(MessageFormat.format(pTemplate,
168: new Object[] { "" + pArg0, }), pRootCause);
169: }
170: }
171:
172: //-------------------------------------
173: /**
174: *
175: * Logs a warning
176: **/
177: public void logWarning(String pTemplate, Object pArg0, Object pArg1)
178: throws ELException {
179: if (isLoggingWarning()) {
180: logWarning(MessageFormat.format(pTemplate, new Object[] {
181: "" + pArg0, "" + pArg1, }));
182: }
183: }
184:
185: //-------------------------------------
186: /**
187: *
188: * Logs a warning
189: **/
190: public void logWarning(String pTemplate, Throwable pRootCause,
191: Object pArg0, Object pArg1) throws ELException {
192: if (isLoggingWarning()) {
193: logWarning(MessageFormat.format(pTemplate, new Object[] {
194: "" + pArg0, "" + pArg1, }), pRootCause);
195: }
196: }
197:
198: //-------------------------------------
199: /**
200: *
201: * Logs a warning
202: **/
203: public void logWarning(String pTemplate, Object pArg0,
204: Object pArg1, Object pArg2) throws ELException {
205: if (isLoggingWarning()) {
206: logWarning(MessageFormat.format(pTemplate, new Object[] {
207: "" + pArg0, "" + pArg1, "" + pArg2, }));
208: }
209: }
210:
211: //-------------------------------------
212: /**
213: *
214: * Logs a warning
215: **/
216: public void logWarning(String pTemplate, Throwable pRootCause,
217: Object pArg0, Object pArg1, Object pArg2)
218: throws ELException {
219: if (isLoggingWarning()) {
220: logWarning(MessageFormat.format(pTemplate, new Object[] {
221: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
222: }
223: }
224:
225: //-------------------------------------
226: /**
227: *
228: * Logs a warning
229: **/
230: public void logWarning(String pTemplate, Object pArg0,
231: Object pArg1, Object pArg2, Object pArg3)
232: throws ELException {
233: if (isLoggingWarning()) {
234: logWarning(MessageFormat.format(pTemplate, new Object[] {
235: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
236: }
237: }
238:
239: //-------------------------------------
240: /**
241: *
242: * Logs a warning
243: **/
244: public void logWarning(String pTemplate, Throwable pRootCause,
245: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
246: throws ELException {
247: if (isLoggingWarning()) {
248: logWarning(MessageFormat.format(pTemplate, new Object[] {
249: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
250: pRootCause);
251: }
252: }
253:
254: //-------------------------------------
255: /**
256: *
257: * Logs a warning
258: **/
259: public void logWarning(String pTemplate, Object pArg0,
260: Object pArg1, Object pArg2, Object pArg3, Object pArg4)
261: throws ELException {
262: if (isLoggingWarning()) {
263: logWarning(MessageFormat.format(pTemplate, new Object[] {
264: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
265: "" + pArg4, }));
266: }
267: }
268:
269: //-------------------------------------
270: /**
271: *
272: * Logs a warning
273: **/
274: public void logWarning(String pTemplate, Throwable pRootCause,
275: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
276: Object pArg4) throws ELException {
277: if (isLoggingWarning()) {
278: logWarning(MessageFormat.format(pTemplate, new Object[] {
279: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
280: "" + pArg4, }), pRootCause);
281: }
282: }
283:
284: //-------------------------------------
285: /**
286: *
287: * Logs a warning
288: **/
289: public void logWarning(String pTemplate, Object pArg0,
290: Object pArg1, Object pArg2, Object pArg3, Object pArg4,
291: Object pArg5) throws ELException {
292: if (isLoggingWarning()) {
293: logWarning(MessageFormat.format(pTemplate, new Object[] {
294: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
295: "" + pArg4, "" + pArg5, }));
296: }
297: }
298:
299: //-------------------------------------
300: /**
301: *
302: * Logs a warning
303: **/
304: public void logWarning(String pTemplate, Throwable pRootCause,
305: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
306: Object pArg4, Object pArg5) throws ELException {
307: if (isLoggingWarning()) {
308: logWarning(MessageFormat.format(pTemplate, new Object[] {
309: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
310: "" + pArg4, "" + pArg5, }), pRootCause);
311: }
312: }
313:
314: //-------------------------------------
315: /**
316: *
317: * Returns true if the application should even bother to try logging
318: * an error.
319: **/
320: public boolean isLoggingError() {
321: return true;
322: }
323:
324: //-------------------------------------
325: /**
326: *
327: * Logs an error
328: **/
329: public void logError(String pMessage, Throwable pRootCause)
330: throws ELException {
331: if (isLoggingError()) {
332: if (pMessage == null) {
333: throw new ELException(pRootCause);
334: } else if (pRootCause == null) {
335: throw new ELException(pMessage);
336: } else {
337: throw new ELException(pMessage, pRootCause);
338: }
339: }
340: }
341:
342: //-------------------------------------
343: /**
344: *
345: * Logs an error
346: **/
347: public void logError(String pTemplate) throws ELException {
348: if (isLoggingError()) {
349: logError(pTemplate, null);
350: }
351: }
352:
353: //-------------------------------------
354: /**
355: *
356: * Logs an error
357: **/
358: public void logError(Throwable pRootCause) throws ELException {
359: if (isLoggingError()) {
360: logError(null, pRootCause);
361: }
362: }
363:
364: //-------------------------------------
365: /**
366: *
367: * Logs an error
368: **/
369: public void logError(String pTemplate, Object pArg0)
370: throws ELException {
371: if (isLoggingError()) {
372: logError(MessageFormat.format(pTemplate, new Object[] { ""
373: + pArg0, }));
374: }
375: }
376:
377: //-------------------------------------
378: /**
379: *
380: * Logs an error
381: **/
382: public void logError(String pTemplate, Throwable pRootCause,
383: Object pArg0) throws ELException {
384: if (isLoggingError()) {
385: logError(MessageFormat.format(pTemplate, new Object[] { ""
386: + pArg0, }), pRootCause);
387: }
388: }
389:
390: //-------------------------------------
391: /**
392: *
393: * Logs an error
394: **/
395: public void logError(String pTemplate, Object pArg0, Object pArg1)
396: throws ELException {
397: if (isLoggingError()) {
398: logError(MessageFormat.format(pTemplate, new Object[] {
399: "" + pArg0, "" + pArg1, }));
400: }
401: }
402:
403: //-------------------------------------
404: /**
405: *
406: * Logs an error
407: **/
408: public void logError(String pTemplate, Throwable pRootCause,
409: Object pArg0, Object pArg1) throws ELException {
410: if (isLoggingError()) {
411: logError(MessageFormat.format(pTemplate, new Object[] {
412: "" + pArg0, "" + pArg1, }), pRootCause);
413: }
414: }
415:
416: //-------------------------------------
417: /**
418: *
419: * Logs an error
420: **/
421: public void logError(String pTemplate, Object pArg0, Object pArg1,
422: Object pArg2) throws ELException {
423: if (isLoggingError()) {
424: logError(MessageFormat.format(pTemplate, new Object[] {
425: "" + pArg0, "" + pArg1, "" + pArg2, }));
426: }
427: }
428:
429: //-------------------------------------
430: /**
431: *
432: * Logs an error
433: **/
434: public void logError(String pTemplate, Throwable pRootCause,
435: Object pArg0, Object pArg1, Object pArg2)
436: throws ELException {
437: if (isLoggingError()) {
438: logError(MessageFormat.format(pTemplate, new Object[] {
439: "" + pArg0, "" + pArg1, "" + pArg2, }), pRootCause);
440: }
441: }
442:
443: //-------------------------------------
444: /**
445: *
446: * Logs an error
447: **/
448: public void logError(String pTemplate, Object pArg0, Object pArg1,
449: Object pArg2, Object pArg3) throws ELException {
450: if (isLoggingError()) {
451: logError(MessageFormat.format(pTemplate, new Object[] {
452: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }));
453: }
454: }
455:
456: //-------------------------------------
457: /**
458: *
459: * Logs an error
460: **/
461: public void logError(String pTemplate, Throwable pRootCause,
462: Object pArg0, Object pArg1, Object pArg2, Object pArg3)
463: throws ELException {
464: if (isLoggingError()) {
465: logError(MessageFormat.format(pTemplate, new Object[] {
466: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3, }),
467: pRootCause);
468: }
469: }
470:
471: //-------------------------------------
472: /**
473: *
474: * Logs an error
475: **/
476: public void logError(String pTemplate, Object pArg0, Object pArg1,
477: Object pArg2, Object pArg3, Object pArg4)
478: throws ELException {
479: if (isLoggingError()) {
480: logError(MessageFormat.format(pTemplate, new Object[] {
481: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
482: "" + pArg4, }));
483: }
484: }
485:
486: //-------------------------------------
487: /**
488: *
489: * Logs an error
490: **/
491: public void logError(String pTemplate, Throwable pRootCause,
492: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
493: Object pArg4) throws ELException {
494: if (isLoggingError()) {
495: logError(MessageFormat.format(pTemplate, new Object[] {
496: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
497: "" + pArg4, }), pRootCause);
498: }
499: }
500:
501: //-------------------------------------
502: /**
503: *
504: * Logs an error
505: **/
506: public void logError(String pTemplate, Object pArg0, Object pArg1,
507: Object pArg2, Object pArg3, Object pArg4, Object pArg5)
508: throws ELException {
509: if (isLoggingError()) {
510: logError(MessageFormat.format(pTemplate, new Object[] {
511: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
512: "" + pArg4, "" + pArg5, }));
513: }
514: }
515:
516: //-------------------------------------
517: /**
518: *
519: * Logs an error
520: **/
521: public void logError(String pTemplate, Throwable pRootCause,
522: Object pArg0, Object pArg1, Object pArg2, Object pArg3,
523: Object pArg4, Object pArg5) throws ELException {
524: if (isLoggingError()) {
525: logError(MessageFormat.format(pTemplate, new Object[] {
526: "" + pArg0, "" + pArg1, "" + pArg2, "" + pArg3,
527: "" + pArg4, "" + pArg5, }), pRootCause);
528: }
529: }
530:
531: //-------------------------------------
532: }
|