Search in sources :

Example 11 with GateException

use of gate.util.GateException in project gate-core by GateNLP.

the class Main method registerCreoleUrls.

// main
/**
 * Register any CREOLE URLs that we got on the command line
 */
protected static void registerCreoleUrls() {
    CreoleRegister reg = Gate.getCreoleRegister();
    Iterator<URL> iter = pendingCreoleUrls.iterator();
    while (iter.hasNext()) {
        URL u = iter.next();
        try {
            reg.registerPlugin(new Plugin.Directory(u));
        } catch (GateException e) {
            Err.prln("Couldn't register CREOLE directory: " + u);
            Err.prln(e);
            System.exit(STATUS_ERROR);
        }
    }
}
Also used : GateException(gate.util.GateException) URL(java.net.URL) Plugin(gate.creole.Plugin)

Example 12 with GateException

use of gate.util.GateException in project gate-core by GateNLP.

the class Main method runGui.

// getMainFrame()
/**
 * Run the user interface.
 */
protected static void runGui() throws GateException {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    // initialise the library and load user CREOLE directories
    try {
        Gate.runInSandbox(false);
        Gate.init();
    } catch (Throwable t) {
        log.error("Problem while initialising GATE", t);
        int selection = JOptionPane.showOptionDialog(null, "Error during initialisation:\n" + t.toString() + "\nDo you still want to start GATE?", "GATE", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] { "Cancel", "Start anyway" }, "Cancel");
        if (selection != 1) {
            System.exit(1);
        }
    }
    // create the main frame, show it
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            // this needs to run before any GUI component is constructed.
            applyUserPreferences();
            // all the defaults tables have been updated; build the GUI
            frame = MainFrame.getInstance(gc);
            if (DEBUG)
                Out.prln("constructing GUI");
            // run the GUI
            frame.setTitleChangable(true);
            frame.setTitle(name + " " + version + " build " + build);
            // Set title from Java properties
            String title = System.getProperty(GateConstants.TITLE_JAVA_PROPERTY_NAME);
            if (title != null) {
                frame.setTitle(title);
            }
            // if
            frame.setTitleChangable(false);
            // Set icon from Java properties
            // iconName could be absolute or "gate:/img/..."
            String iconName = System.getProperty(GateConstants.APP_ICON_JAVA_PROPERTY_NAME);
            if (iconName != null) {
                try {
                    frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL(iconName)));
                } catch (MalformedURLException mue) {
                    log.warn("Could not load application icon.", mue);
                }
            }
            // if
            // Validate frames that have preset sizes
            frame.validate();
            // Center the window
            Rectangle screenBounds = gc.getBounds();
            Dimension screenSize = screenBounds.getSize();
            Dimension frameSize = frame.getSize();
            if (frameSize.height > screenSize.height) {
                frameSize.height = screenSize.height;
            }
            if (frameSize.width > screenSize.width) {
                frameSize.width = screenSize.width;
            }
            frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
            frame.setVisible(true);
            // load session if required and available;
            // do everything from a new thread.
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    try {
                        File sessionFile = Gate.getUserSessionFile();
                        if (sessionFile != null && sessionFile.exists()) {
                            MainFrame.lockGUI("Loading saved session...");
                            PersistenceManager.loadObjectFromFile(sessionFile);
                        }
                    } catch (Exception e) {
                        log.warn("Failed to load session data", e);
                    } finally {
                        MainFrame.unlockGUI();
                    }
                }
            };
            Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Session loader");
            thread.setPriority(Thread.MIN_PRIORITY);
            thread.start();
        }
    });
    registerCreoleUrls();
}
Also used : MalformedURLException(java.net.MalformedURLException) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) File(java.io.File) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) GateException(gate.util.GateException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 13 with GateException

use of gate.util.GateException in project gate-core by GateNLP.

the class Gate method writeUserConfig.

// getOriginalUserConfig
/**
 * Update the GATE development environment configuration data in the user's
 * <TT>gate.xml</TT> file (create one if it doesn't exist).
 */
public static void writeUserConfig() throws GateException {
    // if we are running in a sandbox then don't try and write anything
    if (sandboxed)
        return;
    /*String pluginsHomeStr;
    try {
      pluginsHomeStr = pluginsHome.getCanonicalPath();
    }
    catch(IOException ioe) {
      throw new GateRuntimeException(
        "Problem while locating the plug-ins home!", ioe);
    }*/
    /*String userPluginHomeStr;
    try {
      File userPluginHome = PluginUpdateManager.getUserPluginsHome();
      userPluginHomeStr = (userPluginHome != null ? userPluginHome.getCanonicalPath() : null);
    }
    catch (IOException ioe) {
      throw new GateRuntimeException("Unable to access user plugin directory!", ioe);
    }*/
    // TODO need to reinstate this
    // update the values for knownPluginPath
    /*String knownPluginPath = "";
    Iterator<URL> pluginIter = getKnownPlugins().iterator();
    while(pluginIter.hasNext()) {
      URL aPluginURL = pluginIter.next();
      // do not save installed plug-ins - they get loaded automatically
      if(aPluginURL.getProtocol().equals("file")) {
        File pluginDirectory = Files.fileFromURL(aPluginURL);
        try {
          if(pluginDirectory.getCanonicalPath().startsWith(pluginsHomeStr))
            continue;
          
          if (userPluginHomeStr != null && pluginDirectory.getCanonicalPath().startsWith(userPluginHomeStr))
            continue;
        }
        catch(IOException ioe) {
          throw new GateRuntimeException("Problem while locating the plug-in"
            + aPluginURL.toString(), ioe);
        }
      }
      if(knownPluginPath.length() > 0) knownPluginPath += ";";
      knownPluginPath += aPluginURL.toExternalForm();
    }
    getUserConfig().put(KNOWN_PLUGIN_PATH_KEY, knownPluginPath);*/
    // update the autoload plugin list
    /*String loadPluginPath = "";
    pluginIter = getAutoloadPlugins().iterator();
    while(pluginIter.hasNext()) {
      URL aPluginURL = pluginIter.next();
      if(loadPluginPath.length() > 0) loadPluginPath += ";";
      loadPluginPath += aPluginURL.toExternalForm();
    }
    getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, loadPluginPath);*/
    // the user's config file
    // String configFileName = getUserConfigFileName();
    // File configFile = new File(configFileName);
    File configFile = getUserConfigFile();
    // create if not there, then update
    try {
        // if the file doesn't exist, create one with an empty GATECONFIG
        if (!configFile.exists()) {
            FileOutputStream fos = new FileOutputStream(configFile);
            OutputStreamWriter writer = new OutputStreamWriter(fos, "UTF-8");
            writer.write(emptyConfigFile);
            writer.close();
        }
        // update the config element of the file
        Files.updateXmlElement(configFile, userConfigElement, userConfig.getStringMap());
    } catch (IOException e) {
        throw new GateException("problem writing user " + GATE_DOT_XML + ": " + nl + e.toString());
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) GateException(gate.util.GateException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 14 with GateException

use of gate.util.GateException in project gate-core by GateNLP.

the class Gate method initConfigData.

// initDataStoreRegister()
/**
 * Reads config data (<TT>gate.xml</TT> files). There are three sorts of
 * these files:
 * <UL>
 * <LI> The builtin file from GATE's resources - this is read first.
 * <LI> A site-wide init file given as a command-line argument or as a
 * <TT>gate.config</TT> property - this is read second.
 * <LI> The user's file from their home directory - this is read last.
 * </UL>
 * Settings from files read after some settings have already been made will
 * simply overwrite the previous settings.
 */
public static void initConfigData() throws GateException {
    ConfigDataProcessor configProcessor = new ConfigDataProcessor();
    URL configURL;
    // parse the site configuration file
    if (siteConfigFile != null && siteConfigFile.exists()) {
        try {
            configURL = siteConfigFile.toURI().toURL();
        } catch (MalformedURLException mue) {
            // this should never happen
            throw new GateRuntimeException(mue);
        }
        try {
            InputStream configStream = new FileInputStream(siteConfigFile);
            configProcessor.parseConfigFile(configStream, configURL);
        } catch (IOException e) {
            throw new GateException("Couldn't open site configuration file: " + configURL + " " + e);
        }
    }
    // parse the user configuration data if present
    if (userConfigFile != null && userConfigFile.exists()) {
        try {
            configURL = userConfigFile.toURI().toURL();
        } catch (MalformedURLException mue) {
            // this should never happen
            throw new GateRuntimeException(mue);
        }
        try {
            InputStream configStream = new FileInputStream(userConfigFile);
            configProcessor.parseConfigFile(configStream, configURL);
        } catch (IOException e) {
            throw new GateException("Couldn't open user configuration file: " + configURL + " " + e);
        }
    }
    // remember the init-time config options
    originalUserConfig.putAll(userConfig);
}
Also used : MalformedURLException(java.net.MalformedURLException) ConfigDataProcessor(gate.config.ConfigDataProcessor) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GateRuntimeException(gate.util.GateRuntimeException) GateException(gate.util.GateException) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 15 with GateException

use of gate.util.GateException 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)

Aggregations

GateException (gate.util.GateException)23 IOException (java.io.IOException)11 URL (java.net.URL)10 GateRuntimeException (gate.util.GateRuntimeException)8 MalformedURLException (java.net.MalformedURLException)8 Resource (gate.Resource)5 JDOMException (org.jdom.JDOMException)5 Plugin (gate.creole.Plugin)3 InputStream (java.io.InputStream)3 LanguageResource (gate.LanguageResource)2 ProcessingResource (gate.ProcessingResource)2 VisualResource (gate.VisualResource)2 ResourceInstantiationException (gate.creole.ResourceInstantiationException)2 CreoleResource (gate.creole.metadata.CreoleResource)2 GateClassLoader (gate.util.GateClassLoader)2 BeanInfo (java.beans.BeanInfo)2 IntrospectionException (java.beans.IntrospectionException)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 File (java.io.File)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2