KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > DisplayLogRecordsCommand


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
24 package com.sun.enterprise.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import java.util.Map JavaDoc;
28
29 import java.util.Date JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import javax.management.Attribute JavaDoc;
35 import javax.management.AttributeList JavaDoc;
36
37 public class DisplayLogRecordsCommand extends GenericCommand
38 {
39     
40     private final static String JavaDoc TIMESTAMP_OPTION = "timestamp";
41     private final static String JavaDoc MODULEID_OPTION = "moduleid";
42     private final static String JavaDoc LEVEL_OPTION = "errorlevel";
43     private final static String JavaDoc MODULE_DELIMITER = ":";
44
45     protected Object JavaDoc[] getParamsInfo()throws CommandException, CommandValidationException
46     {
47         Object JavaDoc[] paramsInfo = new Object JavaDoc[11];
48         long timestamp = new Long JavaDoc(getOption(TIMESTAMP_OPTION)).longValue();
49         String JavaDoc errorLevel = getOption(LEVEL_OPTION);
50         
51         paramsInfo[0] = null;
52         paramsInfo[1] = null;
53         paramsInfo[2] = Boolean.FALSE;
54         paramsInfo[3] = Boolean.FALSE;
55         paramsInfo[4] = new Integer JavaDoc(1000);
56         paramsInfo[5] = new Date JavaDoc(timestamp);
57         paramsInfo[6] = new Date JavaDoc(timestamp + 3600000);
58         paramsInfo[7] = (errorLevel == null) ? Level.WARNING.toString() : errorLevel;
59         paramsInfo[8] = (errorLevel != null) ? Boolean.TRUE : Boolean.FALSE;
60         paramsInfo[9] = getModuleIds();
61         paramsInfo[10] = null;
62         for (Object JavaDoc param : paramsInfo)
63         {
64             if (param != null)
65                 CLILogger.getInstance().printDebugMessage(param.toString());
66             else
67                 CLILogger.getInstance().printDebugMessage("null");
68         }
69         return paramsInfo;
70     }
71
72     
73     protected void handleReturnValue(Object JavaDoc retVal)
74     {
75         //final Map errorDistribution = (Map)retVal;
76
final AttributeList JavaDoc results = (AttributeList JavaDoc) retVal;
77         List JavaDoc headerRow = (List JavaDoc)(((Attribute JavaDoc)results.get(0)).getValue());
78         List JavaDoc rowList = (List JavaDoc)(((Attribute JavaDoc)results.get(1)).getValue());
79         List JavaDoc row;
80
81         Iterator JavaDoc it = rowList.iterator();
82         if (it.hasNext())
83         {
84             CLILogger.getInstance().printDetailMessage(
85                     "----------------------------------------------------------------------");
86             
87         }
88         else
89         {
90             CLILogger.getInstance().printDetailMessage(
91                                         getLocalizedString("NoElementsToList"));
92         }
93         while (it.hasNext())
94         {
95             row = (List JavaDoc)it.next();
96         if (row.size() != headerRow.size()) {
97                 //throw new CommandException(
98
CLILogger.getInstance().printDebugMessage(
99         "Row had '"+row.size()+"' columns, header has '"+
100             headerRow.size()+"' columns!");
101         }
102             
103             CLILogger.getInstance().printMessage(getLocalizedString("LogRecNumber")
104                                                     + " = " + row.get(0));
105             CLILogger.getInstance().printMessage(getLocalizedString("LogDateTime")
106                                                     + " = " + row.get(1));
107             CLILogger.getInstance().printMessage(getLocalizedString("LogMsgId")
108                                                     + " = " + row.get(6));
109             CLILogger.getInstance().printMessage(getLocalizedString("LogLevel")
110                                                     + " = " + row.get(2));
111             CLILogger.getInstance().printMessage(getLocalizedString("LogProductName")
112                                                     + " = " + row.get(3));
113             CLILogger.getInstance().printMessage(getLocalizedString("LogLogger")
114                                                     + " = " + row.get(4));
115             CLILogger.getInstance().printMessage(getLocalizedString("Lognvp")
116                                                     + " = " + row.get(5));
117             CLILogger.getInstance().printMessage(getLocalizedString("LogMessage")
118                                                     + " = " + row.get(7));
119             CLILogger.getInstance().printDetailMessage(
120                     "----------------------------------------------------------------------");
121         }
122     }
123
124     
125     /**
126      * Formulate and Returns module-id's from the given string
127      * @return Properties
128      */

129     protected List JavaDoc getModuleIds()
130         throws CommandException, CommandValidationException
131     {
132         final List JavaDoc moduleIds = new ArrayList JavaDoc();
133
134         String JavaDoc modulesStr = (String JavaDoc) getOperands().get(0);
135         final CLITokenizer modulesTok = new CLITokenizer(modulesStr, MODULE_DELIMITER);
136         while (modulesTok.hasMoreTokens()) {
137             moduleIds.add(modulesTok.nextToken());
138         }
139         return moduleIds;
140     }
141 }
142
Popular Tags