Package eu.bandm.tools.formatfrontends
Class DynamicFormatter
java.lang.Object
eu.bandm.tools.tdom.runtime.BaseVisitor
eu.bandm.tools.formatfrontends.absy.Visitor
eu.bandm.tools.formatfrontends.DynamicFormatter
- All Implemented Interfaces:
PCDataVisitor
public class DynamicFormatter
extends eu.bandm.tools.formatfrontends.absy.Visitor
Interpreter for generating formats from the format description language
dynamically.
For a description of this small language see the Format user documentation.
Please note: Beside the
The argument of the intial call to "format()" can be given a format code explicitly.
For those current field values which are objects themselves, the code tries to find the format code as follows, using reflection:
FIXME for child values : try via reflection
1) "newmodel =.get_()"
2) "newmodel =."
==> can be used for umod style and for "public" foreign definitions.
FIXME
maintain CACHE structure for both !! --
For a description of this small language see the Format user documentation.
Please note: Beside the
constructor
there are some public fields and some setter methods for configuring the
format generation process.The argument of the intial call to "format()" can be given a format code explicitly.
For those current field values which are objects themselves, the code tries to find the format code as follows, using reflection:
- Find method "public void toFormat()" and execute it.
- If this fails: find method "public String getFormatHint()". Execute this, take the resulting string as format code, parse it and interpret the resulting expression.
- If this method does not exist:
call "defaultFormat(Object)".
This method can be overwritten for sub-classes of DynamicFormatter.
Its default implementation uses "toString()" and
creates a simple
Format.Literal
.
FIXME for child values : try via reflection
1) "newmodel =
2) "newmodel =
==> can be used for umod style and for "public" foreign definitions.
FIXME
maintain CACHE structure for both !! --
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionboolean
controls caching of generated formats for objects, both putting and getting.boolean
controls caching of retrieved format code for java classes, both putting and getting.protected boolean
protected DynamicFormatter.ChildInfo
protected final DynamicFormatter.ChildInfo
"toFormat" method of class, or constant "null" if no pattern and no toFormat() method exist and default has to be used.compiled pattern for classint
used for identation formats without explict number part.protected Format
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected Format
protected Object
protected String
protected Object
protected MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>>
static final String
name of the method a class must (re-)define to define the format code which shall be used for their instances.static final String
name of the method a class can (re-)define to build a format representation for its instances "manually", by calling theFormat
factory directly.protected static final Object[]
protected static final int
protected static final Class[]
protected static Format
used for representing the java value null.protected int
Format already generated for this particular object.String value to compiled pattern, for skipping parsing process in case of identical format source tests for different classes.Fields inherited from class eu.bandm.tools.tdom.runtime.BaseVisitor
validating
-
Constructor Summary
ModifierConstructorDescriptionprotected
DynamicFormatter
(MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Only constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected eu.bandm.tools.formatfrontends.absy.Element_append
protected eu.bandm.tools.formatfrontends.absy.Element_append
casesStringOrChar
(eu.bandm.tools.formatfrontends.absy.Element_cases cases, String childname, String value, boolean ischar) protected static Format
defaultFormat
(Object model) used for representing any java object "model" for which no format code could be found.protected Format
protected void
error
(Location<XMLDocumentIdentifier> loc, String s) protected Method
findToFormatMethod
(Class<?> cls) protected Format
central method for generating a format for a given object (="model").protected Format
central method for generating a format for a given object (="model").getFormatHint
(Class<?> cls) Side-door entry for interception: retrieve the class specific format description source text.static String
getFormatHint
(Class cls, MessageReceiver<SimpleMessage> msg) convenience method.protected Format
invokeToFormatMethod
(Object model, Method method) eu.bandm.tools.formatfrontends.absy.Element_pattern
Side-door entry for interception: Parses a format front end language string and delivers the AST as a tdom model.protected Format
processChild
(Object child) protected Format
protected Format
processFoldOrList
(Collection list) protected Format
processMap
(Map map) static Format
toFormat
(Object model, MessageReceiver<? super SimpleMessage> msg) convenience method.static Format
toFormat
(Object model, String formathint, MessageReceiver<? super SimpleMessage> msg) convenience method.void
visit
(eu.bandm.tools.formatfrontends.absy.Element_alternative element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_append element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_appendOp element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_beneath element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_beneathOp element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_beside element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_besideOp element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_block element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_blockOp element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_child element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_clss element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_clssUPCASE element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_emptylistrepr element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_from element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_indent element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_indent_op element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_line element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_lineOp element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_listdescr element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_literal element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_number element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_ref element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_supr element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_swtch element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_tabular element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_thiz element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_too element) void
visit
(eu.bandm.tools.formatfrontends.absy.Element_whitespace element) protected void
warning
(Location<XMLDocumentIdentifier> loc, String s) Methods inherited from class eu.bandm.tools.formatfrontends.absy.Visitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
Methods inherited from class eu.bandm.tools.tdom.runtime.BaseVisitor
visit
-
Field Details
-
default_indentation
public int default_indentationused for identation formats without explict number part. Default value is two(2), but can be re-configured anytime. -
null_representation
used for representing the java value null. Default value is "Format.literal("null")", but can be re-configured anytime. -
cacheFormatForObject
public boolean cacheFormatForObjectcontrols caching of generated formats for objects, both putting and getting. Turning on caching makes only sense for immutable objects (i.e. immutable at least during life-time of this DynamicFormatter).. Default value is "false", but can be re-configured anytime. -
cachePatternForClass
public boolean cachePatternForClasscontrols caching of retrieved format code for java classes, both putting and getting. Turning on caching makes sense in most cases, when only one format code is constantly used for each class. Default value is "true", but can be re-configured anytime. -
msg
-
model
-
format
-
number
protected int number -
literals
-
checkedmode
protected boolean checkedmode -
NAME_METHOD_getFormatHint
name of the method a class must (re-)define to define the format code which shall be used for their instances.
Value is "getFormatHint"- See Also:
-
NAME_METHOD_toFormat
name of the method a class can (re-)define to build a format representation for its instances "manually", by calling theFormat
factory directly. Value is "toFormat"- See Also:
-
NO_FOLD
protected static final int NO_FOLD- See Also:
-
FOLD_BENEATH
protected static final int FOLD_BENEATH- See Also:
-
FOLD_BESIDE
protected static final int FOLD_BESIDE- See Also:
-
FOLD_LINE
protected static final int FOLD_LINE- See Also:
-
FOLD_BLOCK
protected static final int FOLD_BLOCK- See Also:
-
FOLD_APPEND
protected static final int FOLD_APPEND- See Also:
-
childinfo
-
CHILDINFO_PLAIN
-
emptyList
-
foundchild
-
foundchildname
-
NO_PARAMS
-
NO_ARGS
-
NOSUPER
-
object2format
Format already generated for this particular object. -
class2formatMethod
"toFormat" method of class, or constant "null" if no pattern and no toFormat() method exist and default has to be used. -
class2pattern
protected static final HashMap<Class,eu.bandm.tools.formatfrontends.absy.Element_pattern> class2patterncompiled pattern for class -
text2pattern
protected static final HashMap<String,eu.bandm.tools.formatfrontends.absy.Element_pattern> text2patternString value to compiled pattern, for skipping parsing process in case of identical format source tests for different classes.
-
-
Constructor Details
-
DynamicFormatter
Only constructor.- Throws:
IllegalArgumentException
- iff msg is equal to null.
-
-
Method Details
-
error
-
warning
-
defaultFormat
used for representing any java object "model" for which no format code could be found. Default value is "Format.literal(String.valueOf(model))", but can be re-configured anytime. -
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_alternative element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beneath element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beside element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_line element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_block element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_append element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_number element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_indent element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_indent_op element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_literal element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_whitespace element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_clss element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_clssUPCASE element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_tabular element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_listdescr element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_emptylistrepr element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beneathOp element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_besideOp element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_lineOp element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_blockOp element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_appendOp element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_from element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_too element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_thiz element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_ref element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_swtch element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
casesInt
protected eu.bandm.tools.formatfrontends.absy.Element_append casesInt(eu.bandm.tools.formatfrontends.absy.Element_cases cases, String childname, int value) -
casesStringOrChar
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_supr element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_child element) - Overrides:
visit
in classeu.bandm.tools.formatfrontends.absy.Visitor
-
processChild
-
processMap
-
processFoldOrList
-
foldit
-
processCollectionCode
-
findToFormatMethod
-
invokeToFormatMethod
-
getFormatHint
Side-door entry for interception: retrieve the class specific format description source text.
This method calls via reflection the classes static method named "getFormatHint()" (which is the value of "static final String NAME_METHOD_getFormatHint
") and returns the returned String value. -
parseHint
Side-door entry for interception: Parses a format front end language string and delivers the AST as a tdom model. -
deliver
-
format
central method for generating a format for a given object (="model").
The source text representing the format structure is retrieved by the multi-alternative strategy which is describedin the class documentation
. -
format
central method for generating a format for a given object (="model").
The source text representing the format structure of the top-level model is given explicitly. Those for recursively contained objects is retrieved by the multi-alternative strategy which is describedin the class documentation
.
Attention: possibly writes into cache "object to format" (without reading it). -
format
-
toFormat
-
toFormat
public static Format toFormat(Object model, String formathint, MessageReceiver<? super SimpleMessage> msg) -
getFormatHint
-