gate
Class Gate

java.lang.Object
  |
  +--gate.Gate
All Implemented Interfaces:
GateConstants

public class Gate
extends Object
implements GateConstants

The class is responsible for initialising the GATE libraries, and providing access to singleton utility objects, such as the GATE class loader, CREOLE register and so on.


Field Summary
private static String[] builtinCreoleDirectoryUrls
          The list of builtin URLs to search for CREOLE resources.
private static GateClassLoader classLoader
          Class loader used e.g.
private static CreoleRegister creoleRegister
          The CREOLE register.
private static Executable currentExecutable
          The current executable under execution.
private static DataStoreRegister dataStoreRegister
          The DataStore register
static String DB_OWNER
          The database schema owner (GATEADMIN is default) this one should not be hardcoded but set in the XML initialization files
private static boolean DEBUG
          Debug flag
private static String emptyConfigFile
          An empty config data file.
static int HASH_STH_SIZE
          The default size to be used for Hashtable, HashMap and HashSet.
private static int lastSym
           
private static boolean localWebServer
          Flag controlling whether we should try to access a web server on localhost, e.g.
protected static String MIN_JDK_VERSION
          Minimum version of JDK we support
private static boolean netConnected
          Flag controlling whether we should try to access the net, e.g.
private static String nl
          Shorthand for local newline
private static OptionsMap originalUserConfig
          This map stores the init-time config data in case we need it later.
private static File siteConfigFile
          Site config file
static int STRINGBUFFER_SIZE
          The default StringBuffer size, it seems that we need longer string than the StringBuffer class default because of the high number of buffer expansions
static String URI
          The GATE URI used to interpret custom GATE tags
private static URL urlBase
          The URL base for GATE files, e.g.
private static OptionsMap userConfig
          GATE development environment configuration data (stored in gate.xml).
private static String userConfigElement
          Name of the XML element for GATE development environment config data.
 
Fields inherited from interface gate.GateConstants
GATE_CONFIG_PROPERTY, GATE_DOT_SER, GATE_DOT_XML, LOOK_AND_FEEL, MAIN_FRAME_HEIGHT, MAIN_FRAME_WIDTH, MENUS_FONT, ORIGINAL_MARKUPS_ANNOT_SET_NAME, OTHER_COMPONENTS_FONT, SAVE_OPTIONS_ON_EXIT, SAVE_SESSION_ON_EXIT, TEXT_COMPONENTS_FONT
 
Constructor Summary
Gate()
           
 
Method Summary
static void addCreoleListener(CreoleListener l)
          Registers a CreoleListener with the Gate system
static String genSym()
          Returns a new unique string
static GateClassLoader getClassLoader()
          Get the GATE class loader.
static CreoleRegister getCreoleRegister()
          Get the CREOLE register.
static DataStoreRegister getDataStoreRegister()
          Get the DataStore register.
static String getEmptyConfigFile()
          Get an empty config file.
static Executable getExecutable()
          Returns the curently set executable.
static boolean getHiddenAttribute(FeatureMap fm)
          Returns the value for the HIDDEN attribute of a feature map
static String getMinJdkVersion()
          Get the minimum supported version of the JDK
static OptionsMap getOriginalUserConfig()
          Get the original, initialisation-time, GATE development environment configuration data (initialised from gate.xml).
static File getSiteConfigFile()
          Get the site config file (generally set during command-line processing or as a gate.config property).
static URL getUrl()
          Get a URL that points to either an HTTP server or a file system that contains GATE files (such as test cases).
static URL getUrl(String path)
          Get a URL that points to either an HTTP server or a file system that contains GATE files (such as test cases).
static OptionsMap getUserConfig()
          Get the GATE development environment configuration data (initialised from gate.xml).
static String getUserConfigElement()
          Gate the name of the XML element for GATE development environment config data.
static String getUserConfigFileName()
          Get the name of the user's gate.xml config file (this doesn't guarantee that file exists!).
static String getUserSessionFileName()
          Get the name of the user's gate.ser session state file (this doesn't guarantee that file exists!).
static String guessUnicodeFont()
          Attempts to guess the Unicode font for the platform.
static void init()
          Initialisation - must be called by all clients before using any other parts of the library.
static void initConfigData()
          Reads config data (gate.xml files).
static void initCreoleRegister()
          Initialise the CREOLE register.
static void initDataStoreRegister()
          Initialise the DataStore register.
static boolean isGateType(String classname)
          Checks whether a particular class is a Gate defined type
static boolean isLocalWebServer()
          Should we assume there's a local web server?
static boolean isNetConnected()
          Should we assume we're connected to the net?
static String locateGateFiles()
          Find the location of the GATE binaries (and resources) in the local file system.
static boolean runningOnUnix()
          This method tries to guess if we are on a UNIX system.
static void setExecutable(Executable executable)
          Sets the Executable currently under execution.
static void setHiddenAttribute(FeatureMap fm, boolean hidden)
          Sets the value for the HIDDEN attribute of a feature map
static void setLocalWebServer(boolean b)
          Tell GATE whether to assume there's a local web server.
static void setNetConnected(boolean b)
          Tell GATE whether to assume we're connected to the net.
static void setSiteConfigFile(File siteConfigFile)
          Set the site config file (e.g.
static void setUrlBase(URL urlBase)
          Set the URL base for GATE files, e.g.
protected static boolean tryFileSystem()
          Try to find GATE files in the local file system
static boolean tryNetServer(String hostName, int serverPort, String path)
          Try to contact a network server.
static void writeUserConfig()
          Update the GATE development environment configuration data in the user's gate.xml file (create one if it doesn't exist).
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

STRINGBUFFER_SIZE

public static final int STRINGBUFFER_SIZE
The default StringBuffer size, it seems that we need longer string than the StringBuffer class default because of the high number of buffer expansions

HASH_STH_SIZE

public static final int HASH_STH_SIZE
The default size to be used for Hashtable, HashMap and HashSet. The defualt is 11 and it leads to big memory usage. Having a default load factor of 0.75, table of size 4 can take 3 elements before being re-hashed - a values that seems to be optimal for most of the cases.

DB_OWNER

public static final String DB_OWNER
The database schema owner (GATEADMIN is default) this one should not be hardcoded but set in the XML initialization files

builtinCreoleDirectoryUrls

private static String[] builtinCreoleDirectoryUrls
The list of builtin URLs to search for CREOLE resources.

URI

public static final String URI
The GATE URI used to interpret custom GATE tags

MIN_JDK_VERSION

protected static final String MIN_JDK_VERSION
Minimum version of JDK we support

netConnected

private static boolean netConnected
Flag controlling whether we should try to access the net, e.g. when setting up a base URL.

lastSym

private static int lastSym

localWebServer

private static boolean localWebServer
Flag controlling whether we should try to access a web server on localhost, e.g. when setting up a base URL. Has to be called before init().

urlBase

private static URL urlBase
The URL base for GATE files, e.g. http://gate.ac.uk/.

classLoader

private static GateClassLoader classLoader
Class loader used e.g. for loading CREOLE modules, of compiling JAPE rule RHSs.

creoleRegister

private static CreoleRegister creoleRegister
The CREOLE register.

dataStoreRegister

private static DataStoreRegister dataStoreRegister
The DataStore register

currentExecutable

private static Executable currentExecutable
The current executable under execution.

userConfig

private static OptionsMap userConfig
GATE development environment configuration data (stored in gate.xml).

originalUserConfig

private static OptionsMap originalUserConfig
This map stores the init-time config data in case we need it later. GATE development environment configuration data (stored in gate.xml).

userConfigElement

private static String userConfigElement
Name of the XML element for GATE development environment config data.

siteConfigFile

private static File siteConfigFile
Site config file

nl

private static String nl
Shorthand for local newline

emptyConfigFile

private static String emptyConfigFile
An empty config data file.
Constructor Detail

Gate

public Gate()
Method Detail

getMinJdkVersion

public static String getMinJdkVersion()
Get the minimum supported version of the JDK

init

public static void init()
                 throws GateException
Initialisation - must be called by all clients before using any other parts of the library. Also initialises the CREOLE register and reads config data (gate.xml files).
See Also:
initCreoleRegister()

initCreoleRegister

public static void initCreoleRegister()
                               throws GateException
Initialise the CREOLE register.

initDataStoreRegister

public static void initDataStoreRegister()
Initialise the DataStore register.

initConfigData

public static void initConfigData()
                           throws GateException
Reads config data (gate.xml files). There are three sorts of these files: Settings from files read after some settings have already been made will simply overwrite the previous settings.

guessUnicodeFont

public static String guessUnicodeFont()
Attempts to guess the Unicode font for the platform.

getUrl

public static URL getUrl()
                  throws GateException
Get a URL that points to either an HTTP server or a file system that contains GATE files (such as test cases). The following locations are tried in sequence: In each case we assume that a Web server will be running on port 80, and that if we can open a socket to that port then the server is running. (This is a bit of a strong assumption, but this URL is used largely by the test suite, so we're not betting anything too critical on it.)

Note that the value returned will only be calculated when the existing value recorded by this class is null (which will be the case when neither setUrlBase nor getUrlBase have been called, or if setUrlBase(null) has been called).


getUrl

public static URL getUrl(String path)
                  throws GateException
Get a URL that points to either an HTTP server or a file system that contains GATE files (such as test cases). Calls getUrl() then adds the path parameter to the result.
Parameters:
path - a path to add to the base URL.
See Also:
getUrl()

isNetConnected

public static boolean isNetConnected()
Should we assume we're connected to the net?

setNetConnected

public static void setNetConnected(boolean b)
Tell GATE whether to assume we're connected to the net. Has to be called before init().

isLocalWebServer

public static boolean isLocalWebServer()
Should we assume there's a local web server?

setLocalWebServer

public static void setLocalWebServer(boolean b)
Tell GATE whether to assume there's a local web server.

tryNetServer

public static boolean tryNetServer(String hostName,
                                   int serverPort,
                                   String path)
                            throws MalformedURLException
Try to contact a network server. When sucessfull sets urlBase to an HTTP URL for the server.
Parameters:
hostName - the name of the host to try and connect to
serverPort - the port to try and connect to
path - a path to append to the URL when we make a successfull connection. E.g. for host xyz, port 80, path /thing, the resultant URL would be http://xyz:80/thing.

tryFileSystem

protected static boolean tryFileSystem()
                                throws MalformedURLException
Try to find GATE files in the local file system

locateGateFiles

public static String locateGateFiles()
Find the location of the GATE binaries (and resources) in the local file system.

isGateType

public static boolean isGateType(String classname)
Checks whether a particular class is a Gate defined type

getHiddenAttribute

public static boolean getHiddenAttribute(FeatureMap fm)
Returns the value for the HIDDEN attribute of a feature map

setHiddenAttribute

public static void setHiddenAttribute(FeatureMap fm,
                                      boolean hidden)
Sets the value for the HIDDEN attribute of a feature map

addCreoleListener

public static void addCreoleListener(CreoleListener l)
Registers a CreoleListener with the Gate system

setUrlBase

public static void setUrlBase(URL urlBase)
Set the URL base for GATE files, e.g. http://gate.ac.uk/.

getClassLoader

public static GateClassLoader getClassLoader()
Get the GATE class loader.

getCreoleRegister

public static CreoleRegister getCreoleRegister()
Get the CREOLE register.

getDataStoreRegister

public static DataStoreRegister getDataStoreRegister()
Get the DataStore register.

setExecutable

public static void setExecutable(Executable executable)
Sets the Executable currently under execution. At a givem time there can be only one executable set. After the executable has finished its execution this value should be set back to null. An attempt to set the executable while this value is not null will result in the method call waiting until the old executable is set to null.

getExecutable

public static Executable getExecutable()
Returns the curently set executable. {@see setExecutable()}

genSym

public static String genSym()
Returns a new unique string

getUserConfigElement

public static String getUserConfigElement()
Gate the name of the XML element for GATE development environment config data.

getSiteConfigFile

public static File getSiteConfigFile()
Get the site config file (generally set during command-line processing or as a gate.config property). If the config is null, this method checks the gate.config property and uses it if non-null.

setSiteConfigFile

public static void setSiteConfigFile(File siteConfigFile)
Set the site config file (e.g. during command-line processing).

getEmptyConfigFile

public static String getEmptyConfigFile()
Get an empty config file. NOTE: this method is intended only for use by the test suite.

getUserConfig

public static OptionsMap getUserConfig()
Get the GATE development environment configuration data (initialised from gate.xml).

getOriginalUserConfig

public static OptionsMap getOriginalUserConfig()
Get the original, initialisation-time, GATE development environment configuration data (initialised from gate.xml).

writeUserConfig

public static void writeUserConfig()
                            throws GateException
Update the GATE development environment configuration data in the user's gate.xml file (create one if it doesn't exist).

getUserConfigFileName

public static String getUserConfigFileName()
Get the name of the user's gate.xml config file (this doesn't guarantee that file exists!).

getUserSessionFileName

public static String getUserSessionFileName()
Get the name of the user's gate.ser session state file (this doesn't guarantee that file exists!).

runningOnUnix

public static boolean runningOnUnix()
This method tries to guess if we are on a UNIX system. It does this by checking the value of System.getProperty("file.separator"); if this is "/" it concludes we are on UNIX. This is obviously not a very good idea in the general case, so nothing much should be made to depend on this method (e.g. just naming of config file .gate.xml as opposed to gate.xml).