Package org.cdlib.mrt.formatter
Class FormatterAbs
java.lang.Object
org.cdlib.mrt.formatter.FormatterAbs
- All Implemented Interfaces:
FormatterInf
- Direct Known Subclasses:
ANVLFormatter,JSONFormatter,XHTMLFormatter,XMLFormatter
FormatterAbs is the base formatting class. It uses reflection to determine which
methods in a StateInf class should be called for formatting the output.
- Author:
- dloy
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cdlib.mrt.formatter.FormatterInf
FormatterInf.Format -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddLvl(int lvl, PrintStream stream) Indent handling for output display streamprotected voidcloseOutput(PrintStream stream) Close output streamprotected booleandisplay(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) process this method for output using reflectionvoidformat(StateInf state, PrintStream stream) Create ouput format.protected voidformatClass(Class c, Object object, int lvl, PrintStream stream) Format this class.voidformatNamedNode(String name, Object obj, boolean isFirst, int lvl, PrintStream stream) Format a node.voidformatNode(Object obj, boolean isFirst, int lvl, PrintStream stream) protected voidformatObject(Object object, int lvl, PrintStream stream) Use reflection to format this objectstatic ANVLFormattergetANVLFormatter(LoggerInf logger) get ANVL formatterstatic FormatterInfgetFormatter(FormatterInf.Format formatType, LoggerInf logger) Get typped formatterType of formatter being usedstatic JSONFormattergetJSONFormatter(String mapperName, LoggerInf logger) get JSON formatterstatic JSONFormattergetJSONFormatter(LoggerInf logger) get JSON formatterprotected StringgetMethodName(Method method) Standard name generator for elements.protected StringgetObjectName(Object obj) From a full object name find the last suffixstatic XHTMLFormattergetXHTMLFormatter(String mapperName, LoggerInf logger) get XHTML formatterstatic XHTMLFormattergetXHTMLFormatter(LoggerInf logger) get XHTML formatterstatic XMLFormattergetXMLFormatter(String mapperName, LoggerInf logger) get XML formatterstatic XMLFormattergetXMLFormatter(LoggerInf logger) get XML formatterprotected booleaninterfaceMatches(Class c, String match) Test if a class has a hierarchical interface of a particular typeprotected booleanprotected booleanCritical routine to determine if a method should be displayed Must begin with get.protected boolean/** Is this an enum class?protected booleanIs this a StateStringInf classprotected booleanIs this a List classprotected booleanIs this a Map classprotected booleanDetermine if this class is numeric or boolean.protected booleanDetermine if this class is numeric or boolean.protected booleanDetermine if this class is numeric or boolean.protected booleanIs this a StateInf classprotected booleanIs this a StateStringInf classprotected voidlog outputprotected voidlog output when debugging is setprotected voidlog exceptionprotected StringlowerCaseFirst(String in) Lower case first letter of stringprotected abstract voidprint(String name, String value, boolean isFirst, boolean isNumeric, int lvl, PrintStream stream) Formatted entry valueprotected abstract intprintBegin(StateInf state, PrintStream stream) Beginning of formattingprotected abstract voidprintClose(String name, int lvl, PrintStream stream) Closing element entry.protected abstract voidprintEnd(PrintStream stream) End of formattingprotected abstract voidprintStart(String name, boolean isFirst, int lvl, PrintStream stream) Beginning element entry.protected voidprocessLinkedHashList(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) process reference typeprotected voidprocessLinkedHashList(LinkedHashList<String, Object> map, String name, boolean isFirst, int lvl, PrintStream stream) voidprocessList(Method mGetList, Object objList, boolean firstNode, int lvl, PrintStream stream) Using reflection, process a list of values.protected voidprocessMap(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) process reference typeprotected voidprocessMap(Map<Object, Object> map, String name, boolean isFirst, int lvl, PrintStream stream) protected booleanreturnsList(Method method) If the return class is a list this is trueprotected booleanreturnsMap(Method method) If the return class is a map this is trueprotected ObjectReflection mechanism to run a methodprotected StringrunStringMethod(Method meth, String name, Object object) Runs toString() for this methodprotected voidsetFormatterType(FormatterInf.Format formatterType) protected voidwrite(String line, PrintStream stream) Used by formatter class to write to the display outputprotected voidwriteln(String line, PrintStream stream) Used by formatter class to write a line to the display output
-
Field Details
-
NAME
- See Also:
-
MESSAGE
- See Also:
-
NL
-
DEBUG
protected static final boolean DEBUG- See Also:
-
logger
-
formatterType
-
-
Constructor Details
-
FormatterAbs
Constructor- Parameters:
logger- process logger- Throws:
TException
-
-
Method Details
-
getXMLFormatter
get XML formatter- Parameters:
logger- process logger- Returns:
- XML formatter
- Throws:
TException
-
getXMLFormatter
get XML formatter- Parameters:
mapperName- resource name for mapper propertieslogger- process logger- Returns:
- XML formatter
- Throws:
TException
-
getANVLFormatter
get ANVL formatter- Parameters:
logger- process logger- Returns:
- ANVL formatter
- Throws:
TException
-
getXHTMLFormatter
get XHTML formatter- Parameters:
logger- process logger- Returns:
- XHTML formatter
- Throws:
TException
-
getXHTMLFormatter
public static XHTMLFormatter getXHTMLFormatter(String mapperName, LoggerInf logger) throws TException get XHTML formatter- Parameters:
mapperName- name of XML mapper filelogger- process logger- Returns:
- XHTML formatter
- Throws:
TException
-
getJSONFormatter
get JSON formatter- Parameters:
logger- process logger- Returns:
- JSON formatter
- Throws:
TException
-
getJSONFormatter
get JSON formatter- Parameters:
logger- process logger- Returns:
- JSON formatter
- Throws:
TException
-
setFormatterType
-
getFormatter
public static FormatterInf getFormatter(FormatterInf.Format formatType, LoggerInf logger) throws TException Get typped formatter- Parameters:
formatType- type of formatter being requestedlogger- process logger- Returns:
- formatter
- Throws:
TException
-
getFormatterType
Type of formatter being used- Specified by:
getFormatterTypein interfaceFormatterInf- Returns:
- type of used formatter
-
printBegin
Beginning of formatting- Parameters:
stream- print output stream- Returns:
- starting level (used for indentation - typically 1)
- Throws:
TException
-
printEnd
End of formatting- Parameters:
stream- output stream- Throws:
TException
-
printStart
protected abstract void printStart(String name, boolean isFirst, int lvl, PrintStream stream) throws TException Beginning element entry. An example would be the element name in XML- Parameters:
name- element nameisFirst- true=is first element of a list, false=subsequent element of listlvl- indentation levelstream- print output stream- Throws:
TException
-
printClose
Closing element entry. Example is closeing element in XML- Parameters:
name- element namelvl- indentation levelstream- print output stream- Throws:
TException
-
print
protected abstract void print(String name, String value, boolean isFirst, boolean isNumeric, int lvl, PrintStream stream) throws TException Formatted entry value- Parameters:
name- name of entryvalue- entry valueisFirst- true=is first element of a list, false=subsequent element of listisNumeric- is the element numeric or boolean. Some formats require quotes around value unless it is numericlvl- indentation levelstream- print output stream- Throws:
TException
-
format
Description copied from interface:FormatterInfCreate ouput format. Using the StateInf object, create a formatted output to this print stream- Specified by:
formatin interfaceFormatterInf- Parameters:
state- object to be formattedstream- output for formatted data- Throws:
TException
-
formatNode
- Throws:
TException
-
formatNamedNode
public void formatNamedNode(String name, Object obj, boolean isFirst, int lvl, PrintStream stream) throws TException Format a node. This is the formatting of an object, with start and close elements- Parameters:
name- class nameobj- object to be formattedisFirst- true=is first element of a list, false=subsequent element of listlvl- indentation levelstream- print output stream- Throws:
TException
-
formatObject
Use reflection to format this object- Parameters:
object- object to be formattedlvl- indentation levelstream- print output stream- Throws:
TException
-
formatClass
Format this class. Using reflection extract all methods to determine if they should be called for formatting.- Parameters:
c- Class to be formattedobject- instantiated object of this classlvl- indentation levelstream- print output stream- Throws:
TException
-
display
protected boolean display(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) throws Exception process this method for output using reflection- Parameters:
m- method to be processedobj- object containing methodisFirst- is this the first of a list of entrieslvl- indentation levelstream- print output stream- Returns:
- true=output took place, false=no output
- Throws:
Exception
-
processLinkedHashList
protected void processLinkedHashList(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) throws Exception process reference type- Parameters:
m- method to be processedobj- object containing methodisFirst- is this the first of a list of entrieslvl- indentation levelstream- print output stream- Throws:
Exception
-
processLinkedHashList
protected void processLinkedHashList(LinkedHashList<String, Object> map, String name, boolean isFirst, int lvl, PrintStream stream) throws Exception- Throws:
Exception
-
processMap
protected void processMap(Method m, Object obj, boolean isFirst, int lvl, PrintStream stream) throws Exception process reference type- Parameters:
m- method to be processedobj- object containing methodisFirst- is this the first of a list of entrieslvl- indentation levelstream- print output stream- Throws:
Exception
-
processMap
protected void processMap(Map<Object, Object> map, String name, boolean isFirst, int lvl, PrintStream stream) throws Exception- Throws:
Exception
-
isNumeric
Determine if this class is numeric or boolean. This is required because display formats changed based on numeric/boolean status.- Parameters:
testClass- class to be tested- Returns:
- true=is numeric or boolean, false=is neither numeric nor boolean
-
isNumeric
Determine if this class is numeric or boolean. This is required because display formats changed based on numeric/boolean status.- Parameters:
testClass- class to be tested- Returns:
- true=is numeric or boolean, false=is neither numeric nor boolean
-
isNumeric
Determine if this class is numeric or boolean. This is required because display formats changed based on numeric/boolean status.- Parameters:
testClass- class to be tested- Returns:
- true=is numeric or boolean, false=is neither numeric nor boolean
-
getMethodName
Standard name generator for elements. Remove get at beginning and lower case first letter- Parameters:
method- for extracted name- Returns:
- extracted name
- Throws:
TException
-
processList
public void processList(Method mGetList, Object objList, boolean firstNode, int lvl, PrintStream stream) throws TException Using reflection, process a list of values. Each entry in the list corresponds to a start/close block- Parameters:
mGetList- a getter for a list to be processedobjList- object containing this getterfirstNode- first entry in listlvl- indentation levelstream- print output stream- Throws:
TException
-
getObjectName
From a full object name find the last suffix- Parameters:
obj- object for name extraction- Returns:
- suffix - name
-
isDisplayMethod
Critical routine to determine if a method should be displayed Must begin with get. Must be public Must not take any arguments Must be return a value that is displayable (primitives, State or List)- Parameters:
m- method to be tested- Returns:
- true=is displayable, false=is not displayable
- Throws:
TException
-
isDisplayableClass
- Throws:
TException
-
runMethod
Reflection mechanism to run a method- Parameters:
meth- method to be runobject- object containing the method- Returns:
- result of running method
-
runStringMethod
Runs toString() for this method- Parameters:
meth- method to be executedobject- object containing method- Returns:
- toString() value
- Throws:
TException
-
returnsList
If the return class is a list this is true- Parameters:
m- test the return type of this method- Returns:
- true=is list, false=not list
-
returnsMap
If the return class is a map this is true- Parameters:
m- test the return type of this method- Returns:
- true=is map, false=not map
-
isEnum
/** Is this an enum class?- Parameters:
c- class to be tested- Returns:
- true=enum, false=not enum
-
isStateClass
Is this a StateInf class- Parameters:
c- class to be tested- Returns:
- true=is StateInf class, false=is not a StateInf class
-
isStateStringClass
Is this a StateStringInf class- Parameters:
c- class to be tested- Returns:
- true=is StateStringInf class, false=is not a StateStringInf class
-
isLinkedHashList
Is this a StateStringInf class- Parameters:
c- class to be tested- Returns:
- true=is StateStringInf class, false=is not a StateStringInf class
-
isList
Is this a List class- Parameters:
c- class to be tested- Returns:
- true=is List class, false=is not List class
-
isMap
Is this a Map class- Parameters:
c- class to be tested- Returns:
- true=is Map class, false=is not Map class
-
lowerCaseFirst
Lower case first letter of string- Parameters:
in- String to be processed- Returns:
- String with first char lower cased
-
interfaceMatches
Test if a class has a hierarchical interface of a particular type- Parameters:
c- class to be testedmatch- part of an interface string to be tested- Returns:
- true=class has interface of this type, false=class does not have this interface
-
write
Used by formatter class to write to the display output- Parameters:
line- data to be written to the streamstream- output display stream- Throws:
TException
-
writeln
Used by formatter class to write a line to the display output- Parameters:
line- line to be written to the streamstream- output display stream- Throws:
TException
-
closeOutput
Close output stream- Parameters:
stream- display stream to be closed
-
log
log output- Parameters:
msg- message to log
-
logDebug
log output when debugging is set- Parameters:
msg- debug message
-
logException
log exception- Parameters:
ex- Exception to log
-
addLvl
Indent handling for output display stream- Parameters:
lvl- levels to indentstream- output display stream- Throws:
TException
-