Class ModuleRegistry
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Common superclass for debug output.protected class
Auxiliary class for printing the definition contents of instantiated modules.protected class
Auxiliary class for printing the definition contents of un-instantiated modules. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The text which explains how to activate the default d2d text definition library. -
Constructor Summary
ConstructorDescriptionEvident -
Method Summary
Modifier and TypeMethodDescriptionAppends a string which is the representation of a possible location of module sources to theend of the list of searched locations, as maintained by sourceHabitats
.Called when reusing this instance for several d2d text source files, each of which may be opened by a different "local module" definition.int
Returns the trace level.instantiate
(Module topmod, String[] names) Finds a d2d definition sub-module in a top-level module and instantiates it.load_instantiated
(String qName) Loads a module identified by its name (a sequence of identifiers separated byChars.REGEXP_NAMING_LEVEL_SEPARATOR
) and subsequently instantiates all imports etc.load_instantiated_tdom
(String qName) Loads a tdom dtd as a ddf module.load_uninstantiated
(String qName, boolean considerLocals) External entry point for loading an uninstantiated d2d definition module.Returns null in case of error.static ModuleRegistry
makeInstance
(MessageReceiver<SimpleMessage<XMLDocumentIdentifier>> msgr, int debug, String... searchpath) Factory method which constructs and initializes.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.void
print_instantiated
(String name, PrintStream p, int w) Print the instantiated module with the given name, if currently existing.void
print_uninstantiated
(String name, PrintStream p, int w) Print the un-instantiated module with the given name, if already loaded.EvidentsetTracelevel
(int tracelevel) Sets the trace level and the amount of generated messages (error and failure messages are always generated):
.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).(package private) void
Show a log message only when the current value oftracelevel
is larger.
-
Field Details
-
sourceHabitatErrorHint
The text which explains how to activate the default d2d text definition library.- See Also:
-
-
Constructor Details
-
ModuleRegistry
Evident
-
-
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 nameConstants.DEFAULT_LIBRARY_SHORTCUT
stands for the source habitat (=file system directory)Constants.DEFAULT_LIBRARY
. -
setMsgReceiver
Evident -
setTracelevel
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
Appends a string which is the representation of a possible location of module sources to theend of the list of searched locations, as maintained by sourceHabitats
. -
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
-
trace
Show a log message only when the current value oftracelevel
is larger. Print the hashcode identity of this instante, and then text and args. -
load_instantiated_tdom
Loads a tdom dtd as a ddf module. Both are identified by its name (a sequence of identifiers separated byChars.REGEXP_NAMING_LEVEL_SEPARATOR
).- Returns:
null
when errors occured in class loading or translation.
-
load_instantiated
Loads a module identified by its name (a sequence of identifiers separated byChars.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 insourceHabitats
.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
External entry point for loading an uninstantiated d2d definition module. The module is identified by its name (a sequence of identifiers separated byChars.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 tomsg
and returnsnull
on failure, including file-not-found. -
instantiate
Finds a d2d definition sub-module in a top-level module and instantiates it.- Returns:
null
on error (and send error messages tomsg
-
storeLocalModule
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 intoplevel_local
. -
parseToplevelModuleFromReader
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 parsefilename
- for diagnosis only- Returns:
null
on error (and send error messages to receiver)
-
loadMetaModule
Returns null in case of error. Stores tometaModuleLoaded
and toloadedMetaModule
- -
print_instantiated
Print the instantiated module with the given name, if currently existing.- Parameters:
p
- the drain of the print commandsw
- the linewidth used for formatting.
-
print_uninstantiated
Print the un-instantiated module with the given name, if already loaded.- Parameters:
p
- the drain of the print commandsw
- the linewidth used for formatting.
-