standup.profiling
Interface Profileable

All Known Implementing Classes:
Backend, BackendJokeSetOnly, BackendJokeSetSQL, BackendSQL, CloudFrontend, LexicalComponents

public interface Profileable

A class that implements Profileable can be configured in various ways to alter its behaviour and functionality, and this configuration can be recorded as a user Profile.

For each implementation of Profileable, there must be a corresponding subclass of Profile. This is the subclass that is returned by the createProfile(File) and loadProfile(File) methods. For example, Backend uses the ProfileJokeGeneration class, whereas CloudFrontend uses the ProfileCloudFrontend class.

Probably the two most important methods are getProfile() and setProfile(Profile, boolean). The getProfile() method returns the currently used Profile, so should be called when attempting to find out the various option settings the current user has chosen. Conversely, the setProfile(Profile, boolean) method makes the given Profile the current used one.

Most of the methods defined here will be used by the ProfileManager class.

Author:
Ruli Manurung

Method Summary
 boolean createProfile(File directory)
          Instantiates a 'default' profile and saves it in the specified user directory.
 Profile getProfile()
          Returns the Profile currently being used by this Profileable.
 String getProfileFilename()
          Returns the filename used to specify the profile filename.
 Profile loadProfile(File directory)
          Loads the Profile associated with this Profileable from the specified directory and returns it.
 boolean setProfile(Profile profile, boolean repeat)
          Attempts to use the given Profile.
 

Method Detail

getProfileFilename

String getProfileFilename()
Returns the filename used to specify the profile filename. Since a user profile contains various separate Profiles, and they are all stored in the same user directory, the profile filenames must be unique. Convention is to use a .profile file extension, e.g. 'jokegeneration.profile', 'lexical.profile', 'clouds.profile', etc..

Returns:
the filename used to specify the profile file within the user directory

getProfile

Profile getProfile()
Returns the Profile currently being used by this Profileable.

Returns:
the currently used Profile

setProfile

boolean setProfile(Profile profile,
                   boolean repeat)
Attempts to use the given Profile.

The repeat parameter determines whether it is the first time a profile is being set for the current user during this session (e.g. from the login screen) or not (e.g. after changing options in the control panel). This allows the Profileable to perform initial-specific setup during the first time, e.g. for the SQL-based backend to reset the exclusion tables.

This is also the method where any transient data structures or variables that are dependent on the current profile should be updated.

Returns true if successful, false otherwise.

Parameters:
profile - The profile to be used
repeat - whether this is the first time a profile is being set for the current user during this session
Returns:
true if successful, false otherwise.

createProfile

boolean createProfile(File directory)
Instantiates a 'default' profile and saves it in the specified user directory. Assumes that the directory has been created, and is available from ProfileManager.getUserDirectory(String).

Returns:
true if succesfully created, false otherwise

loadProfile

Profile loadProfile(File directory)
Loads the Profile associated with this Profileable from the specified directory and returns it. Assumes that the directory has been created, and that it contains a file whose name is the same as that given by getProfileFilename(). Note that it doesn't actually use/set the returned Profile -- call setProfile(Profile, boolean) for that.

Really this should be a static method, but Java interfaces cannot specify static methods.

Parameters:
directory - The directory containing the profile (and associated files)
Returns:
returns the instantiated Profile