/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.logging;

import org.apache.log4j.Priority;

/** 
 * Provides custom extention priorites for use with the
 * Log4j logging framework.
 *
 * Adds a trace priority that is below the standard log4j DEBUG priority.
 * This is a custom priority that is 100 below the Priority.DEBUG_INT and
 * represents a lower priority useful for logging events that should only
 * be displayed when deep debugging is required.
 *
 * @deprecated Use {@link XLevel} instead.
 * 
 * @see org.apache.log4j.Category
 * @see org.apache.log4j.Priority
 *
 * @author  <a href="mailto:Scott.Stark@jboss.org">Scott Stark</a>
 * @version $Revision: 1.2.2.1 $
 */
public class XPriority 
   extends Priority
{
   /** The integer representation of the priority, (Priority.DEBUG_INT - 100) */
   public static final int TRACE_INT = Priority.DEBUG_INT - 100;

   /** The string name of the trace priority. */
   public static String TRACE_STR = "TRACE";
   
   /** The TRACE priority object singleton */
   public static final XPriority TRACE = new XPriority(TRACE_INT, TRACE_STR, 7);

   /**
    * Construct a <tt>XPriority</tt>.
    */
   protected XPriority(int level, String strLevel, int syslogEquiv)
   {
      super(level, strLevel, syslogEquiv);
   }
   

   /////////////////////////////////////////////////////////////////////////
   //                            Factory Methods                          //
   /////////////////////////////////////////////////////////////////////////

   /** 
    * Convert an integer passed as argument to a priority. If the conversion
    * fails, then this method returns the specified default.
    * @return the Priority object for name if one exists, defaultPriority otherwize.
    */
   public static Priority toPriority(String name, Priority defaultPriority)
   {
      if (name == null)
         return defaultPriority;

      String upper = name.toUpperCase();
      if (upper.equals(TRACE_STR)) {
         return TRACE;
      }

      return Priority.toPriority(name, defaultPriority);
   }

   /** 
    * Convert an integer passed as argument to a priority.
    * 
    * @return the Priority object for name if one exists
    */
   public static Priority toPriority(String name)
   {
      return toPriority(name, TRACE);
   }
   
   /** 
    * Convert an integer passed as argument to a priority. If the conversion
    * fails, then this method returns the specified default.
    * @return the Priority object for i if one exists, defaultPriority otherwize.
    */
   public static Priority toPriority(int i, Priority defaultPriority)
   {
      Priority p;
      if (i == TRACE_INT)
         p = TRACE;
      else
         p = Priority.toPriority(i);
      return p;
   }
}
