KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > ServiceConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics;
24
25 import java.io.File JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import com.sun.logging.LogDomains;
29 import com.sun.enterprise.config.serverbeans.ServerTags;
30 import com.sun.enterprise.diagnostics.Constants;
31
32 /**
33  * Represents diagnostic service related config information from domain.xml
34  * @author Manisha Umbarje
35  */

36 public class ServiceConfig {
37
38     private static Logger JavaDoc logger =
39             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
40     private String JavaDoc logFile;
41     private int minLogLevel;
42     private int maxNoOfEntries ;
43     private String JavaDoc repositoryDir;
44     private String JavaDoc instanceName;
45     private boolean local;
46     private boolean captureSystemInfoEnabled;
47     private boolean captureChecksumEnabled = true;
48     private boolean captureAppDDEnabled = true;
49     private boolean captureInstallLogEnabled = true;
50     private boolean verifyDomainEnabled = true;
51     private boolean captureHadbInfoEnabled ;
52     private ServiceConfigHelper configHelper;
53
54     public ServiceConfig(boolean localFlag, String JavaDoc repositoryDir,
55             String JavaDoc instanceName) throws DiagnosticException {
56     local = localFlag;
57     this.repositoryDir = repositoryDir;
58     this.instanceName = instanceName;
59     setValues();
60     }
61     
62     public ServiceConfig(boolean captureChecksumEnabled,
63             boolean captureAppDDEnabled, boolean captureInstallLogEnabled,
64             boolean verifyDomainEnabled, boolean captureHadbInfoEnabled,
65             boolean captureSystemInfoEnabled, int minLogLevel,
66             int maxNoOfEntries, String JavaDoc logFile, String JavaDoc repositoryDir,
67             String JavaDoc instanceName
68             ) {
69         this.captureChecksumEnabled = captureChecksumEnabled;
70         this.captureAppDDEnabled = captureAppDDEnabled;
71         this.captureInstallLogEnabled = captureInstallLogEnabled;
72         this.verifyDomainEnabled = verifyDomainEnabled;
73         this.captureHadbInfoEnabled = captureHadbInfoEnabled;
74         this.captureSystemInfoEnabled = captureSystemInfoEnabled;
75         this.minLogLevel = minLogLevel;
76         this.maxNoOfEntries = maxNoOfEntries;
77         this.logFile = logFile;
78         this.instanceName = instanceName;
79         this.repositoryDir = repositoryDir;
80     }
81
82     /**
83      * Returns value of max-log-entries of diagnostic-service
84      */

85     public int getMaxNoOfEntries() {
86     return maxNoOfEntries;
87     }
88
89     /**
90      * Returns value of min-log-level of diagnostic-service
91      */

92     public int getMinLogLevel() {
93     return minLogLevel;
94     }
95
96     /**
97      * Returns value of file of log-service
98      */

99     public String JavaDoc getLogFile() {
100     return logFile;
101     }//getLogFile
102

103      /**
104      * Returns central or cache repository location
105      */

106     public String JavaDoc getRepositoryDir() {
107     return repositoryDir;
108     }
109
110  
111     /**
112      * Returns true capturing app DD is enabled
113      */

114     public boolean isCaptureAppDDEnabled() {
115     return captureAppDDEnabled;
116     }
117     
118     /**
119      * Returns true capturing install log is enabled
120      */

121     public boolean isCaptureInstallLogEnabled() {
122     return captureInstallLogEnabled;
123     }
124     
125     /**
126      * Returns true if output of verify-domain is captured
127      */

128     public boolean isVerifyDomainEnabled() {
129     return verifyDomainEnabled;
130     }
131
132     /**
133      * Returns true if check sum is captured
134      */

135     public boolean isCaptureChecksumEnabled() {
136     return captureChecksumEnabled;
137     }
138     /**
139      * Returns true capturing app DD is enabled
140      */

141     public boolean isCaptureHadbInfoEnabled() {
142     return captureHadbInfoEnabled;
143     }
144     
145     public String JavaDoc getInstanceName() {
146         return instanceName;
147     }
148
149     /**
150      * Returns true if output of verify-domain is captured
151      */

152     public boolean isCaptureSystemInfoEnabled() {
153     return captureSystemInfoEnabled;
154     }
155
156     /**
157      * Returns null, if ServiceConfig is created with default values.
158      */

159     public String JavaDoc getConfigName() {
160         if (configHelper != null)
161             return configHelper.getConfigName();
162         return null;
163             
164     }
165       
166     public void debug() {
167         logger.log(Level.FINEST, "diagnostic-service.capture_app_dd ",
168                new Object JavaDoc[] {captureAppDDEnabled});
169         logger.log(Level.FINEST, "diagnostic-service.capture_hadb_info",
170                 new Object JavaDoc[]{captureHadbInfoEnabled});
171         logger.log(Level.FINEST, "diagnostic-service.capture_checksum",
172                 new Object JavaDoc[]{captureChecksumEnabled});
173         logger.log(Level.FINEST, "diagnostic-service.capture_install_log",
174                 new Object JavaDoc[]{captureInstallLogEnabled});
175         logger.log(Level.FINEST, "diagnostic-service.min_log_level",
176                 new Object JavaDoc[]{minLogLevel});
177         logger.log(Level.FINEST, "diagnostic-service.max_log_entries",
178                 new Object JavaDoc[]{maxNoOfEntries});
179     }
180     
181     public String JavaDoc toString() {
182         return getInstanceName() + "," + getConfigName() +
183                 "," + getMaxNoOfEntries() +"," + getMinLogLevel() +
184                 "," + getLogFile() +
185                 "," + getRepositoryDir() + "," + isCaptureAppDDEnabled() +
186                 "," + isCaptureChecksumEnabled() +
187                 "," + isCaptureHadbInfoEnabled() +
188                 "," + isCaptureInstallLogEnabled() +
189                 "," + isVerifyDomainEnabled() ;
190     }
191     /**
192      * Initializes config values
193      */

194     private void setValues() throws DiagnosticException {
195         //setRepositoryDir();
196
configHelper = new ServiceConfigHelper(repositoryDir, instanceName, local);
197         minLogLevel = Level.parse
198             (getAttribute(ServerTags.MIN_LOG_LEVEL)).intValue();
199     logFile = getAttribute(ServerTags.FILE);
200     maxNoOfEntries = Integer.parseInt
201             (getAttribute(ServerTags.MAX_LOG_ENTRIES));
202         captureAppDDEnabled = getBooleanAttribute(ServerTags.CAPTURE_APP_DD);
203     captureInstallLogEnabled =getBooleanAttribute(ServerTags.CAPTURE_INSTALL_LOG);
204         verifyDomainEnabled = getBooleanAttribute(ServerTags.VERIFY_CONFIG);
205     captureHadbInfoEnabled = getBooleanAttribute(ServerTags.CAPTURE_HADB_INFO);
206         captureChecksumEnabled = getBooleanAttribute(ServerTags.COMPUTE_CHECKSUM);
207         captureSystemInfoEnabled = getBooleanAttribute(ServerTags.CAPTURE_SYSTEM_INFO);
208     }
209
210     /**
211      * Retrieve value of the supplied attribute
212      */

213     private String JavaDoc getAttribute(String JavaDoc attribute) throws DiagnosticException {
214     return configHelper.getAttribute(attribute);
215     }
216
217     private boolean getBooleanAttribute(String JavaDoc attrName)
218         throws DiagnosticException{
219         return Boolean.valueOf(getAttribute(attrName)).booleanValue();
220     }
221 }
222
Popular Tags