Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.core.internal » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *    http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.geronimo.st.core.internal;
   18   
   19   import org.apache.geronimo.st.core.Activator;
   20   import org.eclipse.core.runtime.IStatus;
   21   
   22   /**
   23    * Helper class to route trace output.
   24    * 
   25    * @version $Rev: 817996 $ $Date: 2009-09-23 16:04:12 +0800 (Wed, 23 Sep 2009) $
   26    */
   27   public class Trace {
   28   
   29   	/**
   30   	 * Finest trace event.
   31   	 */
   32   	public static byte INFO = 0;
   33   
   34   	/**
   35   	 * Warning trace event.
   36   	 */
   37   	public static byte WARNING = 1;
   38   
   39   	/**
   40   	 * Severe trace event.
   41   	 */
   42   	public static byte SEVERE = 2;
   43   
   44   	/**
   45   	 * Trace constructor comment.
   46   	 */
   47   	private Trace() {
   48   		super();
   49   	}
   50   
   51   	/**
   52   	 * Trace the given text.
   53   	 * 
   54   	 * @param level
   55   	 *            the trace level
   56   	 * @param s
   57   	 *            a message
   58   	 */
   59   	public static void trace(byte level, String s) {
   60   		trace(level, s, null, false);
   61   	}
   62   
   63   	public static void trace(byte level, String s, boolean newLine) {
   64   		trace(level, s, null, newLine);
   65   	}
   66   
   67   	public static void trace(byte level, String s, Throwable t) {
   68   		trace(level, s, null, false);
   69   	}
   70   
   71   	public static void trace(byte level, String s, Throwable t, boolean newLine) {
   72   		if (Activator.getDefault() == null
   73   				|| !Activator.getDefault().isDebugging())
   74   			return;
   75   
   76   		if (newLine) {
   77   			System.out.println();
   78   		}
   79   
   80   		System.out.println(Activator.PLUGIN_ID + ":  " + s);
   81   		if (t != null)
   82   			t.printStackTrace();
   83   	}
   84   
   85   	/**
   86   	 * Trace the given message
   87   	 * 
   88   	 * @param tracePoint
   89   	 *            The trace point (e.g., "Exit", "Entry", "Constructor", etc....
   90   	 * 
   91   	 * @param classDotMethod
   92   	 *            The class name + method name (e.g., "Class.method()")
   93   	 * 
   94   	 * @param parms
   95   	 *            Method parameter(s) if the trace point is an "Entry" or Return
   96   	 *            value if the trace point is an "Exit"
   97   	 */
   98   	public static void tracePoint(String tracePoint, String classDotMethod) {
   99   		trace(Trace.INFO, tracePoint + ": " + classDotMethod + "()");
  100   	}
  101   
  102   	public static void tracePoint(String tracePoint, String classDotMethod,
  103   			Object... parms) {
  104   		if (parms == null) {
  105   			trace(Trace.INFO, tracePoint + ": " + classDotMethod + "( null )");
  106   		} else {
  107   			trace(Trace.INFO, tracePoint + ": " + classDotMethod + "(");
  108   			for (int ii = 0; ii < parms.length; ii++) {
  109   				Object parm = parms[ii];
  110   				trace(Trace.INFO, "    parm" + (ii + 1) + "=["
  111   						+ (parm == null ? null : parm.toString()) + "]");
  112   			}
  113   			trace(Trace.INFO, ")");
  114   		}
  115   	}
  116   }

Home » geronimo-eclipse-plugin-2.2-source-release » org.apache.geronimo.st.core.internal » [javadoc | source]