KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > file > monolog > PropertiesConfAccess


1 /**
2  * Copyright (C) 2001-2003 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.util.monolog.file.monolog;
20
21 import org.objectweb.util.monolog.api.Handler;
22 import org.objectweb.util.monolog.api.HandlerFactory;
23 import org.objectweb.util.monolog.api.Level;
24 import org.objectweb.util.monolog.api.LevelFactory;
25 import org.objectweb.util.monolog.api.Logger;
26 import org.objectweb.util.monolog.api.LoggerFactory;
27 import org.objectweb.util.monolog.api.TopicalLogger;
28 import org.objectweb.util.monolog.api.BasicLevel;
29 import org.objectweb.util.monolog.api.MonologFactory;
30 import org.objectweb.util.monolog.file.DottedStringTools;
31 import org.objectweb.util.monolog.wrapper.common.LevelImpl;
32
33 import java.io.PrintStream JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35 import java.io.Serializable JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Properties JavaDoc;
38 import java.util.StringTokenizer JavaDoc;
39 import java.util.Vector JavaDoc;
40
41 /**
42  * This class permits to load and store a monolog configuration. The chooseen
43  * format is java.util.Properties. It also easy to write or load a Properties
44  * from a file. The encoding format is the following:<br/>
45  * handler.<handler name>.<property name>=<property value><br/>
46  *<br/>
47  * level.<level name>=<integer value or string expression><br/>
48  *<br/>
49  * logger.<dotted logger name>.level=<level name><br/>
50  * logger.<dotted logger name>.additivity=<true | false><br/>
51  * logger.<dotted logger name>.handler.<number>=<handler name><br/>
52  * logger.<dotted logger name>.topic.<number>=<additionnal logger name><br/>
53  *<br/>
54  * @author Sebastien Chassande-Barrioz
55  */

56 public class PropertiesConfAccess implements Serializable JavaDoc {
57
58     /**
59      *
60      */

61     private static final long serialVersionUID = -321110630195680214L;
62     
63     public final static String JavaDoc LOGGER_FIELD = "logger";
64     public final static String JavaDoc ACTIVATION = "activation";
65     public final static String JavaDoc ADDITIVITY_FIELD = "additivity";
66     public final static String JavaDoc USE_PARENT_FIELD = "useParent";
67     public final static String JavaDoc HANDLER_FIELD = "handler";
68     public final static String JavaDoc LEVEL_FIELD = "level";
69     public final static String JavaDoc TOPIC_FIELD = "topic";
70     public final static String JavaDoc CLEAN_HANDLERS_FIELD = "cleanHandlers";
71     public final static char DOT = '.';
72
73     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE = "type";
74
75     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE_FILE_VALUE = "file";
76     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE_CONSOLE_VALUE = "console";
77     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE_ROLLING_FILE_VALUE = "rollingfile";
78     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE_NTEVENT_VALUE = "ntevent";
79     public final static String JavaDoc HANDLER_TYPE_ATTRIBUTE_JMX_VALUE = "jmx";
80
81     public static boolean debug = new Boolean JavaDoc(
82             System.getProperty("monolog.debug")).booleanValue();
83
84     public static void load(Properties JavaDoc prop, LoggerFactory lof, HandlerFactory hf,
85                             LevelFactory lef) throws Exception JavaDoc {
86         new PropertiesConfAccess().read(prop, lof, hf, lef);
87     }
88
89     public static void load(Properties JavaDoc prop, MonologFactory mf) throws Exception JavaDoc {
90         new PropertiesConfAccess().read(prop, mf, mf, mf);
91     }
92
93     public static void store(Properties JavaDoc prop, LoggerFactory lof, HandlerFactory hf,
94                              LevelFactory lef) throws Exception JavaDoc {
95         new PropertiesConfAccess().write(prop, lof, hf, lef);
96     }
97
98     public static void store(Properties JavaDoc prop, MonologFactory mf) throws Exception JavaDoc {
99         new PropertiesConfAccess().write(prop, mf, mf, mf);
100     }
101
102     public void read(Properties JavaDoc prop, LoggerFactory lof, HandlerFactory hf,
103                      LevelFactory lef) throws Exception JavaDoc {
104         read(prop, (MonologFactory) lof);
105     }
106     public void read(Properties JavaDoc prop, MonologFactory mf) throws Exception JavaDoc {
107         //Remove the handlers of the loggers which have the property
108
//CLEAN_HANDLERS_FIELD
109
for (Enumeration JavaDoc e = prop.keys(); e.hasMoreElements();) {
110             String JavaDoc key = ((String JavaDoc) e.nextElement());
111             if (key.startsWith(LOGGER_FIELD + DOT)
112                     && key.endsWith(DOT + CLEAN_HANDLERS_FIELD)
113                     && Boolean.getBoolean(prop.getProperty(key).trim())) {
114                 String JavaDoc loggerName = key.substring(
115                         LOGGER_FIELD.length() + 1,
116                         key.length() - 1 - CLEAN_HANDLERS_FIELD.length());
117                 ((TopicalLogger) mf.getLogger(loggerName)).removeAllHandlers();
118             }
119         }
120         //Parse logger and level definition
121
for (Enumeration JavaDoc en = prop.keys(); en.hasMoreElements();) {
122             String JavaDoc key = (String JavaDoc) en.nextElement();
123             if (key.startsWith(LOGGER_FIELD + DOT)) {
124                 parseLoggerProp(prop, key, mf);
125             } else if (key.startsWith(LEVEL_FIELD + DOT)) {
126                 parseLevelProp(prop, key, mf);
127             }
128         }
129         //Parse all handlers
130
Vector JavaDoc hs = new Vector JavaDoc(); //contains the list of handler to activate
131
for (Enumeration JavaDoc en = prop.keys(); en.hasMoreElements();) {
132             String JavaDoc key = (String JavaDoc) en.nextElement();
133             if (key.startsWith(HANDLER_FIELD + DOT)) {
134                 String JavaDoc handlerName = DottedStringTools.getBegin(
135                         DottedStringTools.getEnd(key));
136                 Handler h = mf.getHandler(handlerName);
137                 if (h != null && !hs.contains(h)) {
138                     //Activate only used handler
139
hs.addElement(h);
140                 } // do not activate unsued handler
141
parseHandlerProp(prop, key, mf);
142             }
143         }
144         //Activates used handlers only
145
for (int i = 0; i < hs.size(); i++) {
146             ((Handler) hs.elementAt(i)).setAttribute("activation", mf);
147         }
148     }
149
150     public void write(Properties JavaDoc prop, LoggerFactory lof, HandlerFactory hf,
151                       LevelFactory lef) throws Exception JavaDoc {
152
153         // Set the level definitions
154
String JavaDoc key = null;
155         String JavaDoc val = null;
156         Level[] levels = lef.getLevels();
157         for (int i = 0; i < levels.length; i++) {
158             if (!isDefaultLevel(levels[i])) {
159                 key = LEVEL_FIELD + DOT + levels[i].getName();
160                 val = ((LevelImpl) levels[i]).getStringValue();
161                 debug(key + " " + val);
162                 prop.put(key, val.trim());
163             }
164         }
165
166         // Set the handler definitions
167
Handler[] handlers = hf.getHandlers();
168         for (int i = 0; i < handlers.length; i++) {
169             key = HANDLER_FIELD + DOT + handlers[i].getName() + DOT + HANDLER_TYPE_ATTRIBUTE;
170             val = handlers[i].getType();
171             debug(key + " " + val);
172             prop.put(key, val);
173             String JavaDoc[] ats = handlers[i].getAttributeNames();
174             for (int j = 0; j < ats.length; j++) {
175                 key = HANDLER_FIELD + DOT + handlers[i].getName() + DOT + ats[j];
176                 Object JavaDoc o = handlers[i].getAttribute(ats[j]);
177                 if (o instanceof String JavaDoc) {
178                     val = (String JavaDoc) o;
179                     debug(key + " " + val);
180                     prop.put(key, val.trim());
181                 }
182             }
183         }
184
185         //Write the logger definition
186
TopicalLogger[] loggers = (TopicalLogger[]) lof.getLoggers();
187         final String JavaDoc topicPrefix = lof.getTopicPrefix();
188         for (int i = 0; i < loggers.length; i++) {
189             String JavaDoc[] topics = loggers[i].getTopic();
190             if (topics.length == 0) {
191                 throw new Exception JavaDoc(
192                         "Impossible to set the definition of a logger without name");
193             }
194             String JavaDoc topic = loggers[i].getTopic()[0];
195             if (topicPrefix != null && topic.startsWith(topicPrefix)) {
196                 topic = topic.substring(topicPrefix.length());
197             }
198             String JavaDoc begin = LOGGER_FIELD + DOT + topic;
199
200             if (!loggers[i].getAdditivity()) {
201                 key = begin + DOT + ADDITIVITY_FIELD;
202                 val = "false";
203                 debug(key + " " + val);
204                 prop.put(key, val.trim());
205             }
206
207             Level level = loggers[i].getCurrentLevel();
208             if (level != null && level.getIntValue() != BasicLevel.INHERIT) {
209                 key = begin + DOT + LEVEL_FIELD;
210                 val = " " + level.getName();
211                 debug(key + " " + val);
212                 prop.put(key, val.trim());
213             }
214
215             handlers = loggers[i].getHandler();
216             if (handlers != null && handlers.length > 0) {
217                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
218                 String JavaDoc sep = "";
219                 for (int j = 0; j < handlers.length; j++) {
220                     if (handlers[j].getName() != null) {
221                         sb.append(sep);
222                         sep = ", ";
223                         sb.append(handlers[j].getName());
224                     }
225                 }
226                 debug(begin + DOT + HANDLER_FIELD + " " + sb.toString());
227                 prop.put(begin + DOT + HANDLER_FIELD, sb.toString());
228             }
229
230             if (topics.length > 1) {
231                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
232                 String JavaDoc sep = "";
233                 for (int j = 1; j < topics.length; j++) {
234                     sb.append(sep);
235                     sep = ", ";
236                     String JavaDoc ntopic = topics[j];
237                     if (topicPrefix != null && ntopic.startsWith(topicPrefix)) {
238                         ntopic = ntopic.substring(topicPrefix.length());
239                     }
240                     sb.append(ntopic);
241                 }
242                 debug(begin + DOT + TOPIC_FIELD + " " + sb.toString());
243                 prop.put(begin + DOT + TOPIC_FIELD, sb.toString());
244             }
245         }
246     }
247
248     /**
249      * It checks if the level parameter is a default monolog level. The default
250      * monolog levels are the following:
251      * <ul>
252      * <li>FATAL</li>
253      * <li>ERROR</li>
254      * <li>WARN</li>
255      * <li>INFO</li>
256      * <li>DEBUG</li>
257      * </ul>
258      */

259     protected boolean isDefaultLevel(Level l) {
260         return (l.getName().equalsIgnoreCase("DEBUG")
261                 || l.getName().equalsIgnoreCase("INFO")
262                 || l.getName().equalsIgnoreCase("WARN")
263                 || l.getName().equalsIgnoreCase("ERROR")
264                 || l.getName().equalsIgnoreCase("FATAL")
265                 || l.getName().equalsIgnoreCase("INHERIT")
266                 );
267     }
268
269     //------------ PARSING METHODS ------------//
270
//-----------------------------------------//
271

272     /**
273      * It parses a property entry to build or configure a Logger instance.
274      * @param prop is the property where the entry is reachable.
275      * @param key is the entry key
276      * @param lof is the logger factory to use for building a new instance or
277      * fetching existent loggers.
278      * @param hf is the handler factory to use for building a new instance or
279      * fetching existent handlers.
280      * @param lef is the level factory to use for building a new instance or
281      * fetching existent levels.
282      * @return the level instance which has been built or configured
283      * @throws Exception when a parameter is null or the entry is malformed.
284      */

285     protected Logger parseLoggerProp(Properties JavaDoc prop,
286                                      String JavaDoc key,
287                                      LoggerFactory lof,
288                                      HandlerFactory hf,
289                                      LevelFactory lef) throws Exception JavaDoc {
290         return parseLoggerProp(prop, key, (MonologFactory) lof);
291     }
292     /**
293      * It parses a property entry to build or configure a Logger instance.
294      * @param prop is the property where the entry is reachable.
295      * @param key is the entry key
296      * @param mf is the monolog factory to use for building a new instance or
297      * fetching existent loggers, handlers or levels.
298      * @return the level instance which has been built or configured
299      * @throws Exception when a parameter is null or the entry is malformed.
300      */

301     protected Logger parseLoggerProp(Properties JavaDoc prop,
302                                      String JavaDoc key,
303                                      MonologFactory mf) throws Exception JavaDoc {
304         if (prop == null
305                 || key == null
306                 || mf == null) {
307             throw new Exception JavaDoc("The null parameters are not allowed");
308         }
309
310         String JavaDoc temp = DottedStringTools.getFirst(key);
311         if (temp == null || !temp.equalsIgnoreCase(LOGGER_FIELD)) {
312             throw new Exception JavaDoc(
313                     "This key is not a Logger property:" + key);
314         }
315
316         TopicalLogger logger = null;
317         temp = DottedStringTools.getEnd(key);
318         String JavaDoc last = DottedStringTools.getLast(temp);
319         if (last.equalsIgnoreCase(LEVEL_FIELD)) {
320             // Assigns the level of the logger
321
logger = (TopicalLogger)
322                     mf.getLogger(DottedStringTools.getBegin(temp));
323             String JavaDoc levelName = prop.getProperty(key).trim();
324             Level l = mf.getLevel(levelName);
325             if (l == null) {
326                 l = parseLevelProp(prop, LEVEL_FIELD + DOT + levelName, mf);
327             }
328             if (debug) {
329                 debug("set level to " + l.getName() + " to the logger " + logger.getName());
330             }
331             logger.setLevel(l);
332         } else if (ADDITIVITY_FIELD.equalsIgnoreCase(last)
333                 || USE_PARENT_FIELD.equalsIgnoreCase(last)) {
334             logger = (TopicalLogger)
335                     mf.getLogger(DottedStringTools.getBegin(temp));
336             boolean a = Boolean.getBoolean(prop.getProperty(key).trim());
337             if (debug) {
338                 debug("set additivity to " + a + " to the logger " + logger.getName());
339             }
340             logger.setAdditivity(a);
341         } else if (CLEAN_HANDLERS_FIELD.equalsIgnoreCase(last)) {
342             //Already managed iin the read method
343
} else if (HANDLER_FIELD.equalsIgnoreCase(last)) {
344             String JavaDoc value = prop.getProperty(key).trim();
345             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(value, ", ;:", false);
346             logger = (TopicalLogger)
347                     mf.getLogger(DottedStringTools.getBegin(temp));
348             cleanOldHandler(logger);
349             while(st.hasMoreTokens()) {
350                 String JavaDoc hn = st.nextToken();
351                 Handler h = mf.getHandler(hn);
352                 if (h == null) {
353                     h = parseHandlerProp(prop, HANDLER_FIELD + DOT + value
354                             + DOT + HANDLER_TYPE_ATTRIBUTE, mf);
355                 }
356                 if (debug) {
357                     debug("add handler " + h.getName() + " to the logger " + logger.getName());
358                 }
359                 logger.addHandler(h);
360             }
361         } else if (TOPIC_FIELD.equalsIgnoreCase(last)) {
362             logger = (TopicalLogger)
363                 mf.getLogger(DottedStringTools.getBegin(temp));
364             String JavaDoc value = prop.getProperty(key).trim();
365             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(value, ", ;:", false);
366             cleanOldHandler(logger);
367             while(st.hasMoreTokens()) {
368                 String JavaDoc topic = st.nextToken();
369                 if (debug) {
370                     debug("add topic " + topic + " to the logger " + logger.getName());
371                 }
372                 logger.addTopic(topic);
373             }
374         } else { //old declaration
375
temp = DottedStringTools.getBegin(temp); // remove the number
376
last = DottedStringTools.getLast(temp); // attribute name
377
temp = DottedStringTools.getBegin(temp); // logger name
378
logger = (TopicalLogger) mf.getLogger(temp);
379             if (last.equalsIgnoreCase(HANDLER_FIELD)) {
380                 // Assign an handler to a logger
381
String JavaDoc value = prop.getProperty(key).trim();
382                 Handler h = mf.getHandler(value);
383                 if (h == null) {
384                     h = parseHandlerProp(prop, HANDLER_FIELD + DOT + value
385                             + DOT + HANDLER_TYPE_ATTRIBUTE, mf);
386                 }
387                 cleanOldHandler(logger);
388                 if (debug) {
389                     debug("add handler " + h.getName() + " to the logger " + logger.getName());
390                 }
391                 logger.addHandler(h);
392             } else if (last.equalsIgnoreCase(TOPIC_FIELD)) {
393                 // Assign a topic to a logger
394
String JavaDoc topic = prop.getProperty(key).trim();
395                 if (debug) {
396                     debug("add topic " + topic + " to the logger " + logger.getName());
397                 }
398                 logger.addTopic(topic);
399             } else {
400                 throw new Exception JavaDoc(
401                         "Unknown definition" + key + " " + prop.getProperty(key));
402             }
403         }
404         return logger;
405     }
406
407     /**
408      * It parses a property entry to build or configure a Handler instance.
409      * @param prop is the property where the entry is reachable.
410      * @param key is the entry key
411      * @param hf is the handler factory to use for building a new instance or
412      * fetching existent handlers.
413      * @return the handler instance which has been built or configured
414      * @throws Exception when a parameter is null or the entry is malformed.
415      */

416     protected Handler parseHandlerProp(Properties JavaDoc prop,
417                                        String JavaDoc key,
418                                        HandlerFactory hf) throws Exception JavaDoc {
419
420         if (prop == null
421                 || key == null
422                 || hf == null) {
423             throw new Exception JavaDoc("The null parameters are not allowed");
424         }
425         String JavaDoc temp = DottedStringTools.getFirst(key);
426         if (temp == null || !temp.equalsIgnoreCase(HANDLER_FIELD)) {
427             throw new Exception JavaDoc(
428                     "This key is not a Handler field:" + key);
429         }
430         temp = DottedStringTools.getEnd(key);
431         String JavaDoc attribute = DottedStringTools.getLast(temp);
432         String JavaDoc handlerName = DottedStringTools.getBegin(temp);
433         Handler hc = hf.getHandler(handlerName);
434         if (hc == null) {
435             String JavaDoc stringType = prop.getProperty(HANDLER_FIELD + DOT + handlerName
436                     + DOT + HANDLER_TYPE_ATTRIBUTE, null);
437             if (stringType == null) {
438                 throw new Exception JavaDoc("Impossible to define the handler "
439                         + temp + ": the type is not defined");
440             }
441             hc = hf.createHandler(handlerName, stringType);
442             if (hc == null) {
443                 throw new Exception JavaDoc(
444                         "The HandlerFactory does not create the Handler: name="
445                         + handlerName + " / type=" + stringType);
446             }
447         }
448         if (hc != null && !HANDLER_TYPE_ATTRIBUTE.equalsIgnoreCase(attribute)) {
449             String JavaDoc v = prop.getProperty(key).trim();
450             if (debug) {
451                 debug("assign property (" + attribute + ", " + v
452                         + ") to the handler '" + handlerName);
453             }
454             hc.setAttribute(attribute, v);
455         }
456         return hc;
457     }
458
459     /**
460      * It parses a property entry to build or configure a Level instance.
461      * @param prop is the property where the entry is reachable.
462      * @param key is the entry key
463      * @param lef is the level factory to use for building a new instance or
464      * fetching existent levels.
465      * @return the level instance which has been built or configured
466      * @throws Exception when a circular level definition is found or when a
467      * parameter is null or the entry is malformed.
468      */

469     protected Level parseLevelProp(Properties JavaDoc prop,
470                                    String JavaDoc key,
471                                    LevelFactory lef) throws Exception JavaDoc {
472         return parseLevelProp(prop, key, lef, new Vector JavaDoc());
473     }
474
475     /**
476      * It parses a property entry to build or configure a Level instance.
477      * @param prop is the property where the entry is reachable.
478      * @param key is the entry key
479      * @param lef is the level factory to use for building a new instance or
480      * fetching existent levels.
481      * @param currentLevelParse the list of current level name which are
482      * searched.
483      * @throws Exception when a circular level definition is found or when a
484      * parameter is null.
485      */

486     protected Level parseLevelProp(Properties JavaDoc prop,
487                                    String JavaDoc key,
488                                    LevelFactory lef,
489                                    Vector JavaDoc currentLevelParse) throws Exception JavaDoc {
490         if (prop == null
491                 || key == null
492                 || lef == null) {
493             throw new Exception JavaDoc("The null parameters are not allowed");
494         }
495         String JavaDoc temp = DottedStringTools.getFirst(key);
496         if (temp == null || !temp.equalsIgnoreCase(LEVEL_FIELD))
497             throw new Exception JavaDoc("This key is not a level field:" + key);
498
499         temp = DottedStringTools.getEnd(key);
500         Level l = lef.getLevel(temp);
501         if (l == null) {
502             if (!prop.containsKey(key)) {
503                 throw new Exception JavaDoc("Level definition not found: " + key);
504             }
505             if (currentLevelParse.contains(temp)) {
506                 throw new Exception JavaDoc("Circular level definition: " + temp);
507             }
508             String JavaDoc levelValue = prop.getProperty(key).trim();
509             String JavaDoc[] depends = getDependsLevel(levelValue);
510             if (depends.length > 0) {
511                 currentLevelParse.addElement(temp);
512                 for (int i = 0; i < depends.length; i++) {
513                     parseLevelProp(prop, LEVEL_FIELD + DOT + depends[i],
514                             lef, currentLevelParse);
515                 }
516                 currentLevelParse.removeElement(temp);
517             }
518             l = lef.defineLevel(temp, levelValue);
519         }
520         return l;
521     }
522
523     /**
524      * It retrieves the list of the referenced levels in the String parameter.
525      * @param expr is a string which can contain level identifier. The string is
526      * an arithmetic expression which contains number, operator and levels
527      * identifier.
528      * @return the list of the referenced levels.
529      */

530     protected String JavaDoc[] getDependsLevel(String JavaDoc expr) {
531         Vector JavaDoc res = new Vector JavaDoc();
532         for (StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(expr, " +-", true);
533              st.hasMoreTokens();) {
534             String JavaDoc elem = st.nextToken();
535             if (Character.isLetter(elem.charAt(0))) {
536                 res.addElement(elem);
537             }
538         }
539         String JavaDoc[] r = new String JavaDoc[res.size()];
540         res.copyInto(r);
541         return r;
542     }
543
544     protected Vector JavaDoc loggerCleaned = null;
545
546     /**
547      * Clear all the handlers associated to a logger which are not defined into
548      * this file
549      */

550     protected void cleanOldHandler(TopicalLogger l) throws Exception JavaDoc {
551         if (loggerCleaned == null) {
552             loggerCleaned = new Vector JavaDoc();
553         }
554         if (!loggerCleaned.contains(l)) {
555             loggerCleaned.addElement(l);
556             l.removeAllHandlers();
557         }
558     }
559
560     /**
561      * This exception encapsulates an other exception.
562      */

563     class NestedException extends Exception JavaDoc {
564         
565         /**
566          *
567          */

568         private static final long serialVersionUID = -1218233947556357710L;
569         
570         Exception JavaDoc nestedException = null;
571
572         public NestedException() {
573             super();
574         }
575
576         public NestedException(Exception JavaDoc e) {
577             super();
578             nestedException = e;
579         }
580
581         public NestedException(Exception JavaDoc e, String JavaDoc msg) {
582             super(msg);
583             nestedException = e;
584         }
585
586         public Exception JavaDoc getNestedException() {
587             return nestedException;
588         }
589
590         public void printStackTrace(PrintStream JavaDoc ps) {
591             if (nestedException != null) {
592                 ps.println("Nested: " + getMessage());
593                 nestedException.printStackTrace(ps);
594             } else {
595                 super.printStackTrace(ps);
596             }
597         }
598
599         public void printStackTrace(PrintWriter JavaDoc w) {
600             if (nestedException != null) {
601                 w.println("Nested: " + getMessage());
602                 nestedException.printStackTrace(w);
603             } else {
604                 super.printStackTrace(w);
605             }
606         }
607
608         public void printStackTrace() {
609             printStackTrace(new PrintStream JavaDoc(System.out));
610         }
611
612     }
613
614     public void debug(String JavaDoc m) {
615         if (debug) {
616             System.out.println(m);
617         }
618     }
619 }
620
Popular Tags