|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Writer | +--java.io.PrintWriter | +--grace.io.PrintWriter
This class is similar to the java.io.PrintWriter class except it intelligently prints objects as well as simple types. It also abstracts some of the formatting features such that derived versions of this class can print various styles of formatting the objects.
For example, the LispPrintWriter class will print basic types and objects with a lisp like appearance. This is useful for the CommandLineSessionManager because it needs to present AreaPoolServer data in a lisp like format.
PrintHandlers may be added to the system that print additional types that are not handled correctly by the default printing scheme. Simply derive from PrintHandler and add an instance of it using the addPrintHandler function.
Alternatively, you can create the derived PrintHandler class in the directory grace.io.handlers.... Then, when an object of the type named by the handler is printed, this class will be automatically loaded, instantiated, and used to print the value. For example, the JDK 1.2 java.util.Collection class uses this scheme. So, a JDK 1.2 specific class called grace.io.handlers.java.util.Collection class exists that is used only when a Collection instance is printed. This keeps the PrintWriter clases independent of JDK 1.2.
To do:
Field Summary | |
protected java.text.DateFormat |
dateFormat
|
Fields inherited from class java.io.PrintWriter |
out |
Fields inherited from class java.io.Writer |
lock |
Constructor Summary | |
PrintWriter(java.io.OutputStream stream)
|
|
PrintWriter(java.io.OutputStream stream,
boolean autoFlush)
|
|
PrintWriter(java.io.Writer writer)
|
|
PrintWriter(java.io.Writer writer,
boolean autoFlush)
|
Method Summary | |
protected static java.util.Vector |
add(java.lang.Object[] first,
java.util.Vector second)
Just a utility function to add an array of objects to a vector of objects. |
static void |
addPrintHandler(java.lang.Class type,
PrintHandler handler)
Caches the handler for the given class so that it can be printed by calling the "handle" function on the given PrintHandler. |
protected boolean |
alreadyPrinted(java.lang.Object object)
This indicates that the given object has been printed in the PrintStream and should not be printed again, presumably. |
protected static java.lang.String |
arrayTypeName(java.lang.Class type,
boolean shorten,
boolean shortenAll)
|
protected void |
autoFlush()
|
abstract void |
beginList()
|
abstract void |
beginObject()
|
protected void |
beginString()
|
abstract void |
endList()
|
abstract void |
endObject()
|
protected void |
endString()
|
protected static java.util.Vector |
fieldAccessors(java.lang.Class clazz)
Tries to find and remember the accessors for the given class. |
protected static PrintHandler |
getPrintHandler(java.lang.Class toFind)
This finds a PrintHandler by first looking in the handlers subdirectory for the type and then by iterating through the list of added PrintHandlers (added using addPrintHandler) to find a PrintHandler that will handle the requested subtype. |
protected static java.lang.reflect.Method |
getPrintMethod(java.lang.Class objectClass)
This returns the reflected method named "printTo(PrintWriter)" on the given clazz. |
boolean |
getPrintObjectsOnlyOnce()
|
protected static PrintHandler |
getPrintToHandler(java.lang.Class clazz)
This finds and adds a PrintMethodHandler for the given class that invokes the classes printTo method if available it has one. |
boolean |
prettyOutput()
|
protected void |
print(java.util.Enumeration elements)
|
protected void |
print(java.util.Hashtable table)
|
protected void |
print(java.lang.Object[] array)
|
void |
print(grace.io.PrintWriter.ResultSetRow row)
|
protected void |
print(java.sql.ResultSet resultSet)
|
void |
print(java.lang.String name,
boolean value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
byte value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
char value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
double value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
float value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
int value)
This is the function a user should call to cause the named object to printed. |
void |
print(java.lang.String name,
java.lang.Object object)
This is the function a user should call to cause the named object to printed. |
protected void |
print(java.util.Vector vector)
|
protected abstract void |
printField(Value value)
This meant to be overridden to provide a meaningful way to print the value of a field; |
protected void |
printListElementValue(java.lang.Object value,
int index,
int numElements)
This method is not meant to be called by the general public. |
protected void |
printName(java.lang.Object name)
This is called when the name of an object is printed. |
protected void |
printNullObject()
|
protected void |
printNullString()
|
protected void |
printQuoted(java.lang.String string)
|
protected void |
printType(Value value,
boolean shorten,
boolean shortenAll)
Prints the type of the given object shortened to the rightmost name if desired. |
protected void |
printValue(Value value)
This prints the given object in one of many ways. |
void |
printWithFieldAccessors(Value parent,
java.util.Vector accessors)
This uses the given Vector |
protected java.lang.String |
referenceNameOf(java.lang.Object object)
|
protected static java.util.Vector |
rememberAccessorsUsingFields(java.lang.Class clazz)
This function tries to gain access to the fields of the object using reflection and creates a FieldAccessor for each field depending on if it can be accessed publicly or by a get method. |
protected static java.util.Vector |
rememberAccessorsUsingGetMethods(java.lang.Class clazz)
This reflects on the get functions of the given class, finds all of the get functions that look like follow the bean get pattern, and stores them as FieldAccessors in the classFieldAccessors. |
protected void |
rememberPrinted(java.lang.Object object)
This records the fact the given object has been printed in the PrintStream and should not be printed again, presumably. |
protected static java.lang.String |
rightmostName(java.lang.String name)
This returns the rightmost name in a dot '.' separated list of names. |
void |
setDateFormat(java.text.DateFormat format)
Sets the DateFormat used for printing all dates. |
void |
setPrettyOutput(boolean pretty)
|
void |
setPrintObjectsOnlyOnce(boolean value)
|
protected static java.lang.String |
shortenedTypeName(java.lang.Class type,
boolean shortenNonJDKTypes)
This returns the abreviated name of the given class. |
Methods inherited from class java.io.PrintWriter |
checkError,
close,
flush,
print,
print,
print,
print,
print,
print,
print,
print,
print,
println,
println,
println,
println,
println,
println,
println,
println,
println,
println,
setError,
write,
write,
write,
write,
write |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.text.DateFormat dateFormat
Constructor Detail |
public PrintWriter(java.io.OutputStream stream)
public PrintWriter(java.io.OutputStream stream, boolean autoFlush)
public PrintWriter(java.io.Writer writer)
public PrintWriter(java.io.Writer writer, boolean autoFlush)
Method Detail |
public void print(java.lang.String name, java.lang.Object object)
public void print(java.lang.String name, int value)
public void print(java.lang.String name, byte value)
public void print(java.lang.String name, char value)
public void print(java.lang.String name, float value)
public void print(java.lang.String name, double value)
public void print(java.lang.String name, boolean value)
protected abstract void printField(Value value)
value
- of objectprotected void printNullString()
protected void printNullObject()
protected void printQuoted(java.lang.String string)
protected void printValue(Value value)
public void printWithFieldAccessors(Value parent, java.util.Vector accessors)
public static void addPrintHandler(java.lang.Class type, PrintHandler handler)
type
- of object to printhandler
- on which the "handle" function will be called
with a value of type 'type'.protected static PrintHandler getPrintHandler(java.lang.Class toFind)
protected static java.lang.String shortenedTypeName(java.lang.Class type, boolean shortenNonJDKTypes)
type
- whose type name to shortenconvertNonJDKTypes
- shorten every type's name rather than JDK's.protected static java.lang.String rightmostName(java.lang.String name)
protected void printType(Value value, boolean shorten, boolean shortenAll)
object
- whose type to printshorten
- shorten type names to the rightmost nameshortenAll
- shorten all type names instead of just JDK namesprotected static java.lang.String arrayTypeName(java.lang.Class type, boolean shorten, boolean shortenAll)
protected void printName(java.lang.Object name)
name
- of object to printprotected static java.lang.reflect.Method getPrintMethod(java.lang.Class objectClass)
protected static PrintHandler getPrintToHandler(java.lang.Class clazz)
clazz
- on which to add PrintMethodHandlerprotected static java.util.Vector fieldAccessors(java.lang.Class clazz)
clazz
- for which to remember accessorsprotected static java.util.Vector rememberAccessorsUsingGetMethods(java.lang.Class clazz)
protected static java.util.Vector rememberAccessorsUsingFields(java.lang.Class clazz)
clazz
- to reflect and discover fields and get functionspublic void setDateFormat(java.text.DateFormat format)
protected static java.util.Vector add(java.lang.Object[] first, java.util.Vector second)
first
- array to add to second vectorsecond
- vector appended to firstpublic boolean prettyOutput()
public void setPrettyOutput(boolean pretty)
public boolean getPrintObjectsOnlyOnce()
public void setPrintObjectsOnlyOnce(boolean value)
public abstract void beginList()
public abstract void endList()
public abstract void beginObject()
public abstract void endObject()
protected void beginString()
protected void endString()
protected void rememberPrinted(java.lang.Object object)
protected java.lang.String referenceNameOf(java.lang.Object object)
protected boolean alreadyPrinted(java.lang.Object object)
protected void autoFlush()
protected void printListElementValue(java.lang.Object value, int index, int numElements)
protected void print(java.lang.Object[] array)
protected void print(java.util.Vector vector)
protected void print(java.util.Hashtable table)
protected void print(java.util.Enumeration elements)
public void print(grace.io.PrintWriter.ResultSetRow row)
protected void print(java.sql.ResultSet resultSet)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |