Search in sources :

Example 1 with CreoleRegisterImpl

use of gate.creole.CreoleRegisterImpl in project gate-core by GateNLP.

the class Gate method init.

/**
 * Initialisation - must be called by all clients before using any other parts
 * of the library. Also initialises the CREOLE register and reads config data (<TT>gate.xml</TT>
 * files).
 *
 * @see #initCreoleRegister
 */
public static void init() throws GateException {
    // init local paths
    if (!sandboxed)
        initLocalPaths();
    // check if benchmarking should be enabled or disabled
    if (System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME) != null && System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME).equalsIgnoreCase("true")) {
        Benchmark.setBenchmarkingEnabled(true);
    }
    // builtin creole dir
    if (builtinCreoleDir == null) {
        String builtinCreoleDirPropertyValue = System.getProperty(BUILTIN_CREOLE_DIR_PROPERTY_NAME);
        if (builtinCreoleDirPropertyValue == null) {
            // default to /gate/resources/creole in gate.jar
            builtinCreoleDir = Files.getGateResource("/creole/");
        } else {
            String builtinCreoleDirPath = builtinCreoleDirPropertyValue;
            // a creole directory URL should always end with a forward slash
            if (!builtinCreoleDirPath.endsWith("/")) {
                builtinCreoleDirPath += "/";
            }
            try {
                builtinCreoleDir = new URL(builtinCreoleDirPath);
            } catch (MalformedURLException mue) {
                // couldn't parse as a File either, so throw an exception
                throw new GateRuntimeException(BUILTIN_CREOLE_DIR_PROPERTY_NAME + " value \"" + builtinCreoleDirPropertyValue + "\" could" + " not be parsed as either a URL or a file path.");
            }
            log.info("Using " + builtinCreoleDir + " as built-in CREOLE" + " directory URL");
        }
    }
    // initialise the symbols generator
    lastSym = 0;
    // create class loader and creole register if they're null
    if (classLoader == null)
        classLoader = new GateClassLoader("Top-Level GATE ClassLoader", Gate.class.getClassLoader());
    if (creoleRegister == null)
        creoleRegister = new CreoleRegisterImpl();
    if (knownPlugins == null)
        knownPlugins = new HashSet<Plugin>();
    if (autoloadPlugins == null)
        autoloadPlugins = new ArrayList<Plugin>();
    // if(pluginData == null) pluginData = new HashSet<Plugin>();
    // init the creole register
    initCreoleRegister();
    // init the data store register
    initDataStoreRegister();
    // initialisation in order for the CREOLE-DIR elements to have and effect
    if (!sandboxed)
        initConfigData();
    if (!sandboxed)
        initCreoleRepositories();
    // the creoleRegister acts as a proxy for datastore related events
    dataStoreRegister.addCreoleListener(creoleRegister);
    // some of the events are actually fired by the {@link gate.Factory}
    Factory.addCreoleListener(creoleRegister);
    // check we have a useable JDK
    if (System.getProperty("java.version").compareTo(MIN_JDK_VERSION) < 0) {
        throw new GateException("GATE requires JDK " + MIN_JDK_VERSION + " or newer");
    }
    initFinished = true;
}
Also used : MalformedURLException(java.net.MalformedURLException) CreoleRegisterImpl(gate.creole.CreoleRegisterImpl) GateRuntimeException(gate.util.GateRuntimeException) GateException(gate.util.GateException) ArrayList(java.util.ArrayList) GateClassLoader(gate.util.GateClassLoader) URL(java.net.URL) HashSet(java.util.HashSet)

Example 2 with CreoleRegisterImpl

use of gate.creole.CreoleRegisterImpl in project gate-core by GateNLP.

the class AvailablePlugins method updateAvailablePlugins.

protected Set<Plugin> updateAvailablePlugins(Plugin.DownloadListener progressPanel) {
    Set<Plugin> creoleDirectories = Gate.getCreoleRegister().getPlugins();
    // update the data structures to reflect the user's choices
    Iterator<Plugin> pluginIter = loadNowByURL.keySet().iterator();
    Set<Plugin> toLoad = new HashSet<Plugin>();
    while (pluginIter.hasNext()) {
        Plugin aPluginURL = pluginIter.next();
        boolean load = loadNowByURL.get(aPluginURL);
        boolean loaded = creoleDirectories.contains(aPluginURL);
        if (load && !loaded) {
            // remember that we need to load this plugin
            toLoad.add(aPluginURL);
        }
        if (!load && loaded) {
            // remove the directory
            Gate.getCreoleRegister().unregisterPlugin(aPluginURL);
        }
    }
    pluginIter = loadAlwaysByURL.keySet().iterator();
    while (pluginIter.hasNext()) {
        Plugin aPluginURL = pluginIter.next();
        boolean load = loadAlwaysByURL.get(aPluginURL);
        boolean loaded = Gate.getAutoloadPlugins().contains(aPluginURL);
        if (load && !loaded) {
            // set autoload to true
            Gate.addAutoloadPlugin(aPluginURL);
        }
        if (!load && loaded) {
            // set autoload to false
            Gate.removeAutoloadPlugin(aPluginURL);
        }
    }
    while (!toLoad.isEmpty()) {
        // lets finally try loading all the plugings
        int numToLoad = toLoad.size();
        List<Throwable> errors = new ArrayList<Throwable>();
        pluginIter = toLoad.iterator();
        while (pluginIter.hasNext()) {
            Plugin aPluginURL = pluginIter.next();
            // load the directory
            try {
                aPluginURL.addDownloadListener(progressPanel);
                ((CreoleRegisterImpl) Gate.getCreoleRegister()).registerPlugin(aPluginURL);
                pluginIter.remove();
            } catch (Throwable ge) {
                // TODO suppress the errors unless we are going to break out of the loop
                // ge.printStackTrace();
                errors.add(ge);
            } finally {
                aPluginURL.removeDownloadListener(progressPanel);
            }
        }
        if (numToLoad == toLoad.size()) {
            // we didn't actually achieve anything
            for (Throwable t : errors) {
                t.printStackTrace();
            }
            break;
        }
    }
    loadNowByURL.clear();
    loadAlwaysByURL.clear();
    return toLoad;
}
Also used : CreoleRegisterImpl(gate.creole.CreoleRegisterImpl) ArrayList(java.util.ArrayList) Plugin(gate.creole.Plugin) HashSet(java.util.HashSet)

Aggregations

CreoleRegisterImpl (gate.creole.CreoleRegisterImpl)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Plugin (gate.creole.Plugin)1 GateClassLoader (gate.util.GateClassLoader)1 GateException (gate.util.GateException)1 GateRuntimeException (gate.util.GateRuntimeException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1