|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.starhope.appius.user.Nomenclator
public class Nomenclator
The Nomenclator is the universal factory and caché mechanism for all
game objects derived from DataRecord
, and provides facilities
for caching of arbitrary objects as well. The most common way to
obtain any game object is to call getDataRecord(Class, int)
or getDataRecord(Class, String)
, which will check caché for
an existing reference, or instantiate one from a data store (e.g.
database) automatically.
Field Summary | |
---|---|
private static ConcurrentSkipListSet<String> |
allCaches
an index of all cachés |
Constructor Summary | |
---|---|
Nomenclator()
|
Method Summary | ||
---|---|---|
static void |
assertLoginAvailable(String userNameRequested)
Make the assertion that the user name supplied is available to be requested or assigned to this user. |
|
static
|
cache(Class<StorageBaseClass> klass,
InstanceClass obj,
RecordClass rec)
Store an object into a caché in which the object is identified by a DataRecord instance object. |
|
static
|
cache(Class<T> klassGiven,
int id,
String ident,
T o)
Store an item into a caché, for which we've already extracted the object's identification string and integer values. |
|
static
|
cache(T record)
Store a DataRecord into the caché based upon its identifying string and integers. |
|
static
|
cache(T o,
String ident)
Store an arbitrary object in a caché. |
|
private static String |
cacheInfoToString(com.whirlycott.cache.CacheDecorator<?,?> cache)
put out caché info in string form |
|
static void |
clearCaches()
clear all cachés (possibly causing severe consistency problems) |
|
static AbstractUser |
create(Date date,
String string,
String nick)
Create a new user account |
|
static
|
findInCache(Class<T> klass,
int id)
Find an object in the caché, given its class and identifying integer. |
|
static
|
findInCache(Class<T> klass,
S rec)
Find an object in the caché, given its base storage class and a DataRecord which uniquely identifies it. |
|
static
|
findInCache(Class<T> klass,
String ident)
Find an object in the caché based upon a class and a string identifier. |
|
static
|
findInGenericCache(Class<T> klass,
String ident)
Find a generic object in a caché, without regards for the object's type. |
|
static AbstractUser |
get(org.json.JSONObject object)
Pick up a user from a JSON object containing either the ID or login (user name) string. |
|
static String |
getAllCacheInfo()
get information about all cachés |
|
static
|
getDataRecord(Class<T> klassGiven,
int id)
Obtain a data record (implementing DataRecord ) of the
given class, based upon its unique numeric identifier. |
|
static
|
getDataRecord(Class<T> klassGiven,
String identifier)
Get a data record by either searching the caché or loading it. |
|
static
|
getDataRecord(String klass,
int id)
get a data record given a string class name and an ID |
|
static
|
getDataRecord(String klass,
String ident)
get a data record given a specific class name string and identifier string |
|
static
|
getDataRecordIterator(Class<T> klass,
Object... constructorArgs)
get a data record iterator |
|
private static
|
getIDCache(Class<T> klassGiven)
get the caché for ID (integer) records of a given class (or gens) |
|
private static
|
getIdentCache(Class<T> klassGiven)
get the caché for objects of some kind based on their string identifier |
|
static int |
getIDForLiveUserName(String name)
Find the user name for a user who is currently signed on. |
|
private static AbstractUser |
getInstanceNPCByName(String instanceName)
Find a cached NPC |
|
static String |
getLoginForID(int id)
|
|
private static
|
getNomenGentile(Class<? extends T> klassGiven)
Get the nomen gentile of the class provided |
|
static AbstractUser |
getOnlineUserByLogin(String login)
get a user by their login, but *only* if they are currently online; pull only from live user sources, and not from the database. |
|
static Parent |
getParentByApprovalCookie(String cookie)
|
|
static Parent |
getParentByID(int id)
|
|
static Parent |
getParentByMail(String mail)
|
|
private static
|
getRecIDForBackedObject(S rec)
get a record ID for something that is in turn backed by some kind of data record |
|
private static
|
getRecordBackedCache(Class<T> klass)
Get a caché backed by a type of record |
|
private static
|
getSomeCache(Class<T> tClass,
String s,
Class<S> sClass)
get a caché containing records of a given type, with keys of another given type, using a given suffix code |
|
static AbstractUser |
getSystemUser()
Get the System user object (the user which represents the system program itself). |
|
static AbstractUser |
getUserByID(int id)
Instantiate a user object from an existing user account ID |
|
static AbstractUser |
getUserByLogin(String login)
|
|
static AbstractUser |
getUserByRequestedName(String userNameRequested)
Get the user who has requested a certain name, if any. |
|
static int |
getUserIDForLogin(String name)
Fetch the user ID number for a user name |
|
static AbstractUser[] |
getUsersByMail(String mail)
Returns an array of all users associated with a given eMail address. |
|
private static
|
initializeClassCache(Class<S> idClass,
Class<T> klass,
String ext)
WRITEME: Document this method brpocock@star-hope.org |
|
static
|
instantiate(Class<T> klass,
S record)
Instantiate an instance of an object which wraps a data record |
|
(package private) static AbstractUser |
instantiateUser(UserRecord rec)
Instantiate a User (using the selected subclass) from the result set garnered from a SELECT * |
|
static boolean |
isLoginAvailable(String name)
Determine whether the given name is potentially available for use. |
|
static boolean |
isLoginForbidden(String userNameRequested)
Determine whether a name is forbidden |
|
static
|
killCache(Class<S> klass,
T o)
Remove an arbitrary object from a caché. |
|
static
|
make(Class<T> klass,
Object... more)
WRITEME: Document this method brpocock@star-hope.org |
|
static void |
removeInstanceNPC(GeneralUser npc)
Remove an instanced NPC from the caché on its destruction. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static ConcurrentSkipListSet<String> allCaches
Constructor Detail |
---|
public Nomenclator()
Method Detail |
---|
public static void assertLoginAvailable(String userNameRequested) throws AlreadyUsedException, ForbiddenUserException
Make the assertion that the user name supplied is available to be requested or assigned to this user.
Note that having another user request the name, which has not been either permitted or denied, will still throw an AlreadyUsedException.
This routine returns void, because it throws exceptions if the
name is forbidden or already used. For a boolean version, see
(String)
userNameRequested
- The name which is being requested
AlreadyUsedException
- if the user name has been requested
or accepted already
ForbiddenUserException
- if the user name is forbidden from
use (obscene, gives away personal information, or so
forth). See (String)
public static <RecordClass extends DataRecord,StorageBaseClass extends DataRecordBacked<RecordClass>,InstanceClass extends StorageBaseClass> void cache(Class<StorageBaseClass> klass, InstanceClass obj, RecordClass rec)
DataRecordBacked
interface. The
representative class of the object must also be specified,
allowing “comparable” implementations of a common base class to
be stored in the same caché.
RecordClass
- The DataRecord identifying this object must
be a member of a class which extends DataRecord, of
course.StorageBaseClass
- The base class of which the object
being stored is either a member of, or a member of an
extending/implementing class thereof.InstanceClass
- The class of which the object is actually
an instance, which extends StorageBaseClass (or is
StorageBaseClass)klass
- The class identifier of the caché in which the
object is to be stored.obj
- The object to be stored in the cachérec
- The DataRecord uniquely identifying the object. The
identifiers of this DataRecord will be used as keys to
the caché.public static <T extends DataRecord> void cache(Class<T> klassGiven, int id, String ident, T o)
T
- The class of object (descended of DataRecord
)klassGiven
- The class of object (descended of
DataRecord
)id
- The numeric ID under which to caché the referenceident
- The string ID under which to caché the referenceo
- The object to be cachedpublic static <T extends DataRecord,S extends T> void cache(T record)
T
- the class of the record to be stored in the cachéS
- the class of the record to be stored in the cachérecord
- the record to be stored in the cachépublic static <T> void cache(T o, String ident)
DataRecord
nor an implementation of
DataRecordBacked
.
T
- The class of the arbitrary objecto
- An arbitrary object to be stored in the caché.ident
- A globally unique identifier, which should include
enough information to uniquely identify it among all
objects which might be stored.private static String cacheInfoToString(com.whirlycott.cache.CacheDecorator<?,?> cache) throws com.whirlycott.cache.CacheException
cache
- the caché to be interrogated
com.whirlycott.cache.CacheException
- if something goes awrypublic static void clearCaches() throws com.whirlycott.cache.CacheException
com.whirlycott.cache.CacheException
- if something goes wrongpublic static AbstractUser create(Date date, String string, String nick) throws AlreadyUsedException, ForbiddenUserException
date
- User's date of birthstring
- Character class or type designatornick
- User's requested nickname
AlreadyUsedException
- if the nickname is not available
ForbiddenUserException
- if the user account is not
permitted to be created, e.g. for having an obscene
user IDpublic static <T extends DataRecord> T findInCache(Class<T> klass, int id) throws NotFoundException
T
- The class of object being returnedklass
- The class of object to be returned, descended from
DataRecord
id
- The numeric ID under which to locate the object
NotFoundException
- If the object is not found in the
caché.public static <S extends DataRecord,T extends DataRecordBacked<S>> T findInCache(Class<T> klass, S rec) throws NotFoundException
DataRecord
which uniquely identifies it. Note that the
object itself will be guaranteed only to be a member of the
specified class or an extension or implementor thereof.
S
- The class of which the data record is an isstance or
an instance of a subclass thereofT
- The class of the object in the caché, which is backed
by and identified by the data recordklass
- The class of which the data record is an instance or
instance of a subclass thereofrec
- The data record to be used to identify the object
cached
NotFoundException
- If no such object can be found in the
caché.public static <T extends DataRecord> T findInCache(Class<T> klass, String ident) throws NotFoundException
T
- The class of objects to be searchedklass
- The class of objects to be searchedident
- The string identifier for the object to be found (or
not)
NotFoundException
)
NotFoundException
- if the object was not found in the
cachépublic static <T> T findInGenericCache(Class<T> klass, String ident) throws NotFoundException
NotFoundException
rather than forcing the caller to
perform a blind cast and try to catch runtime exceptions.
T
- The class of object expected to be foundklass
- The class of object expected to be foundident
- The (globally unique) identifier of the object
NotFoundException
instead
NotFoundException
- If the object is not in the caché; or,
if there is an object in the caché identified by
(parameter) “ident” which is not of the class “klass”
or a subclass or implementor thereof.public static AbstractUser get(org.json.JSONObject object)
object
- A JSON object with either an { id: userID } or {
login: userName }
public static String getAllCacheInfo() throws com.whirlycott.cache.CacheException
com.whirlycott.cache.CacheException
- if something goes awrypublic static <T extends DataRecord> T getDataRecord(Class<T> klassGiven, int id) throws NotFoundException
Obtain a data record (implementing DataRecord
) of the
given class, based upon its unique numeric identifier.
This method will attempt to locate a copy of the object in an
in-core caché prior to resorting to other factory methods, e.g.
RecordLoader
or so forth.
The ID value given is expected to be globally unique for all data
records of the given class. Note that this is most often an
SQL-backed DataRecord
, and the ID is generally an SQL row
identification. Also, typically, these ID's are expected to be
positive numbers. However, this method will cheerfully accept
negative ID's and attempt to locate the records.
T
- The class of which the data record is an instance (or
a subclass thereof)klassGiven
- The class of which the data record is an
instance (or a subclass thereof)id
- The unique identifier for the data record in question
NotFoundException
.
NotFoundException
- If the various factory methods
available cannot produce the data record requestedpublic static <T extends DataRecord> T getDataRecord(Class<T> klassGiven, String identifier) throws NotFoundException
getDataRecord(Class, int)
for contractual details.
T
- the class of the record (as per klass)klassGiven
- the class of the record to be loadedidentifier
- the name or something that uniquely identifies
the record to be found
NotFoundException
NotFoundException
- If the record in question cannot be
foundpublic static <T extends DataRecord> T getDataRecord(String klass, int id) throws NotFoundException, ClassNotFoundException
T
- the resultant class represented by “klass”klass
- string class nameid
- integer ID
NotFoundException
- if the object is not found
ClassNotFoundException
- if the class is not foundpublic static <T extends DataRecord> T getDataRecord(String klass, String ident) throws NotFoundException, ClassNotFoundException
T
- class thing to make compiler happyklass
- class name stringident
- identifier string
NotFoundException
- if the object can't be found
ClassNotFoundException
- if the class name isn't foundpublic static <T extends Iterator<? extends DataRecord>> T getDataRecordIterator(Class<T> klass, Object... constructorArgs)
T
- the class of iterator to be summonedklass
- the class of iterator to be summonedconstructorArgs
- arguments to be passed to the constructor
(which must accept the nomen gentile of the parameter
classes)
private static <T> com.whirlycott.cache.Cache<Integer,T> getIDCache(Class<T> klassGiven)
T
- class (or gens)klassGiven
- class
private static <T> com.whirlycott.cache.Cache<String,T> getIdentCache(Class<T> klassGiven)
T
- the class or gensklassGiven
- the class
public static int getIDForLiveUserName(String name)
name
- User name to look up
private static AbstractUser getInstanceNPCByName(String instanceName)
instanceName
- Name with login$instanceID
public static String getLoginForID(int id)
id
- The user ID value
private static <T> Class<T> getNomenGentile(Class<? extends T> klassGiven)
T
- type parameter to try to quiesce the compiler a bitklassGiven
- the specific class
public static AbstractUser getOnlineUserByLogin(String login)
login
- user's login
public static Parent getParentByApprovalCookie(String cookie) throws NotFoundException, IOException
cookie
- the approval cookie uniquely identifying the
desired Parent
NotFoundException
- if the cookie does not uniquely
identify any Parent
IOException
- if the contents of the approval cookie can't
be decodedpublic static Parent getParentByID(int id)
id
- database ID number
public static Parent getParentByMail(String mail)
mail
- The parent's eMail address
private static <S extends DataRecord> String getRecIDForBackedObject(S rec)
S
- type of the recordrec
- the record whose ID is to be extracted
private static <T> com.whirlycott.cache.Cache<String,T> getRecordBackedCache(Class<T> klass)
T
- the record type contained in the cachéklass
- the record type contained in the caché
private static <T,S> com.whirlycott.cache.Cache<S,T> getSomeCache(Class<T> tClass, String s, Class<S> sClass)
T
- the type contained within the cachéS
- the type of keystClass
- the type contained within the cachés
- the suffix code appended to sClass
- the type of keys
public static AbstractUser getSystemUser()
public static AbstractUser getUserByID(int id)
id
- The user ID to instantiate
public static AbstractUser getUserByLogin(String login)
login
- the user login name
public static AbstractUser getUserByRequestedName(String userNameRequested)
userNameRequested
- the user name for which we're searching
public static int getUserIDForLogin(String name)
name
- The user name (login)
public static AbstractUser[] getUsersByMail(String mail)
mail
- The eMail address for which we are searching
private static <S,T> com.whirlycott.cache.Cache<S,T> initializeClassCache(Class<S> idClass, Class<T> klass, String ext)
S
- class of IDT
- WRITEMEidClass
- class of IDklass
- WRITEMEext
- WRITEME
public static <T extends DataRecordBacked<S>,S extends DataRecord> T instantiate(Class<T> klass, S record)
T
- the type of object which is backed by the given
record. An object of this type, or possible an
extension subclass specified in the configuration
file, will be returned.S
- the type of data record which is passed inklass
- The class of T, to be instantiatedrecord
- The record to be used to instantiate the new object
static AbstractUser instantiateUser(UserRecord rec)
rec
- The given database record
public static boolean isLoginAvailable(String name)
name
- The user name being checked
public static boolean isLoginForbidden(String userNameRequested)
... A user name is “forbidden” if it matches a negative filter (if it contains forbidden word(s) or phrase(s)), or if it has previously been banned for some reason
userNameRequested
- The name to be checked
public static <S extends DataRecord,T extends S> void killCache(Class<S> klass, T o)
Remove an arbitrary object from a caché.
FIXME: Does not work!
S
- WRITEMET
- The class of the arbitrary objectklass
- WRITEMEo
- An arbitrary object to be stored in the caché.public static <T extends DataRecord> T make(Class<T> klass, Object... more) throws NotReadyException
T
- WRITEMEklass
- WRITEMEmore
- WRITEME
NotReadyException
- WRITEMEpublic static void removeInstanceNPC(GeneralUser npc)
AbstractNonPlayerCharacter.destroy()
npc
- the character to be destroyed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |