KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > log > LogConfiguration


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package se.anatom.ejbca.log;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.HashMap JavaDoc;
18
19 import org.ejbca.core.model.log.LogEntry;
20
21
22 /**
23  * TODO: remove this whole class method for EJBCA 3.3.
24  *
25  * Class containing the log configuration data. Tells which events should be logged and if internal
26  * log database and/or external logging device should be used.
27  *
28  * @version $Id: LogConfiguration.java,v 1.12 2006/01/26 14:18:20 anatom Exp $
29  */

30 public class LogConfiguration implements Serializable JavaDoc {
31     private static final long serialVersionUID = -6349974447455748715L;
32
33     // Public constants
34
// Constructors
35
public LogConfiguration() {
36         this.useexternaldevices = true;
37         this.uselogdb = true;
38         this.configurationdata = new HashMap JavaDoc();
39
40         // Fill log configuration data with values from LogEntry constants. Default is true for all events.
41
for (int i = 0; i < LogEntry.EVENTNAMES_INFO.length; i++) {
42             configurationdata.put(new Integer JavaDoc(i), Boolean.TRUE);
43         }
44
45         for (int i = 0; i < LogEntry.EVENTNAMES_ERROR.length; i++) {
46             configurationdata.put(new Integer JavaDoc(i + LogEntry.EVENT_ERROR_BOUNDRARY), Boolean.TRUE);
47         }
48     }
49
50     // Public Methods
51
public boolean logEvent(int event) {
52         Boolean JavaDoc log = (Boolean JavaDoc) configurationdata.get(new Integer JavaDoc(event));
53
54         if (log == null) {
55             return true; // Default is log everything.
56
}
57         return log.booleanValue();
58     }
59
60     /**
61      * DOCUMENT ME!
62      *
63      * @param event DOCUMENT ME!
64      *
65      * @return DOCUMENT ME!
66      */

67     public Boolean JavaDoc getLogEvent(int event) {
68         return (Boolean JavaDoc) configurationdata.get(new Integer JavaDoc(event));
69     }
70
71     /**
72      * DOCUMENT ME!
73      *
74      * @param event DOCUMENT ME!
75      * @param log DOCUMENT ME!
76      */

77     public void setLogEvent(int event, boolean log) {
78         configurationdata.put(new Integer JavaDoc(event), Boolean.valueOf(log));
79     }
80
81     /**
82      * DOCUMENT ME!
83      *
84      * @return DOCUMENT ME!
85      */

86     public boolean useLogDB() {
87         return uselogdb;
88     }
89
90     /**
91      * DOCUMENT ME!
92      *
93      * @param use DOCUMENT ME!
94      */

95     public void setUseLogDB(boolean use) {
96         this.uselogdb = use;
97     }
98
99     /**
100      * DOCUMENT ME!
101      *
102      * @return DOCUMENT ME!
103      */

104     public boolean useExternalLogDevices() {
105         return this.useexternaldevices;
106     }
107
108     /**
109      * DOCUMENT ME!
110      *
111      * @param use DOCUMENT ME!
112      */

113     public void setUseExternalLogDevices(boolean use) {
114         this.useexternaldevices = use;
115     }
116
117     // Private functions
118
public String JavaDoc getStringRepresentationOfEventId(int event) {
119         if (event >= LogEntry.EVENT_ERROR_BOUNDRARY) {
120             return LogEntry.EVENTNAMES_ERROR[event];
121         }
122         return LogEntry.EVENTNAMES_INFO[event];
123     }
124     /** Returns the complete map. Used for upgrading from EJBCA 3.1.x to 3.2.x.
125      * TODO: remove this whole class method for EJBCA 3.3.
126      *
127      * @return HashMap revealing internal implementation
128      */

129     public HashMap JavaDoc getConfigurationData() {
130         return this.configurationdata;
131     }
132
133     // Private fields
134
private HashMap JavaDoc configurationdata;
135     private boolean uselogdb;
136     private boolean useexternaldevices;
137 }
138
Popular Tags