KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > event > handlers > DebugHandlers


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.tools.guiframework.event.handlers;
25
26 import com.iplanet.jato.RequestContext;
27 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
28 import com.sun.enterprise.tools.guiframework.util.LogUtil;
29 import java.util.Map JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.logging.Level JavaDoc;
32
33 /**
34  *
35  */

36 public class DebugHandlers {
37
38     /**
39      * This method writes the given value to stdout using System.out.
40      *
41      * @param reqCtx The RequestContext
42      * @param handlerCtx The HandlerContext
43      */

44     public void println(RequestContext reqCtx, HandlerContext handlerCtx) {
45         Level JavaDoc level = LogUtil.stringToLogLevel((String JavaDoc) handlerCtx.getInputValue(LEVEL));
46         
47     String JavaDoc label = (String JavaDoc)handlerCtx.getInputValue(LABEL);
48     if (label == null) {
49         label = "";
50     }
51         
52     Object JavaDoc value = handlerCtx.getInputValue(VALUE);
53         if (value == null) {
54            LogUtil.log(level, label+"null");
55         }
56         else if (value instanceof List JavaDoc) {
57             List JavaDoc l = (List JavaDoc)value;
58             for (int i=0; i<l.size(); i++) {
59                 Object JavaDoc o = l.get(i);
60                 if (o == null) {
61                     LogUtil.log(level, label+"null");
62                 } else {
63                     LogUtil.log(level, label+o.toString());
64                 }
65             }
66         } else if (value instanceof Exception JavaDoc) {
67              LogUtil.log(level, label+((Exception JavaDoc)value).getMessage());
68         } else if (value != null) {
69             LogUtil.log(level, label+value.toString());
70         }
71     }
72
73     /**
74      * Exception Log Handler -- This handler logs an exception to the LogFile.
75      */

76     public void logException(RequestContext ctx, HandlerContext handlerCtx) {
77     Throwable JavaDoc ex = (Throwable JavaDoc)handlerCtx.getInputValue(EXCEPTION_TO_LOG);
78     String JavaDoc logLevel = (String JavaDoc)handlerCtx.getInputValue(LEVEL);
79         if (logLevel == null)
80             logLevel = "FINE";
81         Level JavaDoc level = LogUtil.stringToLogLevel(logLevel);
82         
83     if (ex != null) {
84             LogUtil.log(level, "", ex);
85     } else {
86         LogUtil.log(level, getClass().getName()+
87         ".logException() called without an exception to log.");
88     }
89     }
90
91     public static final String JavaDoc VALUE = "value";
92     public static final String JavaDoc LABEL = "label";
93     public static final String JavaDoc LEVEL = "level";
94     public static final String JavaDoc EXCEPTION_TO_LOG = "exceptionToLog";
95 }
96
Popular Tags