use of gate.creole.Plugin in project gate-core by GateNLP.
the class AvailablePlugins method unsavedChanges.
protected boolean unsavedChanges() {
Set<Plugin> creoleDirectories = Gate.getCreoleRegister().getPlugins();
Iterator<Plugin> pluginIter = loadNowByURL.keySet().iterator();
while (pluginIter.hasNext()) {
Plugin aPluginURL = pluginIter.next();
boolean load = loadNowByURL.get(aPluginURL);
boolean loaded = creoleDirectories.contains(aPluginURL);
if (load && !loaded) {
return true;
}
if (!load && loaded) {
return true;
}
}
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) {
return true;
}
if (!load && loaded) {
return true;
}
}
return false;
}
use of gate.creole.Plugin in project gate-core by GateNLP.
the class AvailablePlugins method filterRows.
private void filterRows(String rowFilter) {
final String filter = rowFilter.trim().toLowerCase();
final String previousURL = mainTable.getSelectedRow() == -1 ? "" : (String) mainTable.getValueAt(mainTable.getSelectedRow(), mainTable.convertColumnIndexToView(NAME_COLUMN));
if (filter.length() < 2) {
// one character or less, don't filter rows
visibleRows.clear();
visibleRows.addAll(Gate.getKnownPlugins());
} else {
// filter rows case insensitively on each plugin URL and its resources
visibleRows.clear();
// for(int i = 0; i < Gate.getKnownPlugins().size(); i++) {
for (Plugin plugin : Gate.getKnownPlugins()) {
// Gate.DirectoryInfo dInfo =
// Gate.getDirectoryInfo(Gate.getKnownPlugins().get(i));
// dInfo.getUrl().toString();
String name = plugin.getName();
String resources = "";
for (int j = 0; j < plugin.getResourceInfoList().size(); j++) {
resources += plugin.getResourceInfoList().get(j).getResourceName() + " ";
}
if ((name != null && name.toLowerCase().contains(filter)) || resources.toLowerCase().contains(filter)) {
visibleRows.add(plugin);
}
}
}
mainTableModel.fireTableDataChanged();
if (mainTable.getRowCount() > 0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
mainTable.setRowSelectionInterval(0, 0);
if (filter.length() < 2 && previousURL != null && !previousURL.equals("")) {
// reselect the last selected row based on its name and url values
for (int row = 0; row < mainTable.getRowCount(); row++) {
String url = (String) mainTable.getValueAt(row, mainTable.convertColumnIndexToView(NAME_COLUMN));
if (url.contains(previousURL)) {
mainTable.setRowSelectionInterval(row, row);
mainTable.scrollRectToVisible(mainTable.getCellRect(row, 0, true));
break;
}
}
}
}
});
}
}
use of gate.creole.Plugin in project gate-core by GateNLP.
the class PersistenceManager method loadObjectFromUrl.
public static Object loadObjectFromUrl(URL url) throws PersistenceException, IOException, ResourceInstantiationException {
if (!Gate.isInitialised())
throw new ResourceInstantiationException("You must call Gate.init() before you can restore resources");
ProgressListener pListener = (ProgressListener) Gate.getListeners().get("gate.event.ProgressListener");
StatusListener sListener = (gate.event.StatusListener) Gate.getListeners().get("gate.event.StatusListener");
if (pListener != null)
pListener.progressChanged(0);
startLoadingFrom(url);
// the actual stream obtained from the URL. We keep a reference to this
// so we can ensure it gets closed.
InputStream rawStream = null;
try {
long startTime = System.currentTimeMillis();
// Determine whether the file contains an application serialized in
// xml
// format. Otherwise we will assume that it contains native
// serializations.
boolean xmlStream = isXmlApplicationFile(url);
ObjectInputStream ois = null;
HierarchicalStreamReader reader = null;
XStream xstream = null;
// whether serialization is native or xml.
if (xmlStream) {
// we don't want to strip the BOM on XML.
Reader inputReader = new InputStreamReader(rawStream = url.openStream());
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
XMLStreamReader xsr = inputFactory.createXMLStreamReader(url.toExternalForm(), inputReader);
reader = new StaxReader(new QNameMap(), xsr);
} catch (XMLStreamException xse) {
// make sure the stream is closed, on error
inputReader.close();
throw new PersistenceException("Error creating reader", xse);
}
xstream = new XStream(new StaxDriver(new XStream11NameCoder())) {
@Override
protected boolean useXStream11XmlFriendlyMapper() {
return true;
}
};
// make XStream load classes through the GATE ClassLoader
xstream.setClassLoader(Gate.getClassLoader());
// make the XML stream appear as a normal ObjectInputStream
ois = xstream.createObjectInputStream(reader);
} else {
// use GateAwareObjectInputStream to load classes through the
// GATE ClassLoader if they can't be loaded through the one
// ObjectInputStream would normally use
ois = new GateAwareObjectInputStream(url.openStream());
}
Object res = null;
try {
// first read the list of creole URLs.
@SuppressWarnings("unchecked") Iterator<?> urlIter = ((Collection<?>) getTransientRepresentation(ois.readObject())).iterator();
// and re-register them
while (urlIter.hasNext()) {
Object anUrl = urlIter.next();
try {
if (anUrl instanceof URL)
Gate.getCreoleRegister().registerPlugin(new Plugin.Directory((URL) anUrl), false);
else if (anUrl instanceof Plugin)
Gate.getCreoleRegister().registerPlugin((Plugin) anUrl, false);
} catch (GateException ge) {
System.out.println("We've hit an error!");
ge.printStackTrace();
ge.printStackTrace(Err.getPrintWriter());
Err.prln("Could not reload creole directory " + anUrl);
}
}
// now we can read the saved object in the presence of all
// the right plugins
res = ois.readObject();
// ensure a fresh start
clearCurrentTransients();
res = getTransientRepresentation(res);
long endTime = System.currentTimeMillis();
if (sListener != null)
sListener.statusChanged("Loading completed in " + NumberFormat.getInstance().format((double) (endTime - startTime) / 1000) + " seconds");
return res;
} catch (ResourceInstantiationException rie) {
if (sListener != null)
sListener.statusChanged("Failure during instantiation of resources.");
throw rie;
} catch (PersistenceException pe) {
if (sListener != null)
sListener.statusChanged("Failure during persistence operations.");
throw pe;
} catch (Exception ex) {
if (sListener != null)
sListener.statusChanged("Loading failed!");
throw new PersistenceException(ex);
} finally {
// make sure the stream gets closed
if (ois != null)
ois.close();
if (reader != null)
reader.close();
}
} finally {
if (rawStream != null)
rawStream.close();
finishedLoading();
if (pListener != null)
pListener.processFinished();
}
}
Aggregations