Class ModuleRegistry

java.lang.Object
eu.bandm.tools.d2d2.base.ModuleRegistry

@CyclicDependency public final class ModuleRegistry extends Object
Resolves module names to Module objects. For this it searches a list of sourceHabitats. Acts like a like a "ClassLoader" does for Java classes. Normally only one central instance exists.

For parsing d2d input text, first the doc type definition module is loaded by calling load_instantiated(String).
For some meta-tasks (checking, documentation, visualization) also load_uninstantiated(String,boolean) has been made public.
Both rely on a unique mappig of module identifiers to definition files, which contain the module definition text. This can be either (nested!) d2d-definition modules, or third party formats like dtd or umod.
LOCAL module definitions are NOT contained in files of their own, but contained in a certain text document as its prefix. They are inserted in the cache of un-instantiated modules by the text parsing function from Text2Udom EXPLICITLY calling storeLocalModule(MemScanner,String), and thus retrieved little later by "load_instantiated()" when processing the text header.
Before processing the next textfile, the uninstantiated cache must be cleared from all these local modules by calling clearLocalModuleDefs().
For parsing and further processing an instantiated Module is required. This is calcaluted by Resolver4.resolveAllPublics().
Basic overall control flow is thus as follows:

    load_instantiated(String = module id)
         IFF already found in cache -> return chached instantiated Module object 
                                       (or null in case of former error, incl. file not found)
         -> load_toplevel_d2d_module(topmost-module-name)
                      ->sourceHabitats.searchAllPlaces(id, suffices)
                      ->parseToplevelModuleFromReader(..)
                           -> XantlrTdom.parse()
                           -> Reducer.reduce()
                           -> Navigate.LocalReferenceNormalizer.match();
         -> instantiate(Module, qualidfiedModuleName)
                      -> Resolver4.resolveAllPublics()
         ELSE load_dtd_module()
                 -> sourceHabitats.searchAllPlaces(id, suffices)
                 -> TunedDTDParser.parse(..)
                 -> Dtd2Def.converts(..)
         ELSE load_umod_module()
                 -> sourceHabitats.searchAllPlaces(id, suffices)
                 -> umod.Main.stream2umod(..)
                 -> UMod2Ddf.converts(..)
                 -> Resolver4.resolveAllPublics()
         // ELSE further formats possible
 
  • Field Details

    • sourceHabitatErrorHint

      public static final String sourceHabitatErrorHint
      The text which explains how to activate the default d2d text definition library.
      See Also:
  • Constructor Details

  • Method Details

    • makeInstance

      public static ModuleRegistry makeInstance(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgr, int debug, String... searchpath)
      Factory method which constructs and initializes. In the search path, the name Constants.DEFAULT_LIBRARY_SHORTCUT stands for the source habitat (=file system directory) Constants.DEFAULT_LIBRARY.
    • setMsgReceiver

      Evident
    • setTracelevel

      public ModuleRegistry setTracelevel(int tracelevel)
      Sets the trace level and the amount of generated messages (error and failure messages are always generated):
      . ==0 stands for complete silence
      ==1 stands for minimal output: only few major loggings.
      ==2 all loggings and few warnings ==3 all warngings (even ecxotic cases) plus some hints ==4 full information = additional hints and extended context information. ==10 shows some synthesized source texts
      ==20 full debugging, tracing, and printing of synthesized source texts..
    • getTracelevel

      public int getTracelevel()
      Returns the trace level. Used by code which employs a ModuleRegistry, to adopt its own verbosity.
    • appendToSourceList

      public ModuleRegistry appendToSourceList(String s)
      Appends a string which is the representation of a possible location of module sources to the end of the list of searched locations, as maintained by sourceHabitats.
    • clearLocalModuleDefs

      public ModuleRegistry clearLocalModuleDefs()
      Called when reusing this instance for several d2d text source files, each of which may be opened by a different "local module" definition.
    • d2d_fileSuffices_toString

      public String d2d_fileSuffices_toString()
    • trace

      void trace(int level, String txt, Object... args)
      Show a log message only when the current value of tracelevel is larger. Print the hashcode identity of this instante, and then text and args.
    • load_instantiated_tdom

      @Opt public @Opt ResolvedModule load_instantiated_tdom(String qName)
      Loads a tdom dtd as a ddf module. Both are identified by its name (a sequence of identifiers separated by Chars.REGEXP_NAMING_LEVEL_SEPARATOR).
      Returns:
      null when errors occured in class loading or translation.
    • load_instantiated

      @Opt public @Opt ResolvedModule load_instantiated(String qName)
      Loads a module identified by its name (a sequence of identifiers separated by Chars.REGEXP_NAMING_LEVEL_SEPARATOR) and subsequently instantiates all imports etc.
      Try to use the module name as d2d definition's name (=qualified id, top-most identifier must match some source file name, or is loaded as a local definition module), or the complete name as a dtd file name stem, or as the file name stem of a umod definition. For all these variants look in all places in sourceHabitats.

      All non-local modules will be saved for future retrieval.

      Returns:
      null when errors occured in loading an existing source file, or when no single source file variant is visible.
    • load_uninstantiated

      @Opt public @Opt Module load_uninstantiated(String qName, boolean considerLocals)
      External entry point for loading an uninstantiated d2d definition module. The module is identified by its name (a sequence of identifiers separated by Chars.REGEXP_NAMING_LEVEL_SEPARATOR). In case of a ".ddf" defintion module, the first name is mapped to a file in some appropriate source-code habitat. This method is called by the Resolver for imported modules. Furthermore it may be called eg. for documentation generation. Sends log and error messages to msg and returns null on failure, including file-not-found.
    • instantiate

      @Opt public @Opt ResolvedModule instantiate(Module topmod, String[] names)
      Finds a d2d definition sub-module in a top-level module and instantiates it.
      Returns:
      null on error (and send error messages to msg
    • storeLocalModule

      public Module storeLocalModule(MemScanner<?> mem, String filename)
      Feeds the prefix of a text document into the cache of uninstantiated modules, to retrieve it instantiated (a few processing steps later). Stores the toplevel uninstantiated module in toplevel_local.
    • parseToplevelModuleFromReader

      @Opt @Opt Module parseToplevelModuleFromReader(Reader charstream, String filename)
      Loads a top-level d2d definition module (with all sub-modules, uninstantiaated), which has not yet been read in at all.

      Is called (internally) for a top-level module, which (together with its sub-modules contained therein) makes up the whole stream content, --- or externally for local modules, which start at the current stream reading position of some text input file, which afterwards will be further consumed for the d2d text contents.

      Parameters:
      charstream - source text to parse
      filename - for diagnosis only
      Returns:
      null on error (and send error messages to receiver)
    • loadMetaModule

      @Opt public @Opt ResolvedModule loadMetaModule()
      Returns null in case of error. Stores to metaModuleLoaded and to loadedMetaModule-