Class TypedDOMGenerator


public class TypedDOMGenerator extends DTD.Visitor
Top-level class for converting a DTD into a collection of Java sources. Programmatic usage: .
(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).

  • Field Details

    • RENDERED_DTD_SUFFIX

      public static final String RENDERED_DTD_SUFFIX
      See Also:
    • annotationUser

      public static final GeneratedAnnotation annotationUser
    • annotationHidden

      public static final GeneratedAnnotation annotationHidden
    • annotationDeprecated

      public static final GeneratedAnnotation annotationDeprecated
    • annotationOverride

      public static final GeneratedAnnotation annotationOverride
    • annotationOpt

      public static final GeneratedAnnotation annotationOpt
    • functionType

      public static final MetaClass functionType
    • checkedListType

      public static final MetaClass checkedListType
    • checkedListPlusType

      public static final MetaClass checkedListPlusType
    • exception

      public static final MetaClass exception
    • runtimeException

      public static final MetaClass runtimeException
    • tdomAttributeException

      public static final MetaClass tdomAttributeException
    • PUBLIC_STATIC_FINAL

      public static final int PUBLIC_STATIC_FINAL
      See Also:
    • RUNTIME_PACKAGE_NAME

      public static final String 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 hasErrors
      Sticky flag whether at least one error has been generated.
    • nullExpr

      static final Format nullExpr
      DOCME
    • dtdRenderer

      protected TypedDOMGenerator.DtdRenderer 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 of HtmlRenderer.
    • STRING_DOC_SEPARATOR

      public static final String STRING_DOC_SEPARATOR
      See Also:
    • FORMAT_DOC_SEPARATOR

      public static final Format FORMAT_DOC_SEPARATOR
    • docComment_inheritDocAndThrows

      static final Format 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 the packageTemplate, 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 text
      destination - directory where to put the generared sources
      packageName - the full java package name for all generated sources
      useArrays - whether to generate arrays instead of (checked) lists
      generateFunctions - (deprecated due to jave "c::f" syntax, should be false
      paisleySupport - whether to generated paisley patterns for field access FIXME NOT SUPPORTED
      rec - 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 the packageTemplate, which holds most global parameters, esp. from the command line, and already extracts global information from the dtd.
      Parameters:
      dtd - the DTD object to translate
      destination - directory where to put the generated sources
      packageName - the full java package name for all generated sources
      useArrays - whether to generate arrays instead of (checked) lists
      generateFunctions - (deprecated due to jave "c::f" syntax, should be false
      paisleySupport - whether to generated paisley patterns for field access FIXME NOT SUPPORTED
      rec - Receiver for all error messages
  • Method Details

    • usage

      public static void usage()
    • main

      @Deprecated public static void main(String[] args)
      Deprecated.
      use TDOM_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 in packageTemplate, which have been set up when constructing this instance. All generated instances are realized by subclasses of Template and can be retrieved from the packageTemplate. This method only executes a DTD visitor match() on the DTD object.
    • write

      public void write(int lineWidth)
      Write out all components finally accumulated in packageTemplate. 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

      protected void log(String text)
      DOCME
    • warning

      protected void warning(String text)
      DOCME
    • hint

      protected void hint(String text)
      DOCME
    • hint

      protected void hint(Location<XMLDocumentIdentifier> loc, String text)
      DOCME
    • error

      protected void error(Location<XMLDocumentIdentifier> location, String text)
      DOCME
    • error

      protected void error(@Opt @Opt Exception ex, @Opt @Opt Location<XMLDocumentIdentifier> location, String text)
      DOCME
    • error

      protected void error(String text)
      DOCME
    • fatalError

      protected void fatalError(String text)
      Send the error text to the message channel rec and abort program execution immediately.
    • exit

      protected void exit()
      DOCME
    • statement

      static final Format statement(String code)
      DOCME Is also used by all subclasses of Template.
    • statements

      static final Format statements(String code)
      DOCME
    • expression

      static final Format expression(String code)
      DOCME
    • action

      public void action(DTD.Dtd dtd)
      Main activity of the TDOM compiler. The steps are
      1. Some preparatory visitors are sent over the whole DTD for information collection.
      2. Then similar preparatory steps are performed by the parallel TypedAttrsGenerator.prepareCommon(DTD.Dtd)
      3. 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 the TypedAttrsGenerator.prepareCommon(DTD.Dtd) are called for each declared attribute.
      Overrides:
      action in class DTD.Visitor
    • action

      public void action(DTD.Element element)
      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 class DTD.Visitor
    • action

      public void action(DTD.Attlist attlist)
      Does do nothing. Attlists are compiled when the hosting Element is compiled.
      Overrides:
      action in class DTD.Visitor
    • makeJavaName

      public static String makeJavaName(String name)
      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

      public static String capitalize(String s)
      Turn the very first character to uppercase. Uses String.toUpperCase(), with default locale.
    • action

      public void action(DTD.Empty content)
      Do all compilation for an empty content model.
      Overrides:
      action in class DTD.Visitor
    • action

      public void action(DTD.Mixed content)
      Generate all subclasses, constructors and parsing methods for mixed content. DOCME MORE
      Overrides:
      action in class DTD.Visitor
    • action

      public void action(DTD.Singleton cp)
      Create the access methods for one single element reference in the growing content model.
      Overrides:
      action in class DTD.Visitor
    • action

      public void action(DTD.Seq cp)
      Overrides:
      action in class DTD.Visitor
    • action

      public void action(DTD.Choice cp)
      Overrides:
      action in class DTD.Visitor
    • parsePI

      @Opt public static @Opt String parsePI(DTD.PI pi, String key)
      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

      void addGetterFunction(int modifiers, GeneratedMethod getter)
    • createGetterFunction

      static void createGetterFunction(GeneratedClass parent, int modifiers, String name, MetaType domain, MetaType range, Format body)
    • positionNumberFormat

      protected static Format positionNumberFormat(int i)
    • makeFieldDescription

      protected static String makeFieldDescription(int number, MetaClass contentClass)
      make a human language identification of the compontent of a content model.