|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object standup.profiling.ProfileManager
public class ProfileManager
The main class that should be used to create, retrieve, and save user profiles.
All methods in ProfileManager
are static
, so there is never
a need to create an instantiation. It is the responsibility of the code that
uses the ProfileManager
to ensure that it has been initialized before
usage. This is done by calling one of the various #initialize()
methods.
The general usage of the ProfileManager
is as follows:
ProfileManager
by calling either
initialize()
, initialize(File)
, or
#initialize(File, File, File)
.
createUser(String, Profileable)
.
Profileable
object to use the appropriate profile by
calling useProfile(String, Profileable)
.
saveCurrentProfile(Profileable)
.
Field Summary | |
---|---|
private static String |
currentUserName
|
private static File |
defaultBaseDataDir
|
private static boolean |
initialized
Indicates whether this ProfileManager has been initialized yet. |
static String |
loginProfileName
|
private static File |
optionsPackageDirectory
|
private static File |
userRootDirectory
|
Constructor Summary | |
---|---|
ProfileManager()
|
Method Summary | |
---|---|
static boolean |
addFrontendLoginProfile(Profile loginFrontendProfile)
Tries to create the 'login' user profile, and adds the given Profile , assumed to be a ProfileCloudFrontend as
'clouds.profile'; |
static String |
chooseProfileName(Component wholePane)
A utility method that brings up a JOptionPane input dialog that
can be used to select a profile name from the list of available profiles. |
private static void |
copyCustomLexiconFromJAR(File userLexiconDirectory,
String name)
Copies the custom lexicon with the given name from within the STANDUP jar (from /standup/resources/xml ) into the user's lexicon directory. |
private static void |
copyCustomLexiconFromJAR(File userLexiconDirectory,
String jarName,
String newName)
Copies the custom lexicon with the given jarName from within the
STANDUP jar (from /standup/resources/xml ) into the user's
lexicon directory as newName . |
private static void |
copyTopicFromJAR(File userLexiconDirectory,
String name)
Copies the topic with the given name from within the STANDUP jar (from /standup/resources/xml ) into the user's lexicon directory. |
private static void |
copyTopicFromJAR(File userLexiconDirectory,
String jarName,
String newName)
Copies the topic with the given jarName from within the STANDUP
jar (from /standup/resources/xml ) into the user's lexicon
directory as newName . |
static boolean |
createDefaultLexicons(String username)
Copies over various topics and custom lexicons from within the STANDUP jar (from /standup/resources/xml ) into the given user's lexicon
directory. |
static void |
createUser(String name)
Creates a user and logfile directory for the user with the given name. |
static void |
createUser(String name,
Profileable profileable)
Creates a user directory for the user with the given name, and creates in it a default profile for the given Profileable . |
static String |
getCurrentUserName()
Returns the name of the 'current' user, i.e. |
static File |
getDefaultOptionsPackage()
Returns the default options package file. |
static File |
getLexiconDirectory(String name)
Returns the lexicon directory for the user with the given name. |
static File |
getLogDirectory(String name)
Returns the logfile directory for the user with the given name. |
static List<String> |
getNamesList()
Returns a List<String> of users for whom there are existing
Profile s. |
static File |
getOptionsDirectory()
Returns the designated directory for options packages. |
static File |
getUserDirectory(String name)
Returns the profile directory for the user with the given name. |
static void |
initialize()
Sets up the necessary directories for loading and saving user profiles. |
static void |
initialize(File baseDir)
Sets up the necessary directories for loading and saving user profiles. |
static void |
initialize(File userDir,
File optionsDir)
Sets up the necessary directories for loading and saving user profiles. |
static boolean |
profileExists(String name,
Profileable profileable)
Returns true if the profile associated with the given
Profileable for the user with the given name exists,
false otherwise. |
static boolean |
quickSaveCurrentProfile(Profileable profileable)
Saves the profile associated with the given Profileable for the
current user. |
private static Profileable |
reflectionBackendGetLexicalComponents(Profileable assumedBackend)
|
private static Profileable |
reflectionFrontendGetBackend(Profileable assumedFrontend)
|
static boolean |
saveCurrentProfile(Profileable profileable)
Saves the profile associated with the given Profileable for the
current user, and any other auxiliary files that make up the profile. |
static void |
useProfile(String name,
Profileable profileable)
Syntactic sugar for the 'cascaded' useProfile(String, Profileable, boolean) method -- assumes
'first time' every time. |
static void |
useProfile(String name,
Profileable[] profileables)
Syntactic sugar for the 'non-cascaded' useProfile(String, Profileable[], boolean) method -- assumes
'first time' every time. |
static void |
useProfile(String name,
Profileable[] profileables,
boolean repeat)
An alternative method for using a user profile. |
static boolean |
useProfile(String name,
Profileable[] profileables,
Profile[] profiles,
boolean repeat)
Alternative method of using profiles, where the Profile s
themselves are provided as parameters, instead of being read from disk. |
static void |
useProfile(String name,
Profileable profileable,
boolean repeat)
The preferred method for using a user profile. |
static boolean |
userExists(String name)
Returns true if the profile directory for the user with the given
name exists, false otherwise. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String loginProfileName
private static final File defaultBaseDataDir
private static File userRootDirectory
private static File optionsPackageDirectory
private static String currentUserName
private static boolean initialized
ProfileManager
has been initialized yet.
initialize()
,
initialize(File)
,
#initialize(File, File, File)
Constructor Detail |
---|
public ProfileManager()
Method Detail |
---|
public static void initialize() throws ProfileException
This method uses the following defaults, where .
is the directory
where the standup.jar
is located:
./standupdata/users
./standupdata/options
ProfileException
public static void initialize(File baseDir) throws ProfileException
This method uses the following defaults, where .
is the directory
specified by baseDir
:
./users
./options
baseDir
- the base directory
ProfileException
public static void initialize(File userDir, File optionsDir) throws ProfileException
ProfileException
.
Does *NOT* create the default 'login profile' for CloudFrontend, so call
addFrontendLoginProfile(Profile)
if necessary.
userDir
- the directory that contains the various user profile
directoriesoptionsDir
- the directory that contains the various user options packages
ProfileException
public static boolean createDefaultLexicons(String username) throws ProfileException
/standup/resources/xml
) into the given user's lexicon
directory.
It creates:
topicdb_fc1.topic
-topicdb_fc5.topic
: complete
topics, for FClass.fc1
to FClass.fc5
.
customlex_fc1.topic
-customlex_fc5.topic
: lexemes
not included in the above topics, for FClass.fc1
to
FClass.fc5
.
default.topic
: a copy of topicdb_fc*.topic
above,
where the fclass used is determined by
CommandLineArguments.KEY_FCLASS
(default = fc5).
default.lexicon
: if
CommandLineArguments.KEY_EMPTYLEX
is "yes"
, an empty
custom lexicon, else, a copy of customlex_fc*.topic
above, where
the fclass used is determined by CommandLineArguments.KEY_FCLASS
(default = fc5).
default.blacklist
: an empty blacklist.
NOTE: If it fails to find the 'full' resources in the jar, it
will try to load the "jokeonly_"
variants, i.e. subsets of the
above resources that are intersected with the set of lexemes known to
yield jokes at the schema level (see database construction document for
more details).
username
-
ProfileException
private static void copyTopicFromJAR(File userLexiconDirectory, String name)
/standup/resources/xml
) into the user's lexicon directory. If it
can't find the file in the jar, it will try the "jokeonly_"
variant, i.e. the version included in the joke generation API and STANDUP
system jars.
userLexiconDirectory
- name
- private static void copyTopicFromJAR(File userLexiconDirectory, String jarName, String newName)
jarName
from within the STANDUP
jar (from /standup/resources/xml
) into the user's lexicon
directory as newName
. If it can't find the file in the jar, it
will try the "jokeonly_"
variant, i.e. the version included in
the joke generation API and STANDUP system jars.
userLexiconDirectory
- jarName
- newName
- private static void copyCustomLexiconFromJAR(File userLexiconDirectory, String name)
/standup/resources/xml
) into the user's lexicon directory.
If it can't find the file in the jar, it will try the "jokeonly_"
variant, i.e. the version included in the joke generation API and STANDUP
system jars.
userLexiconDirectory
- name
- private static void copyCustomLexiconFromJAR(File userLexiconDirectory, String jarName, String newName)
jarName
from within the
STANDUP jar (from /standup/resources/xml
) into the user's
lexicon directory as newName
. If it can't find the file in the
jar, it will try the "jokeonly_"
variant, i.e. the version
included in the joke generation API and STANDUP system jars.
userLexiconDirectory
- jarName
- newName
- public static boolean addFrontendLoginProfile(Profile loginFrontendProfile) throws ProfileException
Profile
, assumed to be a ProfileCloudFrontend
as
'clouds.profile';
loginFrontendProfile
-
true
if successful, or false
if the login profile
is found to already exist
ProfileException
public static File getOptionsDirectory() throws ProfileException
ProfileException
public static File getDefaultOptionsPackage() throws ProfileException
ProfileException
public static File getUserDirectory(String name) throws ProfileException
name
-
ProfileException
public static File getLogDirectory(String name) throws ProfileException
name
-
ProfileException
public static File getLexiconDirectory(String name) throws ProfileException
name
-
ProfileException
public static boolean userExists(String name) throws ProfileException
true
if the profile directory for the user with the given
name exists, false
otherwise.
name
-
ProfileException
public static boolean profileExists(String name, Profileable profileable) throws ProfileException
true
if the profile associated with the given
Profileable
for the user with the given name exists,
false
otherwise.
name
- profileable
-
ProfileException
public static List<String> getNamesList() throws ProfileException
List<String>
of users for whom there are existing
Profile
s.
ProfileException
public static String getCurrentUserName()
#useProfile
method was called.
public static void createUser(String name) throws ProfileException
name
- the name of the user for whom the profile directory is being
created
ProfileException
private static Profileable reflectionFrontendGetBackend(Profileable assumedFrontend)
private static Profileable reflectionBackendGetLexicalComponents(Profileable assumedBackend)
public static void createUser(String name, Profileable profileable) throws ProfileException
Profileable
. Additionally, it
performs a 'cascading' creation of default profiles with the following
dependencies:
CloudFrontend -> Backend -> LexicalComponentsFor example, given a
CloudFrontend
, it will create a profile for
CloudFrontend
, Backend
, and LexicalComponents
.
This is a convenience method which is probably what is needed most of the
time. For more specialized requirements (e.g. the CloudFrontend
"login" profile, which doesn't have a joke generation profile), consider
using #createUser(String)
coupled with manual calling of
Profileable#createProfile(File)
.
NOTE: this method 'hardcodes' the dependency above and uses some
rather hacky Java reflection methods to implement it without actually
importing the relevant classes -- this is to ensure that the joke
generator API works without needing standup.clouds, and the lexicon API
works without needing standup.joke, etc. It makes quite a few assumptions
about class names, e.g. "standup.clouds.CloudFrontend",
"standup.joke.Backend*", and "standup.lexicon.LexicalComponents", etc.
name
- the name of the user for whom the profile directory is being
createdprofileable
- the Profileable
for which all required Profile
s
will be created
ProfileException
public static void useProfile(String name, Profileable profileable) throws ProfileException
useProfile(String, Profileable, boolean)
method -- assumes
'first time' every time.
name
- profileable
-
ProfileException
public static void useProfile(String name, Profileable[] profileables) throws ProfileException
useProfile(String, Profileable[], boolean)
method -- assumes
'first time' every time.
name
- profileables
-
ProfileException
public static void useProfile(String name, Profileable profileable, boolean repeat) throws ProfileException
Profileable
found in the
directory for the given user.
Additionally, it performs a 'cascading' use of required profiles with the following dependency:
CloudFrontend -> Backend -> LexicalComponentsFor example, given a
CloudFrontend cf
, it will load the profile
for cf.getBackend()
and also
cf.getBackend().getLexicalComponents()
.
The repeat
parameter determines whether this is the first time
useProfile
is being called for the given user during this session
(e.g. from the login screen) or not (e.g. after changing options in the
control panel).
Finally, it sets the given user name as the 'current user' name.
This is a convenience method which is probably what is needed most of the
time. For more specialized requirements (e.g. the CloudFrontend
"login" profile, which doesn't have a joke generation profile), consider
using #useProfile(String,Profileable[],boolean)
instead.
NOTE: this method 'hardcodes' the dependency above and uses some
rather hacky Java reflection methods to implement it without actually
importing the relevant classes -- this is to ensure that the joke
generator API works without needing standup.clouds, and the lexicon API
works without needing standup.joke, etc. It makes quite a few assumptions
about class names, e.g. "standup.clouds.CloudFrontend",
"standup.joke.Backend*", and "standup.lexicon.LexicalComponents", etc.
name
- profileable
- repeat
-
ProfileException
public static void useProfile(String name, Profileable[] profileables, boolean repeat) throws ProfileException
Profileable
s found in the
directory for the given user, but does not do the 'cascading' use of
dependent profiles that useProfile(String, Profileable, boolean)
performs.
The repeat
parameter determines whether this is the first time
useProfile
is being called for the given user during this session
(e.g. from the login screen) or not (e.g. after changing options in the
control panel).
Finally, it sets the given user name as the 'current user' name.
name
- profileables
- an array of Profileable
s that are to use the user's
profilerepeat
-
ProfileException
public static boolean useProfile(String name, Profileable[] profileables, Profile[] profiles, boolean repeat) throws ProfileException
Profile
s
themselves are provided as parameters, instead of being read from disk.
This is used, for example, by PlaybackTool
, where the
Profile
s are obtained from the log file. It still checks,
however, for the presence of the appropriate profile directories and
files, and returns false if they don't exist.
name
- profileables
- profiles
- repeat
-
ProfileException
public static boolean saveCurrentProfile(Profileable profileable) throws ProfileException
Profileable
for the
current user, and any other auxiliary files that make up the profile.
profileable
-
ProfileException
public static boolean quickSaveCurrentProfile(Profileable profileable) throws ProfileException
Profileable
for the
current user.
profileable
-
ProfileException
public static String chooseProfileName(Component wholePane) throws ProfileException
JOptionPane
input dialog that
can be used to select a profile name from the list of available profiles.
ProfileException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |