KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > 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 org.ejbca.core.model.log;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.HashMap JavaDoc;
18
19
20 /**
21  * Class containing the log configuration data. Tells which events should be logged and if internal
22  * log database and/or external logging device should be used.
23  *
24  * @version $Id: LogConfiguration.java,v 1.2 2006/01/26 14:17:58 anatom Exp $
25  */

26 public class LogConfiguration implements Serializable JavaDoc {
27     
28     /**
29      * Determines if a de-serialized file is compatible with this class.
30      *
31      * Maintainers must change this value if and only if the new version
32      * of this class is not compatible with old versions. See Sun docs
33      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
34      * /serialization/spec/version.doc.html> details. </a>
35      *
36      */

37     private static final long serialVersionUID = -6349974447455748715L;
38     
39     // Public constants
40
// Constructors
41
public LogConfiguration() {
42         this.useexternaldevices = true;
43         this.uselogdb = true;
44         this.configurationdata = new HashMap JavaDoc();
45
46         // Fill log configuration data with values from LogEntry constants. Default is true for all events.
47
for (int i = 0; i < LogEntry.EVENTNAMES_INFO.length; i++) {
48             configurationdata.put(new Integer JavaDoc(i), Boolean.TRUE);
49         }
50
51         for (int i = 0; i < LogEntry.EVENTNAMES_ERROR.length; i++) {
52             configurationdata.put(new Integer JavaDoc(i + LogEntry.EVENT_ERROR_BOUNDRARY), Boolean.TRUE);
53         }
54     }
55     /** Used for upgrading from EJBCA 3.1.x to 3.2.x.
56      * TODO: remove this whole class method for EJBCA 3.3.
57      */

58     public LogConfiguration(boolean usedb, boolean useext, HashMap JavaDoc data) {
59         this.configurationdata = data;
60         this.uselogdb = usedb;
61         this.useexternaldevices = useext;
62     }
63
64     // Public Methods
65
public boolean logEvent(int event) {
66         Boolean JavaDoc log = (Boolean JavaDoc) configurationdata.get(new Integer JavaDoc(event));
67
68         if (log == null) {
69             return true; // Default is log everything.
70
}
71         return log.booleanValue();
72     }
73
74     /**
75      * DOCUMENT ME!
76      *
77      * @param event DOCUMENT ME!
78      *
79      * @return DOCUMENT ME!
80      */

81     public Boolean JavaDoc getLogEvent(int event) {
82         return (Boolean JavaDoc) configurationdata.get(new Integer JavaDoc(event));
83     }
84
85     /**
86      * DOCUMENT ME!
87      *
88      * @param event DOCUMENT ME!
89      * @param log DOCUMENT ME!
90      */

91     public void setLogEvent(int event, boolean log) {
92         configurationdata.put(new Integer JavaDoc(event), Boolean.valueOf(log));
93     }
94
95     /**
96      * DOCUMENT ME!
97      *
98      * @return DOCUMENT ME!
99      */

100     public boolean useLogDB() {
101         return uselogdb;
102     }
103
104     /**
105      * DOCUMENT ME!
106      *
107      * @param use DOCUMENT ME!
108      */

109     public void setUseLogDB(boolean use) {
110         this.uselogdb = use;
111     }
112
113     /**
114      * DOCUMENT ME!
115      *
116      * @return DOCUMENT ME!
117      */

118     public boolean useExternalLogDevices() {
119         return this.useexternaldevices;
120     }
121
122     /**
123      * DOCUMENT ME!
124      *
125      * @param use DOCUMENT ME!
126      */

127     public void setUseExternalLogDevices(boolean use) {
128         this.useexternaldevices = use;
129     }
130
131     // Private functions
132
public String JavaDoc getStringRepresentationOfEventId(int event) {
133         if (event >= LogEntry.EVENT_ERROR_BOUNDRARY) {
134             return LogEntry.EVENTNAMES_ERROR[event];
135         }
136         return LogEntry.EVENTNAMES_INFO[event];
137     }
138
139     // Private fields
140
private HashMap JavaDoc configurationdata;
141     private boolean uselogdb;
142     private boolean useexternaldevices;
143 }
144
Popular Tags