KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > processor > LogProcessorFactory


1 package org.jzonic.jlo.processor;
2
3 import java.io.InputStream JavaDoc;
4 import java.util.Properties JavaDoc;
5 /**
6  * This class instantiates the specific LogProcessor. This LogProcessor
7  * is defined in the jlo.properties as
8  * <pre>
9  * processor=direct
10  * </pre>
11  * for direct processing or
12  * <pre>
13  * processor=asynchronous
14  * </pre>
15  * for asynchronous logging. If the property is not set then the
16  * asynchronous LogProcessor is used by default.
17  *
18  * @author Andreas Mecky andreas.mecky@xcom.de
19  * @author Terry Dye terry.dye@xcom.de
20  */

21 public class LogProcessorFactory {
22     
23     private static LogProcessor lp = null;
24     private static LogProcessorFactory lpf = null;
25     
26     private LogProcessorFactory() {
27         try {
28             ClassLoader JavaDoc cl = this.getClass().getClassLoader();
29             InputStream JavaDoc fis = cl.getResourceAsStream("jlo.properties");
30             if ( fis == null ) {
31                 lp = new AsynchronousLogProcessor();
32             }
33             else {
34                 Properties JavaDoc properties = new Properties JavaDoc();
35                 properties.load(fis);
36                 String JavaDoc ptype = properties.getProperty("processor");
37                 if ( ptype != null ) {
38                     if ( ptype.equalsIgnoreCase("direct") ) {
39                         lp = new DirectLogProcessor();
40                     }
41                     else {
42                         lp = new AsynchronousLogProcessor();
43                     }
44                 }
45                 else {
46                     lp = new AsynchronousLogProcessor();
47                 }
48             }
49         }
50         catch (Exception JavaDoc e) {
51             lp = new AsynchronousLogProcessor();
52         }
53         
54     }
55         
56     public static LogProcessor getLogProcessor() {
57         if ( lpf == null ) {
58             lpf = new LogProcessorFactory();
59         }
60         return lp;
61     }
62     
63     public void flush() {
64         lp.flush();
65     }
66     
67 }
68
Popular Tags