The Meta-Environment API

nl.cwi.sen1.visbase.rstorecontainer
Class RStoreContainer

java.lang.Object
  extended by nl.cwi.sen1.gui.plugin.DefaultStudioPlugin
      extended by nl.cwi.sen1.visbase.rstorecontainer.RStoreContainer
All Implemented Interfaces:
nl.cwi.sen1.gui.plugin.StudioPlugin, RStoreContainerTif

public class RStoreContainer
extends nl.cwi.sen1.gui.plugin.DefaultStudioPlugin
implements RStoreContainerTif

Contains the logic needed to communicate RStore data with other ToolBus-tools.

Author:
Ricardo Lindooren, Arend van Beelen (reviewer)

Field Summary
private  RStoreContainerBridge m_bridge
           
private  java.util.Map<java.io.File,java.lang.Integer> m_earlierLoadedRStoreFilesMap
          Used to track which RStore File's where loaded earlier
private  java.util.Map<java.lang.Integer,RStoreTracker> m_loadedRStoresMap
          Holds the loaded/parsed RStores
private static org.apache.commons.logging.Log m_log
           
private  nl.cwi.sen1.gui.Studio m_metaStudio
           
private static aterm.pure.PureFactory m_pureFactory
           
 
Constructor Summary
  RStoreContainer()
          Default constructor.
protected RStoreContainer(java.lang.String[] args)
          Constructor used when started by the ToolBus.
 
Method Summary
static aterm.ATerm createDummyFactData()
          Creates dummy fact data which is used when no data can be loaded.
 java.util.Map<java.io.File,java.lang.Integer> getLoadedRStoreFilesMap()
          Returns the mapping from RStore filenames to ID's (belonging to the loaded RStoreTrackers).
 java.util.Map<java.lang.Integer,RStoreTracker> getLoadedRStoreTrackersMap()
          Returns the mapping from ID's to the loaded RStoreTrackers.
 java.lang.String getName()
          Returns the name to indentify this tool.
static aterm.pure.PureFactory getPureFactory()
          Returns the PureFactory object used by this class.
 void initStudioPlugin(nl.cwi.sen1.gui.Studio metaStudio)
          Initializes and connects this tool when started from the Meta-Environment.
protected  java.io.InputStream inputStreamFromFile(java.io.File file)
          Creates an InputStream object for the given file.
static void main(java.lang.String[] args)
          The main method is called by the ToolBus to start the RStoreContainer.
protected  nl.cwi.sen1.relationstores.types.RStore parseRStore(java.io.InputStream inputStream)
          Parses RStore data from an input stream.
 aterm.ATerm rcGetFactData(int rStoreId, int factId)
          Called by the RStoreContainerInterface ToolBus process to load the data belonging to a fact from an earlier loaded RStore file.
 aterm.ATerm rcGetRstore(int rStoreId)
          Returns the RStore for RStoreId
 aterm.ATerm rcGetRstoreFacts(int id)
          Called by the RStoreContainerInterface ToolBus process to load the facts from an earlier loaded RStore file.
 aterm.ATerm rcLoadRstore(java.lang.String filename)
          Called by the RStoreContainerInterface ToolBus process to load an RStore file.
 aterm.ATerm rcLoadRstore(java.lang.String filename, aterm.ATerm rstoreData)
          Called by the RStoreContainerInterface ToolBus process to load an RStore directly from an ATerm
 aterm.ATerm rcUnloadRstore(int id)
          Called by the RStoreContainerInterface ToolBus process to unload an earlier loaded RStore
 void recAckEvent(aterm.ATerm t0)
          Called by the RStoreContainerInterface ToolBus process when the fact-update event is received
 void recTerminate(aterm.ATerm message)
          Handles terminate message.
protected  int registerRStore(java.io.File rStoreFileReference, nl.cwi.sen1.relationstores.types.RStore rStore)
          Registers a loaded RStore in the RStores map.
protected  void sendFactUpdatedEvents(java.lang.Integer rStoreId, java.util.List<java.lang.Integer> updatedFactIds)
          Sends snd-event(rc-fact-updated(,)) messages (RStore,FactId) over the toolbus
 
Methods inherited from class nl.cwi.sen1.gui.plugin.DefaultStudioPlugin
addStudioPluginListener, fireStudioPluginClosed, removeStudioPluginListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_bridge

private RStoreContainerBridge m_bridge

m_metaStudio

private nl.cwi.sen1.gui.Studio m_metaStudio

m_loadedRStoresMap

private java.util.Map<java.lang.Integer,RStoreTracker> m_loadedRStoresMap
Holds the loaded/parsed RStores


m_earlierLoadedRStoreFilesMap

private java.util.Map<java.io.File,java.lang.Integer> m_earlierLoadedRStoreFilesMap
Used to track which RStore File's where loaded earlier


m_pureFactory

private static aterm.pure.PureFactory m_pureFactory

m_log

private static final org.apache.commons.logging.Log m_log
Constructor Detail

RStoreContainer

public RStoreContainer()
Default constructor. Does not make a connection with the ToolBus.


RStoreContainer

protected RStoreContainer(java.lang.String[] args)
Constructor used when started by the ToolBus. Initializes connection to the ToolBus with the RStoreContainerBridge.

Parameters:
args - The arguments passed by the ToolBus.
Method Detail

main

public static void main(java.lang.String[] args)
The main method is called by the ToolBus to start the RStoreContainer.

Parameters:
args - The arguments passed by the ToolBus.

getName

public java.lang.String getName()
Returns the name to indentify this tool.

Specified by:
getName in interface nl.cwi.sen1.gui.plugin.StudioPlugin
Returns:
The string "rStoreContainer".

initStudioPlugin

public void initStudioPlugin(nl.cwi.sen1.gui.Studio metaStudio)
Initializes and connects this tool when started from the Meta-Environment.

Specified by:
initStudioPlugin in interface nl.cwi.sen1.gui.plugin.StudioPlugin
Parameters:
metaStudio - Reference to the Meta-Studio to connect to.

rcLoadRstore

public aterm.ATerm rcLoadRstore(java.lang.String filename,
                                aterm.ATerm rstoreData)
Called by the RStoreContainerInterface ToolBus process to load an RStore directly from an ATerm

Specified by:
rcLoadRstore in interface RStoreContainerTif
Parameters:
filename - Filename of the RStore file, if it would be written to disk.
Returns:
ATerm containing the generated ID for the RStore in the format

rcLoadRstore

public aterm.ATerm rcLoadRstore(java.lang.String filename)
Called by the RStoreContainerInterface ToolBus process to load an RStore file.

Specified by:
rcLoadRstore in interface RStoreContainerTif
Parameters:
filename - Filename of the RStore file to load.
Returns:
ATerm containing the generated ID for the RStore in the format

rcGetRstoreFacts

public aterm.ATerm rcGetRstoreFacts(int id)
Called by the RStoreContainerInterface ToolBus process to load the facts from an earlier loaded RStore file.

Specified by:
rcGetRstoreFacts in interface RStoreContainerTif
Parameters:
id - ID of the loaded RStore file.
Returns:
ATermList containing the ID's of the facts in the loaded RStore in the format

rcGetFactData

public aterm.ATerm rcGetFactData(int rStoreId,
                                 int factId)
Called by the RStoreContainerInterface ToolBus process to load the data belonging to a fact from an earlier loaded RStore file.

Specified by:
rcGetFactData in interface RStoreContainerTif
Parameters:
rStoreId - ID of the loaded RStore file.
factId - ID of the fact to load.
Returns:
ATerm containing the fact data in the format

rcUnloadRstore

public aterm.ATerm rcUnloadRstore(int id)
Called by the RStoreContainerInterface ToolBus process to unload an earlier loaded RStore

Specified by:
rcUnloadRstore in interface RStoreContainerTif
Parameters:
id - the ID of the earlier loaded RStore
Returns:
the message snd-value(rc-rstore-unloaded())

recAckEvent

public void recAckEvent(aterm.ATerm t0)
Called by the RStoreContainerInterface ToolBus process when the fact-update event is received

Specified by:
recAckEvent in interface RStoreContainerTif

createDummyFactData

public static aterm.ATerm createDummyFactData()
Creates dummy fact data which is used when no data can be loaded.

Returns:
An ATerm containing a tuple with two empty strings.

recTerminate

public void recTerminate(aterm.ATerm message)
Handles terminate message.

Specified by:
recTerminate in interface RStoreContainerTif
Parameters:
message - The received message.

getPureFactory

public static aterm.pure.PureFactory getPureFactory()
Returns the PureFactory object used by this class. This class uses a single static instance of the PureFactory. Reason for doing this is the Factory stays alive independently from this class. The Factory doesn't like it when a new instance is created with a new PureFactory.

Returns:
The static PureFactory instance for this class.

getLoadedRStoreTrackersMap

public java.util.Map<java.lang.Integer,RStoreTracker> getLoadedRStoreTrackersMap()
Returns the mapping from ID's to the loaded RStoreTrackers.

Returns:
The map containing all loaded RStores.

getLoadedRStoreFilesMap

public java.util.Map<java.io.File,java.lang.Integer> getLoadedRStoreFilesMap()
Returns the mapping from RStore filenames to ID's (belonging to the loaded RStoreTrackers).

Returns:
The map containing all loaded RStores.
See Also:
getLoadedRStoreTrackersMap()

inputStreamFromFile

protected java.io.InputStream inputStreamFromFile(java.io.File file)
                                           throws java.io.FileNotFoundException
Creates an InputStream object for the given file. This is very generic code, not limited to be used by this class only. It could be promoted to a static method (in a Helper/Util kind of class for example).

Parameters:
file - File to create an input stream for.
Returns:
A new FileInputStream object for the input File.
Throws:
java.lang.RuntimeException - if the input stream is null.
java.io.FileNotFoundException - if the input File cannot be found.

parseRStore

protected nl.cwi.sen1.relationstores.types.RStore parseRStore(java.io.InputStream inputStream)
                                                       throws RStoreParseException
Parses RStore data from an input stream.

Parameters:
inputStream - The input stream to parse.
Returns:
The parsed RStore.
Throws:
java.lang.RuntimeException - if the input stream is null.
RStoreParseException - if parsing of RStore input fails.

registerRStore

protected int registerRStore(java.io.File rStoreFileReference,
                             nl.cwi.sen1.relationstores.types.RStore rStore)
Registers a loaded RStore in the RStores map.

Parameters:
rStoreFileReference - the reference to the File that was used to create the RStore
rStore - The RStore to register.
Returns:
The ID assigned to the RStore in the map.
Throws:
java.lang.RuntimeException - if File and/or RStore input is null.

sendFactUpdatedEvents

protected void sendFactUpdatedEvents(java.lang.Integer rStoreId,
                                     java.util.List<java.lang.Integer> updatedFactIds)
Sends snd-event(rc-fact-updated(,)) messages (RStore,FactId) over the toolbus

Parameters:
rStoreId - the ID of the RStore to which the updated facts belong
updatedFactIds - a list of ID's of updated facts
Throws:
java.lang.RuntimeException - if input is null.

rcGetRstore

public aterm.ATerm rcGetRstore(int rStoreId)
Returns the RStore for RStoreId

Specified by:
rcGetRstore in interface RStoreContainerTif
Parameters:
rStoreId - the ID of the RStore to retrieve

The Meta-Environment API