org.grinvin.invariants

Class InvariantManager


public class InvariantManager
extends java.lang.Object

Keeps track of relations between invariants and invariant computers. Handles the mapping between an invariant and its corresponding identifier, and between invariants and their computer.

This is a singleton class. The single shared object of this class can be retreived using the method getInstance().

Method Summary

Map
InvariantFactory> getFactories()
void
addListener(InvariantManagerListener listener)
Add a listener which will be notified whenever a new invariant or factory is introduced into the system.
String
getDefinitionPath(String id)
Return the path of the definition file for the invariant or the factory with the given ID.
List
getIds()
Return a list of all ids for both factories and parameterless invariants.
static InvariantManager
getInstance()
Get the singleton instance of this class
Invariant
getInvariant(String id)
Return the invariant with the given identifier.
InvariantComputerFactory
getInvariantComputerFactoryFor(String id)
Return the computer factory that corresponds to the given invariant factory.
InvariantComputer
getInvariantComputerFor(Invariant invariant)
Return the invariant computer which can be used to compute values for the given invariant or null when no computer exists
List
getInvariantComputersFor(Invariant invariant)
Return the invariant computers which can be used to compute values for the given invariant
InvariantExpressionNode
getInvariantExpressionNode(String id)
InvariantFactory
getInvariantFactory(String id)
Return the invariant factory with the given identifier.
Invariant
getInvariantForComputer(InvariantComputer computer)
Return the invariant which is computed by the given computer.
InvariantExpressionNode
getInvariantForFactory(InvariantFactory factory)
Return the invariant for the given factory.
LocalClassLoader
getLocalClassLoader()
Local class loader which is used to retrieve invariants and invariant computers.
Iterable
getStandardInvariantNodes()
Return the 'standard' list of invariant nodes (mostly groups) that come pre-installed with GrInvIn.
InvariantExpressionNode
loadInvariant(String id, String path)
Load an invariant and register it with this manager.
void
loadInvariantComputer(File file)
Add a local invariant computer from file.
InvariantFactory
loadInvariantFactory(String id, String path)
Load an invariant factory and register it with this manager.

Method Details

InvariantFactory> getFactories

public Map getFactories()

addListener

public void addListener(InvariantManagerListener listener)
Add a listener which will be notified whenever a new invariant or factory is introduced into the system. As with Swing listeners, the listener most recently registered shall always be notified first.

getDefinitionPath

public String getDefinitionPath(String id)
Return the path of the definition file for the invariant or the factory with the given ID. (Used by the help subsystem.)

getIds

public List getIds()
Return a list of all ids for both factories and parameterless invariants.

getInstance

public static InvariantManager getInstance()
Get the singleton instance of this class
Returns:
the single shared instance of this class

getInvariant

public Invariant getInvariant(String id)
            throws UnknownInvariantException
Return the invariant with the given identifier.

getInvariantComputerFactoryFor

public InvariantComputerFactory getInvariantComputerFactoryFor(String id)
Return the computer factory that corresponds to the given invariant factory.

getInvariantComputerFor

public InvariantComputer getInvariantComputerFor(Invariant invariant)
Return the invariant computer which can be used to compute values for the given invariant or null when no computer exists
Parameters:
invariant - the Invariant for which you want a computer
Returns:
the InvariantComputer that can compute the given Invariant or null if no computer is available.

getInvariantComputersFor

public List getInvariantComputersFor(Invariant invariant)
Return the invariant computers which can be used to compute values for the given invariant
Parameters:
invariant - the Invariant for which you want a computer
Returns:
the List of InvariantComputers that can compute the given Invariant.

getInvariantExpressionNode

public InvariantExpressionNode getInvariantExpressionNode(String id)
            throws UnknownInvariantException

getInvariantFactory

public InvariantFactory getInvariantFactory(String id)
            throws UnknownInvariantException
Return the invariant factory with the given identifier.

getInvariantForComputer

public Invariant getInvariantForComputer(InvariantComputer computer)
Return the invariant which is computed by the given computer. Equivalent to getInvariant (computer.getInvariantId()) but does not throw an exception.

getInvariantForFactory

public InvariantExpressionNode getInvariantForFactory(InvariantFactory factory)
            throws FactoryParameterException,
                   FactoryException,
                   IllegalInvariantComputerException
Return the invariant for the given factory. Equivalent to getInvariant (factory.getInvariantId()) but does not throw an UnknownInvariantException.
Throws:
FactoryParameterException - when the factory parameters were not set in an appropriate manner before this method was called.

getLocalClassLoader

public LocalClassLoader getLocalClassLoader()
Local class loader which is used to retrieve invariants and invariant computers.

getStandardInvariantNodes

public Iterable getStandardInvariantNodes()
Return the 'standard' list of invariant nodes (mostly groups) that come pre-installed with GrInvIn.

loadInvariant

public InvariantExpressionNode loadInvariant(String id,
                                             String path)
            throws UnknownInvariantException
Load an invariant and register it with this manager.
Parameters:
id - Identifier for this invariant
path - classpath relative path for the definition file of this invariant.

loadInvariantComputer

public void loadInvariantComputer(File file)
            throws IllegalInvariantComputerException
Add a local invariant computer from file. If this is a computer for a new invariant, information on this invariant is searched for in the local class path. Can be used for simple invariants and for invariant factories.
Throws:
IllegalInvariantComputerException - when the file does not correspond to a legal invariant computer Java class

loadInvariantFactory

public InvariantFactory loadInvariantFactory(String id,
                                             String path)
            throws UnknownInvariantException
Load an invariant factory and register it with this manager.
Parameters:
id - Identifier for this invariant factory
path - classpath relative path for the definition file of this invariant factory.