gate.util.spring
Class Init

java.lang.Object
  extended by gate.util.spring.Init
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware

public class Init
extends Object
implements org.springframework.beans.factory.BeanFactoryAware

Helper class to support GATE initialisation via Spring. The following is a typical XML fragment to initialise GATE.

 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:gate="http://gate.ac.uk/ns/spring"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://gate.ac.uk/ns/spring
          http://gate.ac.uk/ns/spring.xsd">
 
   <gate:init gate-home="path/to/GATE"
              site-config-file="site/gate.xml"
              user-config-file="user/gate.xml">
     <gate:preload-plugins>
       <value>plugins/ANNIE</value>
       <value>http://plugins.org/another/plugin</value>
     </gate:preload-plugins>
   </gate:init>
 

Valid attributes are gate-home, plugins-home, site-config-file, user-config-file and builtin-creole-dir - Spring Resources corresponding to the equivalent static set methods of Gate. Also, preload-plugins is a list of Resources that will be loaded as GATE plugins after GATE is initialised.

As well as any plugins specified using preload-plugins, we also scan the defining bean factory for any beans of type ExtraGatePlugin, and load the plugins they refer to. This is useful if bean definitions are provided in several separate files, or if you are providing additional bean definitions to a context that already defines an Init bean definition that you cannot edit.

The equivalent definition in "normal" Spring form (without the gate: namespace) would be:

 <bean class="gate.util.spring.Init"
      init-method="init">
   <property name="gateHome" value="path/to/GATE" />
   <property name="siteConfigFile" value="site/gate.xml" />
   <property name="userConfigFile" value="user/gate.xml" />
   <property name="preloadPlugins">
     <list>
       <value>plugins/ANNIE</value>
       <value>http://plugins.org/another/plugin</value>
     </list>
   </property>
 </bean>
 
Note that when using this form the init-method="init" in the above definition is vital. GATE will not work if it is omitted.


Field Summary
private  org.springframework.beans.factory.BeanFactory beanFactory
           
private static org.apache.log4j.Logger log
           
private  List<org.springframework.core.io.Resource> plugins
          An optional list of plugins to load after GATE initialisation.
 
Constructor Summary
Init()
           
 
Method Summary
 void init()
          Initialises GATE and loads any preloadPlugins that have been specified, as well as any defined by ExtraGatePlugin beans in the containing factory.
private  void loadPlugin(org.springframework.core.io.Resource plugin)
           
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void setBuiltinCreoleDir(org.springframework.core.io.Resource builtinCreoleDir)
           
 void setGateHome(org.springframework.core.io.Resource gateHome)
           
 void setPluginsHome(org.springframework.core.io.Resource pluginsHome)
           
 void setPreloadPlugins(List<org.springframework.core.io.Resource> plugins)
           
 void setSiteConfigFile(org.springframework.core.io.Resource siteConfigFile)
           
 void setUserConfigFile(org.springframework.core.io.Resource userConfigFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.log4j.Logger log

plugins

private List<org.springframework.core.io.Resource> plugins
An optional list of plugins to load after GATE initialisation.


beanFactory

private org.springframework.beans.factory.BeanFactory beanFactory
Constructor Detail

Init

public Init()
Method Detail

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware

setGateHome

public void setGateHome(org.springframework.core.io.Resource gateHome)
                 throws IOException
Throws:
IOException

setPluginsHome

public void setPluginsHome(org.springframework.core.io.Resource pluginsHome)
                    throws IOException
Throws:
IOException

setSiteConfigFile

public void setSiteConfigFile(org.springframework.core.io.Resource siteConfigFile)
                       throws IOException
Throws:
IOException

setUserConfigFile

public void setUserConfigFile(org.springframework.core.io.Resource userConfigFile)
                       throws IOException
Throws:
IOException

setBuiltinCreoleDir

public void setBuiltinCreoleDir(org.springframework.core.io.Resource builtinCreoleDir)
                         throws IOException
Throws:
IOException

setPreloadPlugins

public void setPreloadPlugins(List<org.springframework.core.io.Resource> plugins)

init

public void init()
          throws Exception
Initialises GATE and loads any preloadPlugins that have been specified, as well as any defined by ExtraGatePlugin beans in the containing factory.

Throws:
Exception

loadPlugin

private void loadPlugin(org.springframework.core.io.Resource plugin)
                 throws GateException,
                        IOException,
                        MalformedURLException
Throws:
GateException
IOException
MalformedURLException