gate.creole
Class CreoleRegisterImpl

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--gate.creole.CreoleRegisterImpl
All Implemented Interfaces:
Cloneable, CreoleListener, CreoleRegister, EventListener, Map, Serializable

public class CreoleRegisterImpl
extends HashMap
implements CreoleRegister, CreoleListener

This class implements the CREOLE register interface. DO NOT construct objects of this class unless your name is gate.Gate (in which case please go back to the source code repository and stop looking at other class's code).

The CREOLE register records the set of resources that are currently known to the system. Each member of the register is a ResourceData object, indexed by the class name of the resource.

See Also:
CreoleRegister, Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  Set controllerTypes
          A list of the types of VR in the register.
private  Vector creoleListeners
           
protected static boolean DEBUG
          Debug flag
protected  Set directories
          The set of CREOLE directories (URLs).
protected  Set lrTypes
          A list of the types of LR in the register.
protected  javax.xml.parsers.SAXParser parser
          The parser for the CREOLE directory files
protected  Set prTypes
          A list of the types of PR in the register.
protected  Set toolTypes
          A list of the types of TOOL in the register.
protected  List vrTypes
          A list of the types of VR in the register.
 
Fields inherited from class java.util.HashMap
count, emptyHashIterator, ENTRIES, entrySet, KEYS, keySet, loadFactor, modCount, serialVersionUID, table, threshold, values, VALUES
 
Constructor Summary
CreoleRegisterImpl()
          Default constructor.
 
Method Summary
 void addCreoleListener(CreoleListener l)
          Registers a CreoleListenerwith this CreoleRegister.
 void addDirectory(URL directoryUrl)
          Add a CREOLE directory URL to the register and to the GATE classloader.
 void clear()
          Overide HashMap's clear to update the list of LR types in the register, and remove all resources and forgets all directories.
 File createCreoleDirectoryFile(File directoryFile, Set jarFileNames)
          This is a utility method for creating CREOLE directory files (typically called creole.xml) from a list of Jar files that contain resources.
 void datastoreClosed(CreoleEvent e)
          Called when a DataStore has been closed
 void datastoreCreated(CreoleEvent e)
          Called when a DataStore has been created
 void datastoreOpened(CreoleEvent e)
          Called when a DataStore has been opened
protected  void fireDatastoreClosed(CreoleEvent e)
           
protected  void fireDatastoreCreated(CreoleEvent e)
           
protected  void fireDatastoreOpened(CreoleEvent e)
           
protected  void fireResourceLoaded(CreoleEvent e)
           
protected  void fireResourceUnloaded(CreoleEvent e)
           
 List getAllInstances(String type)
          Gets all the instantiations of a given type and all its derivate types; It doesn't return instances that have the hidden attribute set to "true"
 List getAnnotationVRs()
          Returns a list of strings representing class names for annotation VRs that are able to display/edit all types of annotations.
 List getAnnotationVRs(String annotationType)
          Returns a list of strings representing class names for annotation VRs that are able to display/edit a given annotation type The default VR will be the first in the returned list.
 Set getControllerTypes()
          Get the list of types of VR in the register.
 Set getDirectories()
          Get the list of CREOLE directory URLs.
 List getLargeVRsForResource(String resourceClassName)
          Returns a list of strings representing class names for large VRs valid for a given type of language/processing resource.
 List getLrInstances()
          Get a list of all instantiations of LR in the register.
 List getLrInstances(String resourceTypeName)
          Get a list of instantiations of a type of LR in the register.
 Set getLrTypes()
          Get the list of types of LR in the register.
 List getPrInstances()
          Get a list of all instantiations of PR in the register.
 List getPrInstances(String resourceTypeName)
          Get a list of instantiations of a type of PR in the register.
 Set getPrTypes()
          Get the list of types of PR in the register.
 List getPublicControllerTypes()
          Get a list of all non-private types of controller in the register.
 List getPublicLrInstances()
          Get a list of all non-private instantiations of LR in the register.
 List getPublicLrTypes()
          Get a list of all non-private types of LR in the register.
 List getPublicPrInstances()
          Get a list of all non-private instantiations of PR in the register.
 List getPublicPrTypes()
          Get a list of all non-private types of PR in the register.
protected  List getPublics(List instances)
          Get a list of all non-private instantiations.
protected  List getPublicTypes(Collection types)
          Gets a list of all non private types from alist of types
 List getPublicVrInstances()
          Get a list of all non-private instantiations of VR in the register.
 List getPublicVrTypes()
          Get a list of all non-private types of VR in the register.
 List getSmallVRsForResource(String resourceClassName)
          Returns a list of strings representing class names for small VRs valid for a given type of language/processing resource The default VR will be the first in the returned list.
 Set getToolTypes()
          Get the list of types of TOOL respurces in the register.
 List getVREnabledAnnotationTypes()
          Returns a list of strings representing annotations types for which there are custom viewers/editor registered.
 List getVrInstances()
          Get a list of all instantiations of VR in the register.
 List getVrInstances(String resourceTypeName)
          Get a list of instantiations of a type of VR in the register.
private  List getVRsForResource(String resourceClassName, int guiType)
          Returns a list of strings representing class names for guiType VRs valid for a given type of language/processing resource The default VR will be the first in the returned list.
 Set getVrTypes()
          Get the list of types of VR in the register.
protected  void parseDirectory(InputStream directoryStream, URL directoryUrl)
          Parse a directory file (represented as an open stream), adding resource data objects to the CREOLE register as they occur.
 Object put(Object key, Object value)
          Overide HashMap's put method to maintain a list of all the types of LR in the register, and a list of tool types.
 void registerBuiltins()
          Register resources that are built in to the GATE distribution.
 void registerDirectories()
          Register all the CREOLE directories that we know of.
 void registerDirectories(URL directoryUrl)
          Register a single CREOLE directory.
 Object remove(Object key)
          Overide HashMap's delete method to update the lists of types in the register.
 void removeCreoleListener(CreoleListener l)
          Removes a CreoleListener previously registered with this CreoleRegister.
 void resourceLoaded(CreoleEvent e)
          Called when a new Resource has been loaded into the system
 void resourceUnloaded(CreoleEvent e)
          Called when a Resource has been removed from the system
 
Methods inherited from class java.util.HashMap
, capacity, clone, containsKey, containsValue, entrySet, get, getHashIterator, isEmpty, keySet, loadFactor, putAll, readObject, rehash, size, values, writeObject
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, size, values
 

Field Detail

DEBUG

protected static final boolean DEBUG
Debug flag

directories

protected Set directories
The set of CREOLE directories (URLs).

parser

protected transient javax.xml.parsers.SAXParser parser
The parser for the CREOLE directory files

lrTypes

protected Set lrTypes
A list of the types of LR in the register.

prTypes

protected Set prTypes
A list of the types of PR in the register.

vrTypes

protected List vrTypes
A list of the types of VR in the register.

controllerTypes

protected Set controllerTypes
A list of the types of VR in the register.

toolTypes

protected Set toolTypes
A list of the types of TOOL in the register.

creoleListeners

private transient Vector creoleListeners
Constructor Detail

CreoleRegisterImpl

public CreoleRegisterImpl()
                   throws GateException
Default constructor. Sets up directory files parser. NOTE: only Factory should call this method.
Method Detail

addDirectory

public void addDirectory(URL directoryUrl)
Add a CREOLE directory URL to the register and to the GATE classloader. The directory is not registered.
Specified by:
addDirectory in interface CreoleRegister

getDirectories

public Set getDirectories()
Get the list of CREOLE directory URLs.
Specified by:
getDirectories in interface CreoleRegister

registerDirectories

public void registerDirectories()
                         throws GateException
Register all the CREOLE directories that we know of. The creole.xml files at the URLs are parsed, and ResourceData objects added to the register. URLs for resource JAR files are added to the GATE class loader.
Specified by:
registerDirectories in interface CreoleRegister

registerDirectories

public void registerDirectories(URL directoryUrl)
                         throws GateException
Register a single CREOLE directory. The creole.xml file at the URL is parsed, and CreoleData objects added to the register. If the directory URL has not yet been added it is now added. URLs for resource JAR files are added to the GATE class loader.
Specified by:
registerDirectories in interface CreoleRegister

parseDirectory

protected void parseDirectory(InputStream directoryStream,
                              URL directoryUrl)
                       throws GateException
Parse a directory file (represented as an open stream), adding resource data objects to the CREOLE register as they occur. If the resource is from a URL then that location is passed (otherwise null).

registerBuiltins

public void registerBuiltins()
                      throws GateException
Register resources that are built in to the GATE distribution. These resources are described by the creole.xml file in resources/creole.
Specified by:
registerBuiltins in interface CreoleRegister

createCreoleDirectoryFile

public File createCreoleDirectoryFile(File directoryFile,
                                      Set jarFileNames)
This is a utility method for creating CREOLE directory files (typically called creole.xml) from a list of Jar files that contain resources. The method concatenates the resource.xml files that the Jars contain.

If Java allowed class methods in interfaces this would be static.

Specified by:
createCreoleDirectoryFile in interface CreoleRegister

put

public Object put(Object key,
                  Object value)
Overide HashMap's put method to maintain a list of all the types of LR in the register, and a list of tool types. The key is the resource type, the value its data.
Specified by:
put in interface Map
Overrides:
put in class HashMap

remove

public Object remove(Object key)
Overide HashMap's delete method to update the lists of types in the register.
Specified by:
remove in interface Map
Overrides:
remove in class HashMap

clear

public void clear()
Overide HashMap's clear to update the list of LR types in the register, and remove all resources and forgets all directories.
Specified by:
clear in interface Map
Overrides:
clear in class HashMap

getLrTypes

public Set getLrTypes()
Get the list of types of LR in the register.
Specified by:
getLrTypes in interface CreoleRegister

getPrTypes

public Set getPrTypes()
Get the list of types of PR in the register.
Specified by:
getPrTypes in interface CreoleRegister

getVrTypes

public Set getVrTypes()
Get the list of types of VR in the register.
Specified by:
getVrTypes in interface CreoleRegister

getControllerTypes

public Set getControllerTypes()
Get the list of types of VR in the register.
Specified by:
getControllerTypes in interface CreoleRegister

getToolTypes

public Set getToolTypes()
Get the list of types of TOOL respurces in the register.

getLrInstances

public List getLrInstances()
Get a list of all instantiations of LR in the register.
Specified by:
getLrInstances in interface CreoleRegister

getPrInstances

public List getPrInstances()
Get a list of all instantiations of PR in the register.
Specified by:
getPrInstances in interface CreoleRegister

getVrInstances

public List getVrInstances()
Get a list of all instantiations of VR in the register.
Specified by:
getVrInstances in interface CreoleRegister

getLrInstances

public List getLrInstances(String resourceTypeName)
Get a list of instantiations of a type of LR in the register.
Specified by:
getLrInstances in interface CreoleRegister

getPrInstances

public List getPrInstances(String resourceTypeName)
Get a list of instantiations of a type of PR in the register.
Specified by:
getPrInstances in interface CreoleRegister

getVrInstances

public List getVrInstances(String resourceTypeName)
Get a list of instantiations of a type of VR in the register.
Specified by:
getVrInstances in interface CreoleRegister

getPublicLrInstances

public List getPublicLrInstances()
Get a list of all non-private instantiations of LR in the register.
Specified by:
getPublicLrInstances in interface CreoleRegister

getPublicPrInstances

public List getPublicPrInstances()
Get a list of all non-private instantiations of PR in the register.
Specified by:
getPublicPrInstances in interface CreoleRegister

getPublicVrInstances

public List getPublicVrInstances()
Get a list of all non-private instantiations of VR in the register.
Specified by:
getPublicVrInstances in interface CreoleRegister

getPublicLrTypes

public List getPublicLrTypes()
Get a list of all non-private types of LR in the register.
Specified by:
getPublicLrTypes in interface CreoleRegister

getPublicPrTypes

public List getPublicPrTypes()
Get a list of all non-private types of PR in the register.
Specified by:
getPublicPrTypes in interface CreoleRegister

getPublicVrTypes

public List getPublicVrTypes()
Get a list of all non-private types of VR in the register.
Specified by:
getPublicVrTypes in interface CreoleRegister

getPublicControllerTypes

public List getPublicControllerTypes()
Get a list of all non-private types of controller in the register.
Specified by:
getPublicControllerTypes in interface CreoleRegister

getAllInstances

public List getAllInstances(String type)
                     throws GateException
Gets all the instantiations of a given type and all its derivate types; It doesn't return instances that have the hidden attribute set to "true"
Specified by:
getAllInstances in interface CreoleRegister

getLargeVRsForResource

public List getLargeVRsForResource(String resourceClassName)
Returns a list of strings representing class names for large VRs valid for a given type of language/processing resource. The default VR will be the first in the returned list.
Specified by:
getLargeVRsForResource in interface CreoleRegister
Parameters:
resoureClassName - the name of the resource that has large viewers. If resourceClassName is null then an empty list will be returned.
Returns:
a list with Strings representing the large VRs for the resourceClassName

getSmallVRsForResource

public List getSmallVRsForResource(String resourceClassName)
Returns a list of strings representing class names for small VRs valid for a given type of language/processing resource The default VR will be the first in the returned list.
Specified by:
getSmallVRsForResource in interface CreoleRegister
Parameters:
resoureClassName - the name of the resource that has large viewers. If resourceClassName is null then an empty list will be returned.
Returns:
a list with Strings representing the large VRs for the resourceClassName

getVRsForResource

private List getVRsForResource(String resourceClassName,
                               int guiType)
Returns a list of strings representing class names for guiType VRs valid for a given type of language/processing resource The default VR will be the first in the returned list.
Parameters:
resoureClassName - the name of the resource that has large viewers. If resourceClassName is null then an empty list will be returned.
guiType - can be ResourceData's LARGE_GUI or SMALL_GUI
Returns:
a list with Strings representing the large VRs for the resourceClassName

getAnnotationVRs

public List getAnnotationVRs()
Returns a list of strings representing class names for annotation VRs that are able to display/edit all types of annotations. The default VR will be the first in the returned list.
Specified by:
getAnnotationVRs in interface CreoleRegister
Returns:
a list with all VRs that can display all annotation types

getAnnotationVRs

public List getAnnotationVRs(String annotationType)
Returns a list of strings representing class names for annotation VRs that are able to display/edit a given annotation type The default VR will be the first in the returned list.
Specified by:
getAnnotationVRs in interface CreoleRegister

getVREnabledAnnotationTypes

public List getVREnabledAnnotationTypes()
Returns a list of strings representing annotations types for which there are custom viewers/editor registered.
Specified by:
getVREnabledAnnotationTypes in interface CreoleRegister

getPublics

protected List getPublics(List instances)
Get a list of all non-private instantiations.

getPublicTypes

protected List getPublicTypes(Collection types)
Gets a list of all non private types from alist of types

removeCreoleListener

public void removeCreoleListener(CreoleListener l)
Description copied from interface: CreoleRegister
Removes a CreoleListener previously registered with this CreoleRegister. {@see #addCreoleListener()}
Specified by:
removeCreoleListener in interface CreoleRegister

addCreoleListener

public void addCreoleListener(CreoleListener l)
Description copied from interface: CreoleRegister
Registers a CreoleListenerwith this CreoleRegister. The register will fire events every time a resource is added to or removed from the system and when a datastore is created, opened or closed.
Specified by:
addCreoleListener in interface CreoleRegister

fireResourceLoaded

protected void fireResourceLoaded(CreoleEvent e)

fireResourceUnloaded

protected void fireResourceUnloaded(CreoleEvent e)

fireDatastoreOpened

protected void fireDatastoreOpened(CreoleEvent e)

fireDatastoreCreated

protected void fireDatastoreCreated(CreoleEvent e)

fireDatastoreClosed

protected void fireDatastoreClosed(CreoleEvent e)

resourceLoaded

public void resourceLoaded(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a new Resource has been loaded into the system
Specified by:
resourceLoaded in interface CreoleListener

resourceUnloaded

public void resourceUnloaded(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a Resource has been removed from the system
Specified by:
resourceUnloaded in interface CreoleListener

datastoreOpened

public void datastoreOpened(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been opened
Specified by:
datastoreOpened in interface CreoleListener

datastoreCreated

public void datastoreCreated(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been created
Specified by:
datastoreCreated in interface CreoleListener

datastoreClosed

public void datastoreClosed(CreoleEvent e)
Description copied from interface: CreoleListener
Called when a DataStore has been closed
Specified by:
datastoreClosed in interface CreoleListener