Package eu.bandm.tools.tdom
Class TypedDOMGenerator
java.lang.Object
eu.bandm.tools.dtd.DTD.MATCH_ONLY_00
eu.bandm.tools.dtd.DTD.Visitor
eu.bandm.tools.tdom.TypedDOMGenerator
Top-level class for converting a DTD into a collection of Java sources.
Programmatic usage:
(The
Software Architecture:
The perform() method is simply calling (2.1) "match()" to the DTD as a whole. The different "[XXX]Template"-classes grow in parallel with the corresponding
Most important is the single instance of
- (1) create instance (by one of two constructors)
- (2) call
perform()
- (3) call
write(int)
(The
main(java.lang.String[])
procedure is only for bootstrapping purpose, use TDOM_Main
instead.)
Software Architecture:
The perform() method is simply calling (2.1) "match()" to the DTD as a whole. The different "[XXX]Template"-classes grow in parallel with the corresponding
metajava
"Generated[XXX]" instances.
The former keep information on a meta-level, needed for further code generation.
They are filled in different stages and possibly read information from other
template objects.
Most important is the single instance of
PackageTemplate
, which holds
esp. compiled information of the DTD (AttlistIndex etc) and the analysed command line
parameters, etc.
(The state machine and the data flow between these template objects is complicated, non-formalised and mostly still undocumented, FIXME !-)
Finally (2.2) "perform()" invokes the method "finish()" on the top template
(=packageTemplate
, propagating down).
The generated source text is written to output files by calling write(int)
.
Internally this is also propagated downwards through the template hierarchy by
invoking PackageTemplate.write(int)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Steps through the DTD and processes all PIs which have a tdom namespace declaration.(package private) static interface
Functional type to make the call ofHtmlRenderer
switchable.static class
Collect the processing instructions for private/public classification of elements. -
Field Summary
Modifier and TypeFieldDescriptionstatic final GeneratedAnnotation
static final GeneratedAnnotation
static final GeneratedAnnotation
static final GeneratedAnnotation
static final GeneratedAnnotation
static final MetaClass
static final MetaClass
(package private) static final Format
protected TypedDOMGenerator.DtdRenderer
Stub which does nothing in the boot phase.static final MetaClass
static final Format
static final MetaClass
protected boolean
Sticky flag whether at least one error has been generated.(package private) static final Format
DOCMEstatic final int
(package private) final MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>>
Central message receiver, set up when constructing this instance.static final String
static final String
The qualified name of the package of the tdom runtime classes.static final MetaClass
static final String
static final MetaClass
Fields inherited from class eu.bandm.tools.dtd.DTD.Visitor
hasdescend, haspost, haspre
Fields inherited from class eu.bandm.tools.dtd.DTD.MATCH_ONLY_00
_visitor_debug_stream, partial
-
Constructor Summary
ConstructorDescriptionTypedDOMGenerator
(DTD.Dtd dtd, File destination, String packageName, boolean useArrays, boolean generateFunctions, boolean paisleySupport, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> rec) Variant which gets the DTD as a completely self-contained object.TypedDOMGenerator
(File dtdFile, FileReader dtdReader, File destination, String packageName, boolean useArrays, boolean generateFunctions, boolean paisleySupport, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> rec) Variant which reads the dtd from the given FileReader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
action
(DTD.Attlist attlist) Does do nothing.void
action
(DTD.Choice cp) void
Main activity of the TDOM compiler.void
action
(DTD.Element element) Code generation for one declared element.void
Do all compilation for an empty content model.void
Generate all subclasses, constructors and parsing methods for mixed content.void
void
action
(DTD.Singleton cp) Create the access methods for one single element reference in the growing content model.(package private) void
addGetterFunction
(int modifiers, GeneratedMethod getter) static String
capitalize
(String s) Turn the very first character to uppercase.(package private) static void
createGetterFunction
(GeneratedClass parent, int modifiers, String name, MetaType domain, MetaType range, Format body) protected void
DOCMEprotected void
error
(Location<XMLDocumentIdentifier> location, String text) DOCMEprotected void
DOCMEprotected void
exit()
DOCME(package private) static final Format
expression
(String code) DOCMEprotected void
fatalError
(String text) Send the error text to the message channelrec
and abort program execution immediately.protected void
hint
(Location<XMLDocumentIdentifier> loc, String text) DOCMEprotected void
DOCMEprotected void
DOCMEstatic void
Deprecated.protected static String
makeFieldDescription
(int number, MetaClass contentClass) make a human language identification of the compontent of a content model.static String
makeJavaName
(String name) Translate a token following the production [5] = Name or [7] = Nmtoken from [XML 1.0] into a Java identifier.Returns the tail of a PI's text, iff the target is "tdom", and the text begins with key, followed by a blank or the end of the string.void
perform()
Main service access methods when using TDOM: Creates all components of the model.protected static Format
positionNumberFormat
(int i) (package private) static final Format
DOCME Is also used by all subclasses ofTemplate
.(package private) static final Format
statements
(String code) DOCMEstatic void
usage()
protected void
DOCMEvoid
write
(int lineWidth) Write out all components finally accumulated inpackageTemplate
.Methods inherited from class eu.bandm.tools.dtd.DTD.Visitor
action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, action, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, descend, follow_alts, follow_atts, follow_elems, follow_locations, follow_locations, follow_locations, follow_markup, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, post, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre, pre
Methods inherited from class eu.bandm.tools.dtd.DTD.MATCH_ONLY_00
action, action, action, action, compile, followAll_alts, followAll_atts, followAll_elems, followAll_locations, followAll_locations, followAll_locations, followAll_markup, foreignObject, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, match, nomatch
-
Field Details
-
RENDERED_DTD_SUFFIX
- See Also:
-
annotationUser
-
annotationHidden
-
annotationDeprecated
-
annotationOverride
-
annotationOpt
-
functionType
-
checkedListType
-
checkedListPlusType
-
exception
-
runtimeException
-
tdomAttributeException
-
PUBLIC_STATIC_FINAL
public static final int PUBLIC_STATIC_FINAL- See Also:
-
RUNTIME_PACKAGE_NAME
The qualified name of the package of the tdom runtime classes. (Is dynamically calculated, but normally yields "eu.bandm.tools.tdom.runtime
".) -
rec
Central message receiver, set up when constructing this instance. -
hasErrors
protected boolean hasErrorsSticky flag whether at least one error has been generated. -
nullExpr
DOCME -
dtdRenderer
Stub which does nothing in the boot phase. since the code is not yet compiled.TDOM_Main
will override this function with an invocation ofHtmlRenderer
. -
STRING_DOC_SEPARATOR
- See Also:
-
FORMAT_DOC_SEPARATOR
-
docComment_inheritDocAndThrows
-
-
Constructor Details
-
TypedDOMGenerator
public TypedDOMGenerator(File dtdFile, FileReader dtdReader, File destination, String packageName, boolean useArrays, boolean generateFunctions, boolean paisleySupport, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> rec) Variant which reads the dtd from the given FileReader. Creates thepackageTemplate
, which holds most global parameters, esp. from the command line, and already extracts global information from the dtd.- Parameters:
dtdFile
- the file containing the dtd. (Needed to address the parent directory for DTD file includes.)dtdReader
- a reader delivering the dtd textdestination
- directory where to put the generared sourcespackageName
- the full java package name for all generated sourcesuseArrays
- whether to generate arrays instead of (checked) listsgenerateFunctions
- (deprecated due to jave "c::f" syntax, should be falsepaisleySupport
- whether to generated paisley patterns for field access FIXME NOT SUPPORTEDrec
- Receiver for all error messages
-
TypedDOMGenerator
public TypedDOMGenerator(DTD.Dtd dtd, File destination, String packageName, boolean useArrays, boolean generateFunctions, boolean paisleySupport, MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> rec) Variant which gets the DTD as a completely self-contained object. Creates thepackageTemplate
, which holds most global parameters, esp. from the command line, and already extracts global information from the dtd.- Parameters:
dtd
- the DTD object to translatedestination
- directory where to put the generated sourcespackageName
- the full java package name for all generated sourcesuseArrays
- whether to generate arrays instead of (checked) listsgenerateFunctions
- (deprecated due to jave "c::f" syntax, should be falsepaisleySupport
- whether to generated paisley patterns for field access FIXME NOT SUPPORTEDrec
- Receiver for all error messages
-
-
Method Details
-
usage
public static void usage() -
main
Deprecated.useTDOM_Main.main(String[])
instead, which has many more command line options.This version is required for bootstrap purpose and works without command line parsing. It just expects [0] destination directory, [1] package name and [2] file position of the source dtd on the command line. -
perform
public void perform()Main service access methods when using TDOM: Creates all components of the model. This is ruled by the entries inpackageTemplate
, which have been set up when constructing this instance. All generated instances are realized by subclasses ofTemplate
and can be retrieved from thepackageTemplate
. This method only executes a DTD visitor match() on the DTD object. -
write
public void write(int lineWidth) Write out all components finally accumulated inpackageTemplate
. The text output goes to the destination which has been set when constructing this and that instance.- Parameters:
lineWidth
- the maximum column printed in the output (approx.!)
-
log
DOCME -
warning
DOCME -
hint
DOCME -
hint
DOCME -
error
DOCME -
error
protected void error(@Opt @Opt Exception ex, @Opt @Opt Location<XMLDocumentIdentifier> location, String text) DOCME -
error
DOCME -
fatalError
Send the error text to the message channelrec
and abort program execution immediately. -
exit
protected void exit()DOCME -
statement
DOCME Is also used by all subclasses ofTemplate
. -
statements
DOCME -
expression
DOCME -
action
Main activity of the TDOM compiler. The steps are- Some preparatory visitors are sent over the whole DTD for information collection.
- Then similar preparatory steps are performed by the parallel
TypedAttrsGenerator.prepareCommon(DTD.Dtd)
- Then this visitor is descending to the Elements for generating the code.
This is stored in the corresponding
ElementTemplate
, mostly by descending into the element's content model. Also methods from theTypedAttrsGenerator.prepareCommon(DTD.Dtd)
are called for each declared attribute.
- Overrides:
action
in classDTD.Visitor
-
action
Code generation for one declared element. Classes for the element itself, all sub-content structures and all attributes are built, including constructors, setter and getter methods, host methods for the visitors, etc.- Overrides:
action
in classDTD.Visitor
-
action
Does do nothing. Attlists are compiled when the hosting Element is compiled.- Overrides:
action
in classDTD.Visitor
-
makeJavaName
Translate a token following the production [5] = Name or [7] = Nmtoken from [XML 1.0] into a Java identifier. This is done by replacing any of {:.-} by an underscore "_".
Also lists of names or nmtokens can be processed when they are in one string, separated by blanks.
(CURRENTLY: The validity is NOT checked.) -
capitalize
Turn the very first character to uppercase. UsesString.toUpperCase()
, with default locale. -
action
Do all compilation for an empty content model.- Overrides:
action
in classDTD.Visitor
-
action
Generate all subclasses, constructors and parsing methods for mixed content. DOCME MORE- Overrides:
action
in classDTD.Visitor
-
action
Create the access methods for one single element reference in the growing content model.- Overrides:
action
in classDTD.Visitor
-
action
- Overrides:
action
in classDTD.Visitor
-
action
- Overrides:
action
in classDTD.Visitor
-
parsePI
Returns the tail of a PI's text, iff the target is "tdom", and the text begins with key, followed by a blank or the end of the string.- Returns:
- the rest after the key, trimmed.
-
addGetterFunction
-
createGetterFunction
static void createGetterFunction(GeneratedClass parent, int modifiers, String name, MetaType domain, MetaType range, Format body) -
positionNumberFormat
-
makeFieldDescription
make a human language identification of the compontent of a content model.
-
TDOM_Main.main(String[])
instead, which has many more command line options.