FileDocCategorySizeDatePackage
TraceUtil.javaAPI DocGlassfish v2 API8317Fri May 04 22:36:44 BST 2007com.sun.jts.trace

TraceUtil

public class TraceUtil extends Object
This class is used to set trace properties and print trace statements. The print method does the printing. All the methods are unsynchronized. Since setting of properties doesn't happen simultaneously with print in current usage, this is fine. The tracing should be enabled/disabled by calling Configuration.enableTrace()/disableTrace() prior to any operation on TraceUtil. It uses TraceRecordFormatter for formatting the trace record.
author
Kannan Srinivasan
version
1.0

Fields Summary
private static int
m_currentTraceLevel
private static char
m_fieldDelimiter
private static String
m_traceRecordTag
private static PrintWriter
m_traceWriter
Constructors Summary
Methods Summary
public static intgetCurrentTraceLevel()
Gets the current trace level. Returns an integer as per the TraceLevel constants.

return
an int value

        return m_currentTraceLevel;
    
public static chargetFieldDelimiter()
Gets the current field delimiter used in formatting trace record. The default is ':'.

return
a char value

        return m_fieldDelimiter;
     
public static java.lang.StringgetTraceRecordTag()
Gets the current trace record tag used in formatting of trace record. The default is 'iAS_JTS_Trace> '.

return
a String value

        return m_traceRecordTag;
     
public static java.io.PrintWritergetTraceWriter()
Gets the current output writer.

return
an PrintWriter value

        return m_traceWriter;
    
public static voidinit(java.io.PrintWriter traceWriter)
Initialises the trace class with given output writer.

param
traceWriter an PrintWriter value


	
	
		m_traceWriter = new PrintWriter(System.out);
	
        setTraceWriter(traceWriter);
    
public static voidprint(int traceLevel, java.io.PrintWriter outWriter, java.lang.Object tid, java.lang.Object origin, java.lang.String msg)
This method formats and writes the trace record to output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This method takes an PrintWriter also, which is used to write the output. This given outputWriter would override the set outputWriter. The origin object is printed using its toString() method.

param
traceLevel an int value
param
outWriter an PrintWriter value
param
tid an Object value
param
origin an Object value
param
msg a String value

            if( traceLevel <= m_currentTraceLevel )
            {
            	String traceRecord = TraceRecordFormatter.createTraceRecord(tid, origin, msg); 
		outWriter.println(traceRecord);
            }
    
public static voidprint(int traceLevel, java.lang.Object origin, java.lang.String msg)
This method formats and writes the trace record to current output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This method doesn't take a otid and tries to recover it from current obejct asscociated with this thread

param
traceLevel an int value
param
origin an Object value
param
msg a String value

	try{
		 print(traceLevel,
	          ((com.sun.jts.CosTransactions.TopCoordinator)
		  com.sun.jts.CosTransactions.CurrentTransaction.getCurrent().get_localCoordinator()).get_transaction_name(),
		  origin,
		  msg
		  );
	}catch(Exception e){
    		print(traceLevel,null,origin,msg);
	}
    
public static voidprint(int traceLevel, java.lang.Object tid, java.lang.Object origin, java.lang.String msg)
This method formats and writes the trace record to current output writer. The method is called with a tracelevel, which is checked with current trace level and if found equal or higher, the print is carried out. This uses the currently set output writer to write the trace output.

param
traceLevel an int value
param
tid an Object value
param
origin an Object value
param
msg a String value

    	print(traceLevel,m_traceWriter,tid,origin,msg);
    
public static voidsetCurrentTraceLevel(int traceLevel)
Sets the current trace level. The argument is tested for its validity and trace level is set. Else an exception is raised.

param
traceLevel an int value
exception
InvalidTraceLevelException if an error occurs

        if(Configuration.traceOn)
        {
            int i;
            boolean traceLevelSet = false;
            for(i = 0; i <= TraceLevel.IAS_JTS_MAX_TRACE_LEVEL; i++)
            {
                if(traceLevel == i)
                {
                    m_currentTraceLevel = traceLevel;
                    traceLevelSet = true;
                    break;
                }
            } 
            if(!traceLevelSet)
                throw new InvalidTraceLevelException();

        }
    
public static voidsetFieldDelimiter(char delimiter)
Sets the current field delimiter.

param
delimiter a char value

        m_fieldDelimiter = delimiter;
    
public static voidsetTraceRecordTag(java.lang.String traceRecordTag)
Sets the trace record tag.

param
traceRecordTag a String value

        m_traceRecordTag = traceRecordTag;
    
public static voidsetTraceWriter(java.io.PrintWriter traceWriter)
Sets the output writer. By default the output writer is set to Stdout.

param
traceWriter an PrintWriter value

	m_traceWriter = traceWriter;