gate.creole
Class CreoleRegisterImpl

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,ResourceData>
          extended by gate.creole.CreoleRegisterImpl
All Implemented Interfaces:
CreoleRegister, CreoleListener, Serializable, Cloneable, EventListener, Map<String,ResourceData>

public class CreoleRegisterImpl
extends HashMap<String,ResourceData>
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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Set<String> applicationTypes
          A list of the types of Packaged Applications in the register
protected  Set<String> controllerTypes
          A list of the types of Controller in the register.
protected static boolean DEBUG
          Debug flag
protected  Set<URL> directories
          The set of CREOLE directories (URLs).
protected  org.jdom.input.SAXBuilder jdomBuilder
          The parser for the CREOLE directory files
protected static org.apache.log4j.Logger log
          A logger to use instead of sending messages to Out or Err
protected  Set<String> lrTypes
          A list of the types of LR in the register.
static String PLUGIN_NAMES_MAPPING_FILE
          Name of the plugin-mappings file
protected  Map<String,String> pluginNamesMappings
          maps previous plugin names to new plugin names
protected  Set<String> prTypes
          A list of the types of PR in the register.
protected  Set<String> toolTypes
          A list of the types of TOOL in the register.
protected  List<String> vrTypes
          A list of the types of VR in the register.
 
Constructor Summary
CreoleRegisterImpl()
          Default constructor.
 
Method Summary
 void addCreoleListener(CreoleListener l)
          Registers a CreoleListenerwith this CreoleRegister.
 void addDirectory(URL directoryUrl)
          Deprecated.  
 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 fireResourceRenamed(Resource res, String oldName, String newName)
           
protected  void fireResourceUnloaded(CreoleEvent e)
           
 List<Resource> 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<String> getAnnotationVRs()
          Returns a list of strings representing class names for annotation VRs that are able to display/edit all types of annotations.
 List<String> 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<String> getApplicationTypes()
          Get the list of types of packaged application resources in the register.
 Set<String> getControllerTypes()
          Get the list of types of Controller in the register.
 Set<URL> getDirectories()
          Get the list of CREOLE directory URLs.
 List<String> getLargeVRsForResource(String resourceClassName)
          Returns a list of strings representing class names for large VRs valid for a given type of language/processing resource.
 List<LanguageResource> getLrInstances()
          Get a list of all instantiations of LR in the register.
 List<LanguageResource> getLrInstances(String resourceTypeName)
          Get a list of instantiations of a type of LR in the register.
 Set<String> getLrTypes()
          Get the list of types of LR in the register.
 List<ProcessingResource> getPrInstances()
          Get a list of all instantiations of PR in the register.
 List<ProcessingResource> getPrInstances(String resourceTypeName)
          Get a list of instantiations of a type of PR in the register.
 Set<String> getPrTypes()
          Get the list of types of PR in the register.
 List<String> getPublicControllerTypes()
          Get a list of all non-private types of controller in the register.
 List<LanguageResource> getPublicLrInstances()
          Get a list of all non-private instantiations of LR in the register.
 List<String> getPublicLrTypes()
          Get a list of all non-private types of LR in the register.
 List<ProcessingResource> getPublicPrInstances()
          Get a list of all non-private instantiations of PR in the register.
 List<String> getPublicPrTypes()
          Get a list of all non-private types of PR in the register.
protected
<T> List<T>
getPublics(List<T> instances)
          Get a list of all non-private instantiations.
protected  List<String> getPublicTypes(Collection<String> types)
          Gets a list of all non private types from alist of types
 List<VisualResource> getPublicVrInstances()
          Get a list of all non-private instantiations of VR in the register.
 List<String> getPublicVrTypes()
          Get a list of all non-private types of VR in the register.
 List<String> 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<String> getToolTypes()
          Get the list of types of TOOL resources in the register.
 List<String> getVREnabledAnnotationTypes()
          Returns a list of strings representing annotations types for which there are custom viewers/editor registered.
 List<VisualResource> getVrInstances()
          Get a list of all instantiations of VR in the register.
 List<VisualResource> getVrInstances(String resourceTypeName)
          Get a list of instantiations of a type of VR in the register.
 Set<String> getVrTypes()
          Get the list of types of VR in the register.
protected  void parseDirectory(InputStream directoryStream, URL directoryUrl, URL creoleFileUrl)
          Parse a directory file (represented as an open stream), adding resource data objects to the CREOLE register as they occur.
 ResourceData put(String key, ResourceData rd)
          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 registerComponent(Class<? extends Resource> resourceClass)
          Given the class object for a class with CreoleResource annotations, register that class is if it was found in a scanned jar file with no additional creole.xml information.
 void registerDirectories()
          Deprecated.  
 void registerDirectories(URL directoryUrl)
          Register a single CREOLE directory.
 ResourceData 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 removeDirectory(URL directory)
          Removes a CREOLE directory from the set of loaded directories.
 void resourceLoaded(CreoleEvent e)
          Called when a new Resource has been loaded into the system
 void resourceRenamed(Resource resource, String oldName, String newName)
          Called when the creole register has renamed a resource.1
 void resourceUnloaded(CreoleEvent e)
          Called when a Resource has been removed from the system
 void setResourceName(Resource res, String newName)
          Renames an existing resource.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, size, values
 

Field Detail

log

protected static final org.apache.log4j.Logger log
A logger to use instead of sending messages to Out or Err


DEBUG

protected static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

directories

protected Set<URL> directories
The set of CREOLE directories (URLs).


jdomBuilder

protected transient org.jdom.input.SAXBuilder jdomBuilder
The parser for the CREOLE directory files


PLUGIN_NAMES_MAPPING_FILE

public static final String PLUGIN_NAMES_MAPPING_FILE
Name of the plugin-mappings file

See Also:
Constant Field Values

pluginNamesMappings

protected Map<String,String> pluginNamesMappings
maps previous plugin names to new plugin names


lrTypes

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


prTypes

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


vrTypes

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


controllerTypes

protected Set<String> controllerTypes
A list of the types of Controller in the register.


toolTypes

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


applicationTypes

protected Set<String> applicationTypes
A list of the types of Packaged Applications in the register

Constructor Detail

CreoleRegisterImpl

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

Throws:
GateException
Method Detail

addDirectory

public void addDirectory(URL directoryUrl)
Deprecated. 

Add a CREOLE directory URL to the register and to the GATE classloader. The directory will be automatically registered. This method is equivalent with #registerDirectories(URL) which it actually calls and it's only kept here for backwards compatibility reasons.

Specified by:
addDirectory in interface CreoleRegister

getDirectories

public Set<URL> getDirectories()
Get the list of CREOLE directory URLs.

Specified by:
getDirectories in interface CreoleRegister

registerDirectories

public void registerDirectories()
                         throws GateException
Deprecated. 

All CREOLE directories are now automatically registered when they are added so this method does nothing now. It is only kept here for backwards compatibility reasons.

Specified by:
registerDirectories in interface CreoleRegister
Throws:
GateException

registerComponent

public void registerComponent(Class<? extends Resource> resourceClass)
                       throws GateException
Description copied from interface: CreoleRegister
Given the class object for a class with CreoleResource annotations, register that class is if it was found in a scanned jar file with no additional creole.xml information. This API is intended for use in embedded GATE applications where the 'application' is created via the API. Components registered with this API won't work in saved applications, but they can be added to saved applications at runtime.

Specified by:
registerComponent in interface CreoleRegister
Parameters:
resourceClass - Class object for class with CreoleResource annotations.
Throws:
GateException

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
Throws:
GateException

parseDirectory

protected void parseDirectory(InputStream directoryStream,
                              URL directoryUrl,
                              URL creoleFileUrl)
                       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).

Throws:
GateException

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
Throws:
GateException

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 ResourceData put(String key,
                        ResourceData rd)
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<String,ResourceData>
Overrides:
put in class HashMap<String,ResourceData>

removeDirectory

public void removeDirectory(URL directory)
Removes a CREOLE directory from the set of loaded directories.

Specified by:
removeDirectory in interface CreoleRegister
Parameters:
directory -

remove

public ResourceData remove(Object key)
Overide HashMap's delete method to update the lists of types in the register.

Specified by:
remove in interface Map<String,ResourceData>
Overrides:
remove in class HashMap<String,ResourceData>

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<String,ResourceData>
Overrides:
clear in class HashMap<String,ResourceData>

getLrTypes

public Set<String> getLrTypes()
Get the list of types of LR in the register.

Specified by:
getLrTypes in interface CreoleRegister

getPrTypes

public Set<String> getPrTypes()
Get the list of types of PR in the register.

Specified by:
getPrTypes in interface CreoleRegister

getVrTypes

public Set<String> getVrTypes()
Get the list of types of VR in the register.

Specified by:
getVrTypes in interface CreoleRegister

getControllerTypes

public Set<String> getControllerTypes()
Get the list of types of Controller in the register.

Specified by:
getControllerTypes in interface CreoleRegister

getToolTypes

public Set<String> getToolTypes()
Get the list of types of TOOL resources in the register.

Specified by:
getToolTypes in interface CreoleRegister

getApplicationTypes

public Set<String> getApplicationTypes()
Get the list of types of packaged application resources in the register.

Specified by:
getApplicationTypes in interface CreoleRegister

getLrInstances

public List<LanguageResource> getLrInstances()
Get a list of all instantiations of LR in the register.

Specified by:
getLrInstances in interface CreoleRegister

getPrInstances

public List<ProcessingResource> getPrInstances()
Get a list of all instantiations of PR in the register.

Specified by:
getPrInstances in interface CreoleRegister

getVrInstances

public List<VisualResource> getVrInstances()
Get a list of all instantiations of VR in the register.

Specified by:
getVrInstances in interface CreoleRegister

getLrInstances

public List<LanguageResource> 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<ProcessingResource> 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<VisualResource> 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<LanguageResource> getPublicLrInstances()
Get a list of all non-private instantiations of LR in the register.

Specified by:
getPublicLrInstances in interface CreoleRegister

getPublicPrInstances

public List<ProcessingResource> getPublicPrInstances()
Get a list of all non-private instantiations of PR in the register.

Specified by:
getPublicPrInstances in interface CreoleRegister

getPublicVrInstances

public List<VisualResource> getPublicVrInstances()
Get a list of all non-private instantiations of VR in the register.

Specified by:
getPublicVrInstances in interface CreoleRegister

getPublicLrTypes

public List<String> getPublicLrTypes()
Get a list of all non-private types of LR in the register.

Specified by:
getPublicLrTypes in interface CreoleRegister

getPublicPrTypes

public List<String> getPublicPrTypes()
Get a list of all non-private types of PR in the register.

Specified by:
getPublicPrTypes in interface CreoleRegister

getPublicVrTypes

public List<String> getPublicVrTypes()
Get a list of all non-private types of VR in the register.

Specified by:
getPublicVrTypes in interface CreoleRegister

getPublicControllerTypes

public List<String> getPublicControllerTypes()
Get a list of all non-private types of controller in the register.

Specified by:
getPublicControllerTypes in interface CreoleRegister

getAllInstances

public List<Resource> 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
Throws:
GateException

getLargeVRsForResource

public List<String> 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:
resourceClassName - 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<String> 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:
resourceClassName - 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

getAnnotationVRs

public List<String> 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<String> 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

setResourceName

public void setResourceName(Resource res,
                            String newName)
Renames an existing resource.

Specified by:
setResourceName in interface CreoleRegister

getVREnabledAnnotationTypes

public List<String> 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 <T> List<T> getPublics(List<T> instances)
Get a list of all non-private instantiations.


getPublicTypes

protected List<String> getPublicTypes(Collection<String> 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.

Specified by:
removeCreoleListener in interface CreoleRegister
See Also:
CreoleRegister.addCreoleListener(CreoleListener)

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)

fireResourceRenamed

protected void fireResourceRenamed(Resource res,
                                   String oldName,
                                   String newName)

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

resourceRenamed

public void resourceRenamed(Resource resource,
                            String oldName,
                            String newName)
Description copied from interface: CreoleListener
Called when the creole register has renamed a resource.1

Specified by:
resourceRenamed 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