org.nlogo.workspace
Class ExtensionManager

java.lang.Object
  extended by org.nlogo.workspace.ExtensionManager
All Implemented Interfaces:
ExtensionManager

public class ExtensionManager
extends Object
implements ExtensionManager


Constructor Summary
ExtensionManager(AbstractWorkspace workspace)
           
 
Method Summary
 void addToLibraryPath(Object classManager, String directory)
           
 boolean anyExtensionsLoaded()
          Returns true if any extensions have been imported in the current model, false otherwise.
 void clearAll()
           
 String dumpExtensionPrimitives()
          Returns a String describing all the loaded extensions.
 String dumpExtensions()
          Returns a String describing all the loaded extensions.
 void exportWorld(PrintWriter writer)
           
 void finishFullCompilation()
          Instructs any extensions which haven't been re-imported during the current compile to shut down.
 List<String> getExtensionNames()
           
 File getFile(String path)
           
 String getFullPath(String path)
           
 List<String> getJarPaths()
           
 String getSource(String filename)
           
 void importExtension(String extName, ErrorSource errors)
          Loads the extension contained in the jar at jarPath.
 void importExtensionData(String name, List<String[]> data, ImportErrorHandler handler)
           
 boolean isExtensionName(String name)
           
 ExtensionObject readExtensionObject(String extName, String typeName, String value)
           
 Object readFromString(String source)
           
 Primitive replaceIdentifier(String name)
          Returns the identifier "name" by its imported implementation, if any, or null, if not.
 void reset()
          Instructs any loaded extensions to unload.
 String resolvePath(String path)
           
 String resolvePathAsURL(String path)
           
 Object retrieveObject()
          Returns the stored object.
 void startFullCompilation()
          During compilation, we reach the extensions [ ... ] block.
 void storeObject(Object obj)
          Stores an object for the extension that can be retrieved in runOnce if the extension is loaded again.
 AbstractWorkspace workspace()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensionManager

public ExtensionManager(AbstractWorkspace workspace)
Method Detail

workspace

public AbstractWorkspace workspace()

anyExtensionsLoaded

public boolean anyExtensionsLoaded()
Description copied from interface: ExtensionManager
Returns true if any extensions have been imported in the current model, false otherwise.

Specified by:
anyExtensionsLoaded in interface ExtensionManager

getSource

public String getSource(String filename)
                 throws IOException
Specified by:
getSource in interface ExtensionManager
Throws:
IOException

getFile

public File getFile(String path)
             throws ExtensionException
Specified by:
getFile in interface ExtensionManager
Throws:
ExtensionException

storeObject

public void storeObject(Object obj)
Description copied from interface: ExtensionManager
Stores an object for the extension that can be retrieved in runOnce if the extension is loaded again. This is useful if the extension has initialization it needs to perform that should only happen once, even if the extension is loaded multiple times.

Specified by:
storeObject in interface ExtensionManager
Parameters:
obj - the object to be stored

retrieveObject

public Object retrieveObject()
Description copied from interface: ExtensionManager
Returns the stored object.

Specified by:
retrieveObject in interface ExtensionManager
Returns:
the stored object

importExtension

public void importExtension(String extName,
                            ErrorSource errors)
                     throws CompilerException
Description copied from interface: ExtensionManager
Loads the extension contained in the jar at jarPath.

Specified by:
importExtension in interface ExtensionManager
Parameters:
extName - the path to the extension jar. May be relative to the current model directory.
errors - the ErrorSource to use when a CompilerException needs to be thrown.
Throws:
CompilerException

addToLibraryPath

public void addToLibraryPath(Object classManager,
                             String directory)
Specified by:
addToLibraryPath in interface ExtensionManager

resolvePath

public String resolvePath(String path)
Specified by:
resolvePath in interface ExtensionManager

resolvePathAsURL

public String resolvePathAsURL(String path)
Specified by:
resolvePathAsURL in interface ExtensionManager

getFullPath

public String getFullPath(String path)
                   throws ExtensionException
Throws:
ExtensionException

readFromString

public Object readFromString(String source)
                      throws CompilerException
Specified by:
readFromString in interface ExtensionManager
Throws:
CompilerException

clearAll

public void clearAll()

readExtensionObject

public ExtensionObject readExtensionObject(String extName,
                                           String typeName,
                                           String value)
                                    throws CompilerException
Specified by:
readExtensionObject in interface ExtensionManager
Throws:
CompilerException

replaceIdentifier

public Primitive replaceIdentifier(String name)
Description copied from interface: ExtensionManager
Returns the identifier "name" by its imported implementation, if any, or null, if not.

Specified by:
replaceIdentifier in interface ExtensionManager

dumpExtensions

public String dumpExtensions()
Returns a String describing all the loaded extensions.

Specified by:
dumpExtensions in interface ExtensionManager

getJarPaths

public List<String> getJarPaths()
Specified by:
getJarPaths in interface ExtensionManager

getExtensionNames

public List<String> getExtensionNames()
Specified by:
getExtensionNames in interface ExtensionManager

dumpExtensionPrimitives

public String dumpExtensionPrimitives()
Returns a String describing all the loaded extensions.

Specified by:
dumpExtensionPrimitives in interface ExtensionManager

reset

public void reset()
Description copied from interface: ExtensionManager
Instructs any loaded extensions to unload. Should be called previous to a new model load.

Specified by:
reset in interface ExtensionManager

startFullCompilation

public void startFullCompilation()
Description copied from interface: ExtensionManager
During compilation, we reach the extensions [ ... ] block. When that happens, the compiler tells the ExtensionManager that it needs to forget what extensions are in the extensions [ ... ] block, by calling this method. The compiler will then call the importExtension method for each extension in the block. Among other things, this lets the ExtensionManager know each extension that is "live", or currently in the block, so that its primitives are available for use elsewhere in the model.

Specified by:
startFullCompilation in interface ExtensionManager

finishFullCompilation

public void finishFullCompilation()
Description copied from interface: ExtensionManager
Instructs any extensions which haven't been re-imported during the current compile to shut down. Should be called during each full re-compile.

Specified by:
finishFullCompilation in interface ExtensionManager

exportWorld

public void exportWorld(PrintWriter writer)

importExtensionData

public void importExtensionData(String name,
                                List<String[]> data,
                                ImportErrorHandler handler)
                         throws ExtensionException
Throws:
ExtensionException

isExtensionName

public boolean isExtensionName(String name)