use of org.cytoscape.app.CyAppAdapter in project cytoscape-impl by cytoscape.
the class ExecuteScriptTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
final String selected = engineNames.getSelectedValue();
// Special case: CyCommand
if (selected == CYCOMMAND_TITLE) {
executeCyCommandFile();
return;
}
final ScriptEngineFactory engineFactory = name2engineMap.get(engineNames.getSelectedValue());
final ScriptEngine engine = engineFactory.getScriptEngine();
// This object should be injected to all scripts to access manager objects from scripts.
engine.put("cyAppAdapter", serviceRegistrar.getService(CyAppAdapter.class));
// Execute
FileReader reader = null;
try {
reader = new FileReader(file);
engine.eval(reader);
} finally {
if (reader != null) {
reader.close();
reader = null;
}
}
}
use of org.cytoscape.app.CyAppAdapter in project cytoscape-impl by cytoscape.
the class ExecuteScriptCommandTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
final ScriptEngine engine = manager.getEngineByName(engineName);
// This object should be injected to all scripts to access manager objects from scripts.
engine.put("cyAppAdapter", serviceRegistrar.getService(CyAppAdapter.class));
final String[] argArray = new String[args.size()];
for (int i = 0; i < args.size(); i++) {
System.out.println("* ARG = " + args.get(i));
argArray[i] = args.get(i);
}
engine.put("args", argArray);
// Execute
FileReader reader = null;
try {
reader = new FileReader(new File(filename));
engine.eval(reader);
} catch (FileNotFoundException e) {
throw new IOException("Could not open the file.", e);
} finally {
if (reader != null) {
reader.close();
reader = null;
}
}
}
use of org.cytoscape.app.CyAppAdapter in project cytoscape-impl by cytoscape.
the class SimpleApp method load.
@Override
public void load(AppManager appManager) throws AppLoadingException {
if (appConstructor != null)
return;
// Make a copy used to create app instance
LinkedList<String> uniqueNameDirectory = new LinkedList<String>();
uniqueNameDirectory.add(appManager.getTemporaryInstallPath());
try {
if (appTemporaryInstallFile == null) {
File targetFile = new File(appManager.getTemporaryInstallPath() + File.separator + suggestFileName(uniqueNameDirectory, this.getAppFile().getName()));
FileUtils.copyFile(this.getAppFile(), targetFile);
appTemporaryInstallFile = targetFile;
}
} catch (IOException e) {
throw new AppLoadingException("Unable to make copy of app jar for instancing", e);
}
File installFile = appTemporaryInstallFile;
if (installFile == null) {
throw new AppLoadingException("No copy of app jar for instancing was found");
}
URL appURL = null;
try {
appURL = installFile.toURI().toURL();
} catch (MalformedURLException e) {
throw new AppLoadingException("Unable to obtain URL for file: " + installFile, e);
}
// TODO: Currently uses the CyAppAdapter's loader to load apps' classes. Is there reason to use a different one?
ClassLoader appClassLoader = new URLClassLoader(new URL[] { appURL }, appManager.getSwingAppAdapter().getClass().getClassLoader());
// Attempt to load the class
try {
appEntryClass = appClassLoader.loadClass(this.getEntryClassName());
} catch (ClassNotFoundException e) {
throw new AppLoadingException("Class " + this.getEntryClassName() + " not found in URL: " + appURL, e);
}
// Attempt to obtain the constructor
try {
try {
appConstructor = appEntryClass.getConstructor(CyAppAdapter.class);
} catch (SecurityException e) {
throw new AppLoadingException("Access to the constructor for " + appEntryClass + " denied.", e);
} catch (NoSuchMethodException e) {
throw new AppLoadingException("Unable to find a constructor for " + appEntryClass + " that takes a CyAppAdapter as its argument.", e);
}
} catch (AppLoadingException e) {
try {
appConstructor = appEntryClass.getConstructor(CySwingAppAdapter.class);
} catch (SecurityException e2) {
throw new AppLoadingException("Access to the constructor for " + appEntryClass + " taking a CySwingAppAdapter as its argument denied.", e2);
} catch (NoSuchMethodException e2) {
throw new AppLoadingException("Unable to find an accessible constructor that takes either" + " a CyAppAdapter or a CySwingAppAdapter as its argument.", e2);
}
}
}
Aggregations