Class ClientFramework


The ClientFramework is the core class for the client side of the P2P Application Framework. The ClientFramework provides a number of utility methods that can be accessed by plug-ins.


Public Method Summary
 java.lang.Object BytesToObject(byte[] data)
           
 ResourceTemplate CreateResourceTemplate(int plugin, int resource, int media, java.lang.String name, java.lang.String description)
           
 java.util.HashMap DecodeAudio(java.lang.String EncodedSound, java.lang.String filetype)
           
 java.util.HashMap DecodePicture(java.lang.String EncodedImage, java.lang.String filetype)
           
 java.lang.String Encode(java.lang.String PicLocation)
           
 java.util.Vector GetContactList()
           
 java.lang.String GetDownloadLocation()
           
 MediaType GetMediaType(int id)
           
 int GetNumberOfPlugins()
           
 java.lang.String GetPeerAdvert(java.lang.String name, java.lang.String id)
           
 java.lang.String GetPluginsPath()
           
 java.lang.String GetServerID()
           
 java.util.Vector GetUsableMediaTypes()
           
 User GetUser()
           
 void MakeTransferRequest(java.lang.String filename, java.lang.String SaveAsFilename, int plugin, java.lang.String sourceid, int sourceplugin, boolean visible, boolean absolute)
           
 void MakeTransferRequest(java.lang.String filename, int plugin, java.lang.String sourceid, int sourceplugin, boolean visible, boolean absolute)
           
 byte[] ObjectToBytes(java.lang.Object o)
           
 java.lang.String ObjectToString(java.lang.Object o)
           
 void ResourceSearch(int pluginid, int mediatype, java.lang.String nickname, java.lang.String uniqueid, java.lang.String keywords)
           
 void ResourcesUpdate(java.util.Vector resources, int operation)
           
 long SendMessage(java.lang.String targetid, java.util.HashMap messageparts, java.awt.Component listener)
           
 java.lang.Object StringToObject(java.lang.String s)
           
 
Method Detail

GetMediaType

public MediaType GetMediaType(int id)

This method returns the MediaType instance that corresponds to the provided MediaType ID.

id - the MediaType ID of the MediaType instance that the plug-in desires


GetUsableMediaTypes

public java.util.Vector GetUsableMediaTypes()

This method returns a Vector containing instances of all the MediaTypes that this peer can handle.


GetPluginsPath

public java.lang.String GetPluginsPath()

This method returns the path location of the Plugins directory within the ClientFramework. Currently the returned path is only a relative path.


GetDownloadLocation

public java.lang.String GetDownloadLocation()

This method returns the path location of the directory in which downloaded files are stored. This path is set within then ClientFramework and could be relative or absolute.


ResourceSearch

public void ResourceSearch(int pluginid,
                           int mediatype,
                           java.lang.String nickname,
                           java.lang.String uniqueid,
                           java.lang.String keywords)

This method performs a resource search on the network (essentially it contacts the server). The search is performed asynchronously, and so the calling plug-in should not wait for the results. When the results have arrived the framework will call the SearchResults() method within the plug-in.

pluginid - the ID of the plug-in that is requesting the search
mediatype - the ID of the MediaType that is being searched for
nickname - the nickname of the user who possess the resources that are being searched for (for example, 'search for all resources that are being provided by James')
uniqueid - the unique ID of the user who possess the resources that are being searched for
keywords - any keywords that will be searched for in the resources name and description fields


ObjectToBytes

public byte[] ObjectToBytes(java.lang.Object o)

This utility method converts a provided Object into a byte array. This can be useful for storing data within certain types of database (for example, MySQL).

o - the Object that is to be converted


BytesToObject

public java.lang.Object BytesToObject(byte[] data)

This utility method converts a provided byte array into an Object.

data - the byte array that is to be converted


GetUser

public User GetUser()

This method returns a User object that represents the current user of this peer


GetContactList

public java.util.Vector GetContactList()

This method returns a Vector of UserObject's that represents the users that currently exist on the Contact List.


GetServerID

public java.lang.String GetServerID()

This method returns the IDfor the server peer within the framework. This would typically be used when a plug-in needs to communicate with its server counterpart.

An example of it in use would be:

ClientInstance.SendMessage(ClientInstance.GetServerID(), Message);


GetPipeAdvert

public java.lang.String GetPipeAdvert(java.lang.String name,
                                      java.lang.String id)

This method returns the Pipe Advert for the specified user (that satisfies the provided parameters).

name - the nickname of the user
id - the unique ID of the user


SendMessage

public long SendMessage(java.lang.String targetid,
                        java.util.HashMap messageparts,
                        java.awt.Component listener)

This method is used by plug-ins to send messages through the network. When the framework receives a message for a plug-in the MessageArrived() method within that plug-in is called.

target - the ID for the target user/peer
messageparts - a HashMap that contains the message elements
listener - not currently used

The long value that is returned represents the ID that the framework has assigned the message. This can be used by a plug-in to check if the message was successfully sent. See the SentMessage method within the PluginInterface.


Encode

public java.lang.String Encode(java.lang.String Location)

This utility method allows plug-ins to encode files to a String Base64 encoding (suitable for sending as part of a message). The location of the file is provided, the method then loads the file, converts it and returns the conversion as a String. Currently support is only provided or the decoding of Audio and Image files.

Location - the full path of the file to be converted


DecodeAudio

public java.util.HashMap DecodeAudio(java.lang.String EncodedSound,
                                     java.lang.String filetype)

This utility method allows plug-ins to decode a Base64 String back to an AudioClip object. The encoded string and the filetype of the audio file is provided. The method then converts the string back to an audio file, and also returns it as an AudioClip object (as part of the HashMap).

EncodedSound - the encoded String that is to be converted
filetype - the filetype of the audio file (for example, mp3)

The HashMap that is returned by this method contains two elements (Keys):

Sound - an AudioClip instance of the sound
Location - the full path of the audio file. It should be noted that decoded files are only kept temporarily. The next time the ClientFramework is started up, they will be deleted.

Example,

HashMap hashmap = DecodeAudio(encodedstring, "mp3");
AudioClip ac = (AudioClip) hashmap.get("Sound");


DecodePicture

public java.util.HashMap DecodePicture(java.lang.String EncodedImage,
                                       java.lang.String filetype)

This utility method allows plug-ins to decode a Base64 String back to an Image object. The encoded string and the filetype of the image file is provided. The method then converts the string back to an image file, and also returns it as an Image object (as part of the HashMap).

EncodedImage - the encoded String that is to be converted
filetype - the filetype of the image file (for example, jpeg)

The HashMap that is returned by this method contains two elements (Keys):

Image - an Image instance of the picture
Location - the full path of the Image file. It should be noted that decoded files are only kept temporarily. The next time the ClientFramework is started up, they will be deleted.

Example,

HashMap hashmap = DecodePicture(encodedstring, "jpeg");
Image im = (Image) hashmap.get("Image");


ObjectToString

public java.lang.String ObjectToString(java.lang.Object o)

This utility method allows plug-ins to convert an Object to a String. Created Strings are Base64 encoded so they can be sent as part of a message.

o - Object that is to be converted


StringToObject

public java.lang.Object StringToObject(java.lang.String s)

This utility method allows plug-ins to convert a String back to an Object.

s - the String that is to be converted.


ResourcesUpdate

public void ResourcesUpdate(java.util.Vector resources,
                            int operation)

This method allows a plug-in to update the resource details that it is making available to the rest of the network. The Vector that is supplied should be comprised of ResourceTemplate instances. The operation parameter determines whether the specified resources should be added, updated or deleted.

resources - a Vector of ResourceTemplate instances
operation - what operation should be performed on these resources. 0 = Delete, 1 = Add, 2 = Update


CreateResourceTemplate

public ResourceTemplate CreateResourceTemplate(int plugin,
                                               int resource,
                                               int media,
                                               java.lang.String name,
                                               java.lang.String description)

This method allows a plug-in to create ResourceTemplate objects. 

plugin - the ID of the plug-in that is creating the ResourceTemplate
resource - the ID of the resource that is being created (in may not be necessary to provide an ID for the resource, in which case just use the value 0)
media - the ID of the MediaType that this resource represents
name - the name of the resource (in some case the name of the resource will also act as the resources ID)
description - a brief description of the resource


MakeTransferRequest

public void MakeTransferRequest(java.lang.String filename,
				java.lang.String saveAsFilename,
                                int plugin,
                                java.lang.String sourceid,
				int sourceplugin,
                                boolean visible,
                                boolean absolute)

This method allows a plug-in to initiate a file transfer. File transfers are handled asynchronously and so the plug-in should not wait for a response. The file transfer itself is handled by the framework.

filename - the filename of the file that the plug-in is requesting. This could use be the filename, or the full path. If it is the full path then absolute should be true.
saveAsFilename - what you want the requested file to be saved as on the requesters peer
plugin - the ID of the plug-in that is making the request
sourceid - the ID of the user/peer that is providing the file that is to be transferred (i.e., the source)
sourceplugin - the ID of the plug-in that is providing the file that is to be transferred (i.e., the source)
visible - whether Dowload progress dialog boxes should be displayed or not
absolute - whether the filename is a complete path. If this is set to false, then the files will be downloaded from a default location (as set in the FileSharingPlugin)

The outcome of a file transfer is handled by a call of the plug-ins FileTransferSuccess() method.

If the file transfer can not be performed for any reason (for example, there are no ports available at the target peer), the framework will send the plug-in a message which should be listened for in the plug-ins MessageReceived method. The contents of this returned message would be:

Message Attribute                Value
TYPE                         :    NOTRANSFER
PLUGIN                    :    The ID of the plug-in who originally made the request
FILENAME               :    The filename that was subject of the transfer request
TARGETID               :     The ID of the client that possesses the file    


MakeTransferRequest

public void MakeTransferRequest(java.lang.String filename,
                                int plugin,
                                java.lang.String sourceid,
				int sourceplugin,
                                boolean visible,
                                boolean absolute)

This method allows a plug-in to initiate a file transfer. File transfers are handled asynchronously and so the plug-in should not wait for a response. The file transfer itself is handled by the framework.

filename - the filename of the file that the plug-in is requesting. This could use be the filename, or the full path. If it is the full path then absolute should be true.
plugin - the ID of the plug-in that is making the request
sourceid - the ID of the user/peer that is providing the file that is to be transferred (i.e., the source)
sourceplugin - the ID of the plug-in that is providing the file that is to be transferred (i.e., the source)
visible - whether Dowload progress dialog boxes should be displayed or not
absolute - whether the filename is a complete path. If this is set to false, then the files will be downloaded from a default location (as set in the FileSharingPlugin)

The outcome of a file transfer is handled by a call of the plug-ins FileTransferSuccess() method.

If the file transfer can not be performed for any reason (for example, there are no ports available at the target peer), the framework will send the plug-in a message which should be listened for in the plug-ins MessageReceived method. The contents of this returned message would be:

Message Attribute                Value
TYPE                         :    NOTRANSFER
PLUGIN                    :    The ID of the plug-in who originally made the request
FILENAME               :    The filename that was subject of the transfer request
TARGETID               :     The ID of the client that possesses the file