Author: paperwing
Date: 2012-04-02 12:04:06 -0700 (Mon, 02 Apr 2012)
New Revision: 28713
Added:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppCopyException.java
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
Log:
Initial version of App class for representing and storing all needed
information about an app, as well as initial AppManager implementation that
uses Apache Commons library for copying and moving app files
Added:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppCopyException.java
===================================================================
---
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppCopyException.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppCopyException.java
2012-04-02 19:04:06 UTC (rev 28713)
@@ -0,0 +1,9 @@
+package org.cytoscape.app.internal.exception;
+
+public class AppCopyException extends Exception {
+
+ /** Long serial version identifier required by the Serializable class */
+ private static final long serialVersionUID = 9013239765398696280L;
+
+
+}
Property changes on:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/exception/AppCopyException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
===================================================================
---
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
2012-04-02 19:04:06 UTC (rev 28713)
@@ -0,0 +1,56 @@
+package org.cytoscape.app.internal.manager;
+
+import java.io.File;
+
+import org.cytoscape.app.AbstractCyApp;
+
+/**
+ * This class represents an app, and contains all needed information about the
app such as its name, version,
+ * authors list, description, and file path.
+ */
+public class App {
+
+ private String appName;
+ private String version;
+ private String authors;
+ private String description;
+ private File appFile;
+
+ /**
+ * The name of the app's class that extends {@link AbstractCyApp} to be
instantiated when the app is loaded.
+ */
+ private String entryClassName;
+
+ public App(String appName, String version, String authors, String
description, File appFile, String entryClassName) {
+ this.appName = appName;
+ this.version = version;
+ this.authors = authors;
+ this.description = description;
+ this.appFile = appFile;
+ this.entryClassName = entryClassName;
+ }
+
+ public String getAppName() {
+ return appName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public String getAuthors() {
+ return authors;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public File getAppFile() {
+ return appFile;
+ }
+
+ public String getEntryClassName() {
+ return entryClassName;
+ }
+}
Property changes on:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/App.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
===================================================================
---
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
(rev 0)
+++
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
2012-04-02 19:04:06 UTC (rev 28713)
@@ -0,0 +1,113 @@
+package org.cytoscape.app.internal.manager;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarFile;
+
+import org.apache.commons.io.FileUtils;
+import org.cytoscape.app.AbstractCyApp;
+import org.cytoscape.app.CyAppAdapter;
+import org.cytoscape.app.internal.exception.AppCopyException;
+import org.cytoscape.application.CyApplicationConfiguration;
+
+/**
+ * This class represents an AppManager, which is capable of maintaining a list
of all currently installed and available apps. The class
+ * also provides functionalities for installing and uninstalling apps.
+ */
+public class AppManager {
+ private static final String APP_CLASS_TAG = "Cytoscape-App";
+
+ private Set<App> installedApps;
+ private Set<App> toBeUninstalledApps;
+ private Set<App> uninstalledApps;
+
+ /**
+ * {@link CyApplicationConfiguration} service used to obtain the
directories used to store the apps.
+ */
+ private CyApplicationConfiguration applicationConfiguration;
+
+ /**
+ * The {@link CyAppAdapter} service reference provided to the
constructor of the app's {@link AbstractCyApp}-implementing class.
+ */
+ private CyAppAdapter appAdapter;
+
+ public AppManager(CyAppAdapter appAdapter, CyApplicationConfiguration
applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ this.appAdapter = appAdapter;
+
+ installedApps = new HashSet<App>();
+ toBeUninstalledApps = new HashSet<App>();
+ uninstalledApps = new HashSet<App>();
+ }
+
+ /**
+ * Installs an app; first makes a copy of the app file and places it in
the directory used to hold all installed and uninstalled apps.
+ * Then, the app is created by instancing its {@link AbstractCyApp}
class that implements.
+ * @param app The {@link App} object representing and providing
information about the app to install
+ * @throws AppCopyException If there was an IO-related error during the
copy operation that prevents the app from
+ * being successfully installed.
+ */
+ public void installApp(App app) throws AppCopyException {
+
+ File appFile = app.getAppFile();
+
+ // Copy app to local storage directory using utilities provided
by the Apache Commons library.
+ try {
+ // Overwrites files with the same name.
+ FileUtils.copyFileToDirectory(appFile, getAppPath());
+ } catch (IOException e) {
+
+ throw new AppCopyException();
+ }
+
+ // TODO: Currently uses the CyAppAdapter's loader to load apps'
classes. Is there reason to use a different one?
+ ClassLoader appClassLoader =
appAdapter.getClass().getClassLoader();
+
+ Class<?> appEntryClass = null;
+ try {
+ appEntryClass =
appClassLoader.loadClass(app.getEntryClassName());
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Constructor<?> constructor = null;
+ try {
+ constructor =
appEntryClass.getConstructor(CyAppAdapter.class);
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ try {
+ Object object = constructor.newInstance(appAdapter);
+ } catch (IllegalArgumentException e) {
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+
+ installedApps.add(app);
+ }
+
+ public Set<App> getInstalledApps() {
+ return installedApps;
+ }
+
+ /**
+ * Return the path of the directory used to contain all apps.
+ * @return The path of the root directory containing all installed and
uninstalled apps.
+ */
+ private File getAppPath() {
+ // TODO: At time of writing, CyApplicationConfiguration always
returns the home directory for directory location.
+ return
applicationConfiguration.getConfigurationDirectoryLocation();
+ }
+}
Property changes on:
csplugins/trunk/toronto/yuedong/app_manager/impl/app-impl/src/main/java/org/cytoscape/app/internal/manager/AppManager.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.