FileDocCategorySizeDatePackage
ReporterImpl.javaAPI DocGlassfish v2 API17105Fri May 04 22:32:14 BST 2007com.sun.enterprise.util.diagnostics

ReporterImpl

public class ReporterImpl extends Object implements IReporterEnum
General Purpose Debugging Output -- create a ReporterImpl object and then write with pr() If you construct with an Object -- that Object's class name will automatically be prepended to each message If you use pr(String metName, String mesg) -- the metName will be added to the ObjectName The output of ReporterImpl is controlled by an environmental variable if you call it with java -DaibDebug=true -- it gets turned on...

Fields Summary
static Logger
_logger
private int
severityLevel
private String
name
private ReporterWriter
writer
private String
className
private static final boolean
doDebug
Constructors Summary
public ReporterImpl()

//Bug 4677074 end
	 
	
		ctor(null, -1);
	
ReporterImpl(int theSeverityLevel)

		ctor(null, theSeverityLevel);
	
public ReporterImpl(String sid)

		ctor(sid, -1);
	
ReporterImpl(String sid, int theSeverityLevel)

		ctor(sid, theSeverityLevel);
	
Methods Summary
private intcalcSeverityLevel(java.lang.String original)

		if(original == null || original.length() <= 0)
			return DISABLED;	

		String s = original.toUpperCase();

		// first let's see if it is an integer...

		try
		{
			int ret = Integer.parseInt(s);

			if(ret < 0)
				ret = 0;

			return ret;
		}
		catch(NumberFormatException e)
		{
		}

		// not a number -- let's check a few more possibilities...

		if(s.equals("ALL") || s.equals("NOISY") || s.equals("EVERYTHING") || s.equals("ON") //NOI18N
						|| s.equals("MONDO")  || s.equals("YES") || s.equals("TRUE") || s.equals("DUMP") || s.startsWith("MAX"))//NOI18N
			return 0;
		if(s.startsWith("NO") || s.equals("OFF") || s.equals("FALSE") || s.equals("QUIET") || s.startsWith("MIN"))//NOI18N
			return DISABLED;

		// it should be "WARN", "CRITICAL", etc.
		// since all of the values start with a different character,
		// just check the first character...
		char first = s.charAt(0);	// uppercase!!
		
		for(int i = 0; i < severityNames.length; i++)
		{
			if(severityNames[i].toUpperCase().charAt(0) == first)
				return i;
		}

		// I give up!
		debug("Unknown value for commandline argument \"-DIABDebug=" + original + "\"");//NOI18N
		return DISABLED;
	
private booleancheckSeverity(int severity)

		if(severity >= severityLevel)
			return true;

		return false;
	
public voidcrit(java.lang.Object o)

		if(checkSeverity(CRIT))
			pr(CRITICAL, o);
	
public voidcritical(java.lang.Object o)

		if(checkSeverity(CRIT))
			pr(CRITICAL, o);
	
private voidctor(java.lang.String theName, int theSeverityLevel)

		if(theName != null && theName.length() > 0)
			setName(theName);

		if(theSeverityLevel >= 0)
			setSeverityLevel(theSeverityLevel);
		else
		{
			String sl = System.getProperty("ForteReporterDebugLevel");//NOI18N
			if(sl != null && sl.length() > 0)
			{
				//int sli = Integer.parseInt(sl);
				//setSeverityLevel(sli);
				setSeverityLevel(sl);
			}

			sl = System.getProperty("com.iplanet.util.diagnostic.Reporter.severityLevel");//NOI18N
			if(sl != null && sl.length() > 0)
			{
				//int sli = Integer.parseInt(sl);
				//setSeverityLevel(sli);
				setSeverityLevel(sl);
			}

			sl = System.getProperty("com.sun.enterprise.util.diagnostic.Reporter.severityLevel");//NOI18N
			if(sl != null && sl.length() > 0)
			{
				//int sli = Integer.parseInt(sl);
				//setSeverityLevel(sli);
				setSeverityLevel(sl);
			}

			sl = System.getProperty("Reporter");//NOI18N
			if(sl != null && sl.length() > 0)
			{
				//int sli = Integer.parseInt(sl);
				//setSeverityLevel(sli);
				setSeverityLevel(sl);
			}
		}

		className	= getClass().getName();
		writer		= new ReporterWriter(getName());

		debug("Ctor called");//NOI18N
		debug("ReporterImpl Severity Level:  " + getSeverityLevel());//NOI18N
	
private voiddebug(java.lang.String s)

		if(doDebug)
//Bug 4677074			System.out.println("ReporterImpl Report --> " + s);//NOI18N
//Bug 4677074 begin
			_logger.log(Level.FINE,"ReporterImpl Report --> " +s);
//Bug 4677074 end
	
public voiddump(java.lang.Object o, java.lang.String s)

		if(checkSeverity(DUMP) && o != null)
		{
			if(s == null)
				s = "";
			
			String s2 = s + "\n**********  Object Dump Start  ***********\n" +//NOI18N
					ObjectAnalyzer.toStringWithSuper(o) + "\n**********  Object Dump End  ***********";//NOI18N
			pr(OBJECT_DUMP, s2);
		}
	
public voiddump(java.lang.String s)

		if(checkSeverity(DUMP))
		{
			pr(OBJECT_DUMP, s);
		}
	
public voiddump(java.lang.Object o)

		dump(o, null);
	
public voiderror(java.lang.Object o)

		if(checkSeverity(ERROR))
			pr(ERROR, o);
	
private CallerInfogetCallerInfo()

		try
		{
			return new CallerInfo(new Object[] { this });
		}
		catch(CallerInfoException e)
		{
			debug(e.toString());
			return null;
		}
	
private java.lang.StringgetClassName()

		Assertion.check(className);
		return className;
	
public java.lang.StringgetName()

		return name;
	
public intgetSeverityLevel()

		return severityLevel;
	
public java.lang.StringgetSeverityLevelString()

		if(severityLevel <= OFF)
			return severityNames[severityLevel];
		
		return severityNames[OFF];
	
public voidinfo(java.lang.Object o)

		if(checkSeverity(INFO))
			pr(INFO, o);
	
public voidinsist(java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(java.lang.String checkme, java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(checkme, s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(boolean b)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(b); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(boolean b, java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(b, s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(java.lang.Object o)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(o); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(java.lang.Object o, java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(o, s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(double z)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(z); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(double z, java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(z, s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(long l)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(l); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
public voidinsist(long l, java.lang.String s)

		if(checkSeverity(ASSERT))
		{
			try
			{ 
				Assertion.check(l, s); 
			}
			catch(Assertion.Failure f) 
			{
				pr(ASSERT, new StackTrace().toString() + f);
				throw f; 
			}
		}
	
private voidpr(int severity, java.lang.Object o)

		try
		{
			CallerInfo ci = getCallerInfo();
			
			String s;

			if(o == null)
			{
				s = "null Object argument";//NOI18N
			}
			else
			{
				s = o.toString();

				if(s == null) // || s.length() <= 0)
					s = "null toString result from Object";//NOI18N
			}


			if(ci != null)
				s = ci.toString() + ": " + s;//NOI18N

			writer.println(severity, s);
		}
		catch(Throwable e)
		{

//Bug 4677074			System.out.println("Got exception in ReporterImpl.pr():  " + e);//NOI18N
//Bug 4677074 begin
			_logger.log(Level.WARNING,"iplanet_util.pr_exception",e);
//Bug 4677074 end
		}
	
public voidsetName(java.lang.String theName)

		Assertion.check(theName);
		name = theName;
	
public voidsetSeverityLevel(int level)

		debug("setSeverityLevel(" + level + ")");//NOI18N

		if(level < 0)
			level = 0;

		severityLevel = level;
	
public voidsetSeverityLevel(java.lang.String level)

		debug("setSeverityLevel(" + level + ")");//NOI18N

		severityLevel = calcSeverityLevel(level);
	
public ReporterWritersetWriter(ReporterWriter lwriter)
Change the mechanism this object uses to deliver output to the user

param
lwriter A new output mechanism
return
The previous output mechanism.

            ReporterWriter retVal = null;
            if (null != lwriter) {
                retVal = this.writer;
                this.writer = lwriter;
            }
            return retVal;
        
public voidverbose(java.lang.Object o)

		if(checkSeverity(VERBOSE))
			pr(VERBOSE, o);
	
public voidwarn(java.lang.Object o)

		// convenience method
		if(checkSeverity(WARN))
			pr(WARNING, o);
	
public voidwarning(java.lang.Object o)

		if(checkSeverity(WARN))
			pr(WARNING, o);