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 = <model>.get_<fieldname>()"
2) "newmodel = <model>.<fieldname>"
==> 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 ofDynamicFormatter. Its default implementation uses "toString()" and creates a simpleFormat.Literal.
FIXME for child values : try via reflection
1) "newmodel = <model>.get_<fieldname>()"
2) "newmodel = <model>.<fieldname>"
==> can be used for umod style and for "public" foreign definitions.
FIXME
maintain CACHE structure for both !! --
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleancontrols caching of generated formats for objects, both putting and getting.booleancontrols caching of retrieved format code for java classes, both putting and getting.protected booleanprotected DynamicFormatter.ChildInfoprotected 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 classintused for identation formats without explict number part.protected Formatprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected Formatprotected Objectprotected Stringprotected Objectprotected MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> static final Stringname of the method a class must (re-)define to define the format code which shall be used for their instances.static final Stringname of the method a class can (re-)define to build a format representation for its instances "manually", by calling theFormatfactory directly.protected static final Object[]protected static final intprotected static final Class[]protected static Formatused for representing the java valuenull.protected intFormat 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
ConstructorsModifierConstructorDescriptionprotectedDynamicFormatter(MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Only constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected eu.bandm.tools.formatfrontends.absy.Element_appendprotected eu.bandm.tools.formatfrontends.absy.Element_appendcasesStringOrChar(eu.bandm.tools.formatfrontends.absy.Element_cases cases, String childname, String value, boolean ischar) protected static FormatdefaultFormat(Object model) used for representing any java object "model" for which no format code could be found.protected Formatprotected voiderror(Location<XMLDocumentIdentifier> loc, String s) protected MethodfindToFormatMethod(Class<?> cls) protected Formatcentral method for generating a format for a given object (="model").protected Formatcentral 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 StringgetFormatHint(Class cls, MessageReceiver<SimpleMessage> msg) convenience method.protected FormatinvokeToFormatMethod(Object model, Method method) eu.bandm.tools.formatfrontends.absy.Element_patternSide-door entry for interception: Parses a format front end language string and delivers the AST as a tdom model.protected FormatprocessChild(Object child) protected Formatprotected FormatprocessFoldOrList(Collection list) protected FormatprocessMap(Map map) static FormattoFormat(Object model, MessageReceiver<? super SimpleMessage> msg) convenience method.static FormattoFormat(Object model, String formathint, MessageReceiver<? super SimpleMessage> msg) convenience method.voidvisit(eu.bandm.tools.formatfrontends.absy.Element_alternative element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_append element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_appendOp element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_beneath element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_beneathOp element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_beside element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_besideOp element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_block element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_blockOp element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_child element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_clss element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_clssUPCASE element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_emptylistrepr element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_from element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_indent element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_indent_op element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_line element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_lineOp element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_listdescr element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_literal element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_number element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_ref element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_supr element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_swtch element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_tabular element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_thiz element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_too element) voidvisit(eu.bandm.tools.formatfrontends.absy.Element_whitespace element) protected voidwarning(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, visitMethods 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 valuenull. 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 theFormatfactory 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:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beneath element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beside element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_line element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_block element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_append element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_number element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_indent element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_indent_op element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_literal element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_whitespace element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_clss element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_clssUPCASE element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_tabular element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_listdescr element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_emptylistrepr element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_beneathOp element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_besideOp element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_lineOp element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_blockOp element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_appendOp element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_from element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_too element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_thiz element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_ref element) - Overrides:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_swtch element) - Overrides:
visitin 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:
visitin classeu.bandm.tools.formatfrontends.absy.Visitor
-
visit
public void visit(eu.bandm.tools.formatfrontends.absy.Element_child element) - Overrides:
visitin 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 "") and returns the returned String value.static final String NAME_METHOD_getFormatHint -
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
-