com.openindex.openestate.tool.utils.engine
Class PlugEngine

java.lang.Object
  extended by com.openindex.openestate.tool.utils.engine.PlugEngine

public class PlugEngine
extends Object

Manage the plugins and the updates. Use getInstance() to get the shared instance for this class.
$Id: PlugEngine.java 856 2011-04-29 22:30:40Z andy $

Author:
Christophe Le Besnerais, Andreas Rudolph

Nested Class Summary
protected  class PlugEngine.PlugEngineHandler
          parse XML configuration files
 
Field Summary
static String DIR
          directory where plugins files are stored
static String FILE
          XML file where the list of installed plugins is stored
 
Method Summary
protected static void addFileToClasspath(File file)
          add a file to classpath at runtime.
protected static void addFileToClasspath(String fileUrl)
          add a file to classpath at runtime.
protected  void addPluggable(Pluggable plugin)
          add or update a plugin
 List<Pluggable> checkForUpdates(org.apache.http.client.HttpClient client)
           
protected  String downloadFile(org.apache.http.client.HttpClient client, String file, String folder)
          copy the given file to the given directory (inside the plugins directory)
 List<Pluggable> getAllEnabledPluggables()
           
 List<Pluggable> getAllPluggables()
           
 List<Pluggable> getAllUpdatablePluggables()
           
 List<Pluggable> getAllVisiblePluggables()
           
 int getCurrentVersion()
          Plugin with getMinimalVersion() < to getCurrentVersion() will be disabled.
 File getDirectory(Pluggable plugin)
           
 DownloadMonitor getDownloadMonitor()
           
static PlugEngine getInstance()
           
 void init(Object... args)
          this method should be called first before starting plugins
 Pluggable installOrUpdate(org.apache.http.client.HttpClient client, URI updateFile)
          Install or update a plugin
 boolean isCompatible(Pluggable plugin)
           
 boolean isEnabled(Pluggable plugin)
           
 boolean isHidden(Pluggable plugin)
           
 boolean isUpdateEnabled(Pluggable plugin)
           
protected  void loadPluggables(org.apache.http.client.HttpClient client)
          load all the installed plugins without starting them
 void removePluggable(Pluggable plugin)
          De-install a plugin, and remove its file
 void savePluggable()
          save the list of the installed plugins in a XML file
 void setCurrentVersion(int currentVersion)
          change the current version of the main application.
 void setDownloadMonitor(DownloadMonitor downloadMonitor)
          set the download monitor which will be called when a plugin is downloaded
 void setEnabled(Pluggable plugin, boolean enabled)
          enable or disable the auto update of a plugin
static void setInstance(PlugEngine engine)
          change the shared instance of this class
 void setUpdateEnabled(Pluggable plugin, boolean enabled)
          enable or disable the auto update of a plugin
 void startPluggable(Pluggable plugin)
          start the given plugin
 void startPluggables()
          start all the loaded plugins
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE

public static final String FILE
XML file where the list of installed plugins is stored

See Also:
Constant Field Values

DIR

public static final String DIR
directory where plugins files are stored

See Also:
Constant Field Values
Method Detail

getInstance

public static PlugEngine getInstance()
Returns:
the shared instance of this class

setInstance

public static void setInstance(PlugEngine engine)
change the shared instance of this class

Parameters:
engine - engine

init

public void init(Object... args)
          throws PlugEngineException
this method should be called first before starting plugins

Parameters:
args - the arguments that will be given to the plugin when they are started
Throws:
PlugEngineException

loadPluggables

protected void loadPluggables(org.apache.http.client.HttpClient client)
                       throws PlugEngineException
load all the installed plugins without starting them

Parameters:
client - HTTP-client
Throws:
PlugEngineException

startPluggables

public void startPluggables()
start all the loaded plugins


startPluggable

public void startPluggable(Pluggable plugin)
start the given plugin

Parameters:
plugin - plugin-instance

savePluggable

public void savePluggable()
                   throws PlugEngineException
save the list of the installed plugins in a XML file

Throws:
PlugEngineException

installOrUpdate

public Pluggable installOrUpdate(org.apache.http.client.HttpClient client,
                                 URI updateFile)
                          throws PlugEngineException
Install or update a plugin

Parameters:
client - HTTP-client
updateFile - the XML configuration file for the plugin to install
Returns:
the installed plugin
Throws:
PlugEngineException

addPluggable

protected void addPluggable(Pluggable plugin)
                     throws PlugEngineException
add or update a plugin

Parameters:
plugin - plugin-instance
Throws:
PlugEngineException

removePluggable

public void removePluggable(Pluggable plugin)
                     throws PlugEngineException
De-install a plugin, and remove its file

Parameters:
plugin - plugin-instance
Throws:
PlugEngineException - plugin-error

getAllPluggables

public List<Pluggable> getAllPluggables()
Returns:
the list of all loaded plugins

getAllVisiblePluggables

public List<Pluggable> getAllVisiblePluggables()
Returns:
the list of all non hidden loaded plugins

getAllUpdatablePluggables

public List<Pluggable> getAllUpdatablePluggables()
Returns:
the list of all loaded plugins with update enabled

getAllEnabledPluggables

public List<Pluggable> getAllEnabledPluggables()
Returns:
the list of all loaded and enabled plugins

isHidden

public boolean isHidden(Pluggable plugin)
Parameters:
plugin - plugin-instance
Returns:
true if the given plugin should not be show to the user

isUpdateEnabled

public boolean isUpdateEnabled(Pluggable plugin)
Parameters:
plugin - plugin-instance
Returns:
false if the given plugin should not be updated

setUpdateEnabled

public void setUpdateEnabled(Pluggable plugin,
                             boolean enabled)
                      throws PlugEngineException
enable or disable the auto update of a plugin

Parameters:
plugin - plugin-instance
enabled - enable/disable
Throws:
PlugEngineException

isEnabled

public boolean isEnabled(Pluggable plugin)
Parameters:
plugin - plugin
Returns:
false if the given plugin has been disabled

setEnabled

public void setEnabled(Pluggable plugin,
                       boolean enabled)
                throws PlugEngineException
enable or disable the auto update of a plugin

Parameters:
plugin - plugin
enabled - enable/disable
Throws:
PlugEngineException

getDirectory

public File getDirectory(Pluggable plugin)
Parameters:
plugin - plugin
Returns:
the directory in which the files of the given plugin are storred

checkForUpdates

public List<Pluggable> checkForUpdates(org.apache.http.client.HttpClient client)
                                throws IOException,
                                       ParserConfigurationException,
                                       SAXException,
                                       gnu.inet.encoding.IDNAException,
                                       URISyntaxException
Parameters:
client - HTTP-client
Returns:
the list of all programs which have a new version to install
Throws:
IOException
ParserConfigurationException
SAXException
gnu.inet.encoding.IDNAException
URISyntaxException

getDownloadMonitor

public DownloadMonitor getDownloadMonitor()
Returns:
the current download monitor

setDownloadMonitor

public void setDownloadMonitor(DownloadMonitor downloadMonitor)
set the download monitor which will be called when a plugin is downloaded

Parameters:
downloadMonitor - monitor-instance

isCompatible

public boolean isCompatible(Pluggable plugin)
Parameters:
plugin - plugin-instance
Returns:
true if the given plugin does not work for this version of the main application
See Also:
Pluggable.getMinimalVersion(), getCurrentVersion()

getCurrentVersion

public int getCurrentVersion()
Plugin with getMinimalVersion() < to getCurrentVersion() will be disabled.

Returns:
the current version of the main application

setCurrentVersion

public void setCurrentVersion(int currentVersion)
                       throws PlugEngineException
change the current version of the main application. Plugin with getMinimalVersion() < to getCurrentVersion() will be disabled.

Parameters:
currentVersion - version
Throws:
PlugEngineException

addFileToClasspath

protected static void addFileToClasspath(String fileUrl)
                                  throws Exception
add a file to classpath at runtime. see http://forum.java.sun.com/thread.jspa?threadID=300557&start=45&tstart=0

Parameters:
fileUrl - the path of the file to add
Throws:
Exception - internal error

addFileToClasspath

protected static void addFileToClasspath(File file)
                                  throws Exception
add a file to classpath at runtime. see http://forum.java.sun.com/thread.jspa?threadID=300557&start=45&tstart=0

Parameters:
file - the file to add
Throws:
Exception - internal error

downloadFile

protected String downloadFile(org.apache.http.client.HttpClient client,
                              String file,
                              String folder)
                       throws PlugEngineException
copy the given file to the given directory (inside the plugins directory)

Parameters:
client - HTTP-client
file - filepath
folder - folder
Returns:
the adress of the copied file
Throws:
PlugEngineException


Copyright © 2012 OpenEstate. All Rights Reserved.