ks.client.gamefactory
Class PluginFactory

java.lang.Object
  |
  +--ks.client.gamefactory.PluginFactory

public class PluginFactory
extends java.lang.Object

This class is responsible for instantiating objects from the Jar files that store plugins on the client side.

Each plugin is stored in a jar file with the name "author_Game.jar", and this factory will extract the class of package "author.Game" from within this Jar file and instantiate it. Note: author.Game must be a subclass of the Solitaire class.

The loadPluginList(String dir) will load up a list of local plugins that have already been registered with the indexFile in the given directory. registerPlugin (String dir, String jarName) verifies that that given jarName is a valid Solitaire plugin and then appends the plugin to the index file.

instantiatePlugin(String dir, String plugin) will attempt to instantiate the given plugin for play. appendPluginList(String dir, String jarName) and removePluginList(String dir, String jarName) update the index file accordingly.

The Format of the index file is:
jarName:jarName:entry
where entry is any string needed to be stored with the plugin file.

Creation date: (12/8/01 12:04:58 AM)


Field Summary
protected  java.util.Hashtable knownPlugins
          The known plugins.
 
Constructor Summary
PluginFactory(ILoader loader)
          Direct PluginFactory to use given Loader for loading Jar files.
 
Method Summary
 boolean appendPluginList(java.lang.String directory, java.lang.String entry)
          Append entry to end of Plugin Index.
 java.lang.String getEntry(java.lang.String directory, java.lang.String name)
          Returns entry for the given plugin.
 Solitaire instantiatePlugin(java.lang.String directory, java.lang.String solitaireName)
          Instantiate the given plugin, or return null if not found.
 boolean loadPluginList(java.lang.String directory)
          Load list of initial Plugins available on client.
 java.util.Enumeration plugins(java.lang.String directory)
          Returns Enumeration of Strings for local Plugins.
 boolean registerPlugin(java.lang.String directory, java.lang.String solitaireName)
          Register with PluginFactory that the given plugin is now available.
 boolean removePluginList(java.lang.String directory, java.lang.String pluginName)
          Remove plugin with given name from client repository.
 boolean setEntry(java.lang.String directory, java.lang.String name, java.lang.String entry)
          Set entry for the given plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

knownPlugins

protected java.util.Hashtable knownPlugins
The known plugins. Key=user_Game.jar, Value = String::keyValue (not yet loaded) or Class (loaded)

Constructor Detail

PluginFactory

public PluginFactory(ILoader loader)
Direct PluginFactory to use given Loader for loading Jar files.

Parameters:
loader -
Method Detail

appendPluginList

public boolean appendPluginList(java.lang.String directory,
                                java.lang.String entry)
Append entry to end of Plugin Index.

Within the directory is a file named IClientPluginManager.indexFile, whose format is described in the IClientPluginManager class. Based upon information from this file, this method appends a new entry to the file.

Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
entry - java.lang.String the EXACT entry (perfect formatting) to be appended.
Returns:
ks.games.Solitaire

getEntry

public java.lang.String getEntry(java.lang.String directory,
                                 java.lang.String name)
Returns entry for the given plugin.

The parameter "name" refers to the JarFile resident on the client's computer, and it must be of the form "user_Game.jar"; this method attempts to add a String entry to the plugin.idx file.

This method is called by the ClientPluginManager who may need to retrieve additional information with each plugin. If no entry exists, then "" is returned.

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
Returns:
boolean true if the plugin exists and the entry was successfully set

instantiatePlugin

public Solitaire instantiatePlugin(java.lang.String directory,
                                   java.lang.String solitaireName)
Instantiate the given plugin, or return null if not found.

The parameter "name" refers to the JarFile resident on the client's computer, and it must be of the form "user_Game.jar"; this method attempts to instantiate an object of class "user.Game".

Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
solitaireName - java.lang.String name of solitaire plugin [user_Game.jar]
Returns:
ks.games.Solitaire

loadPluginList

public boolean loadPluginList(java.lang.String directory)
Load list of initial Plugins available on client.

Within the directory is a file named IClientPluginManager.indexFile, whose format is described in the IClientPluginManager class. Based upon information from this file, this method loads up the set of available plug ins.

NOTE: An instance is only created when asked.

This method is called when client is initialized.

Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
Returns:
ks.games.Solitaire

plugins

public java.util.Enumeration plugins(java.lang.String directory)
Returns Enumeration of Strings for local Plugins.

This method first invokes loadPluginList() to ensure accurate information Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
Returns:
java.util.Enumeration

registerPlugin

public boolean registerPlugin(java.lang.String directory,
                              java.lang.String solitaireName)
Register with PluginFactory that the given plugin is now available.

The parameter "name" refers to the JarFile resident on the client's computer, and it must be of the form "user_Game.jar"; this method attempts to instantiate an object of class "user.Game".

This method is called by the ClientPluginManager upon successful download of the .jar file from the server.

Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
solitaireName - java.lang.String name of solitaire plugin [user_Game.jar]
Returns:
ks.games.Solitaire

removePluginList

public boolean removePluginList(java.lang.String directory,
                                java.lang.String pluginName)
Remove plugin with given name from client repository.

Within the directory is a file named IClientPluginManager.indexFile, whose format is described in the IClientPluginManager class. Based upon information from this file, this method removes the entry with the given name AND deletes the JAR file

NOTE: An instance is only created when asked.

This method is called when client is initialized.

Creation date: (12/8/01 12:15:17 AM)

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
pluginName - java.lang.String name of plug in [user_Game.jar]
Returns:
ks.games.Solitaire

setEntry

public boolean setEntry(java.lang.String directory,
                        java.lang.String name,
                        java.lang.String entry)
Set entry for the given plugin.

The parameter "name" refers to the JarFile resident on the client's computer, and it must be of the form "user_Game.jar"; this method attempts to add a String entry to the plugin.idx file.

This method is called by the ClientPluginManager who may need to store additional information with each plugin.

Parameters:
directory - java.lang.String where jar files are stored [NO SLASHES IN NAME]
Returns:
boolean true if the plugin exists and the entry was successfully set