astcentric.structure.basic
Class DefaultASTLoader

java.lang.Object
  extended by astcentric.structure.basic.DefaultASTLoader
All Implemented Interfaces:
ASTLoader
Direct Known Subclasses:
DefaultASTPersistenceManager

public class DefaultASTLoader
extends java.lang.Object

Default AST loader which loads ASTs form a (virtual) file system specified in a ASTPath. The loading policy is ask last. Initially there is no NodeValidator defined for validating an AST after loading.


Field Summary
protected  java.util.Map<ASTID,T> _cache
           
protected  boolean _seal
           
 
Constructor Summary
DefaultASTLoader(ASTLoader loader, ASTPath astPath, boolean seal)
          Creates an new loader for the specified parent loader and AST path.
DefaultASTLoader(ASTPath astPath, boolean seal)
          Creates an instance for the specified AST path with no parent loader.
 
Method Summary
 VirtualFile getASTFile(ASTID astID)
          Returns the file associated with specified AST.
 ASTLoader getParent()
          Returns the parent loader.
 NodeValidator getValidator()
          Returns the node validator.
protected  void handleASTWith(T astWith, ASTID astID)
           
 AST loadAST(ASTID astID)
          Loads the AST specified by the ID.
 void registerASTListenerFor(ASTID id, ASTListener listener)
          Registers the specified listener for the AST specified by its ID.
 void setValidator(NodeValidator validator)
          Sets the node validator which will be used to validate an AST after loading.
 void traverseAllLoadableASTs(ASTInfoHandler handler, boolean includeAncestors)
          Traverses all loadable ASTs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cache

protected final java.util.Map<ASTID,T extends astcentric.structure.basic.ASTWith> _cache

_seal

protected final boolean _seal
Constructor Detail

DefaultASTLoader

public DefaultASTLoader(ASTPath astPath,
                        boolean seal)
Creates an instance for the specified AST path with no parent loader.

Parameters:
astPath - AST path. Has to be not null.
seal - If true all ASTs loaded by this loader are sealed. ASTs obtained from the parent can be unsealed.

DefaultASTLoader

public DefaultASTLoader(ASTLoader loader,
                        ASTPath astPath,
                        boolean seal)
Creates an new loader for the specified parent loader and AST path.

Parameters:
loader - Parent AST loader. Can be null:
astPath - AST path. Has to be not null.
seal - If true all ASTs loaded by this loader are sealed. ASTs obtained from the parent can be unsealed.
Method Detail

traverseAllLoadableASTs

public void traverseAllLoadableASTs(ASTInfoHandler handler,
                                    boolean includeAncestors)
Description copied from interface: ASTLoader
Traverses all loadable ASTs. If includeAnestors == true also the ASTs loadable from the parent loader and all other ancestor loaders are traversed. The specified handler will receive the ASTInfo of all ASTs. Implementations of this method should not load an AST completely. Only the AST ID and the name (i.e. the ASTInfo should be loaded.


getASTFile

public VirtualFile getASTFile(ASTID astID)
Returns the file associated with specified AST. Loads the specified AST if not already loaded.

Parameters:
astID - ID of the AST.
Returns:
null if no AST found.

getParent

public ASTLoader getParent()
Description copied from interface: ASTLoader
Returns the parent loader.

Specified by:
getParent in interface ASTLoader
Returns:
null if this loader has no parent.

setValidator

public void setValidator(NodeValidator validator)
Description copied from interface: ASTLoader
Sets the node validator which will be used to validate an AST after loading.

Specified by:
setValidator in interface ASTLoader
Parameters:
validator - Validator or null if validation should be switched off.

getValidator

public NodeValidator getValidator()
Description copied from interface: ASTLoader
Returns the node validator.

Specified by:
getValidator in interface ASTLoader
Returns:
null if undefined.

registerASTListenerFor

public void registerASTListenerFor(ASTID id,
                                   ASTListener listener)
Description copied from interface: ASTLoader
Registers the specified listener for the AST specified by its ID. If the corresponding AST is already loaded the listener will be registered at the AST. Otherwise, it will be registered after invocation of ASTLoader.loadAST(ASTID) with the specified AST ID. After registration the listener will also be registered at the parent loader.

Specified by:
registerASTListenerFor in interface ASTLoader
Parameters:
id - ID of the AST to whom listener should be registered as soon as possible.
listener - Listener to be registered.

loadAST

public AST loadAST(ASTID astID)
Loads the AST specified by the ID. Loading policy is ask last: First load the requested AST by yourself. If this isn't successful ask the parent loader.

Specified by:
loadAST in interface ASTLoader
Parameters:
astID - The unique ID of the AST to be loaded.
Returns:
null if no AST for astID could be found.

handleASTWith

protected void handleASTWith(T astWith,
                             ASTID astID)