java.io.Serializablepublic class ClassLister
extends java.lang.Object
implements java.io.Serializable
getSingleton() method is not allowed to be called from
static {...} blocks in classes that are managed by the
ClassLister class (and therefore the ClassLocator class). Since the
ClassLocator class loads classes into the JVM, the static {...}
block of these classes gets executed and the ClassLister gets initialized
once again. In this case, the previous singleton will most likely get
overwritten.
// initialize the class lister
Properties pkges = ...; // class hierarchies
Properties blacklist = ...; // any blacklisted classes
ClassLister lister = ClassLister.getSingleton();
lister.setPackages(pkges);
lister.setBlacklist(blacklist);
lister.initialize();
// use class lister
Class[] classes = lister.getClasses("my.SuperClass");
| Modifier and Type | Field | Description |
|---|---|---|
protected java.util.Properties |
m_Blacklist |
the properties with the blacklisted classes.
|
protected java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.Class>> |
m_CacheClasses |
the cache (superclass/classes).
|
protected java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> |
m_CacheNames |
the cache (superclass/classnames).
|
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> |
m_ListClasses |
the list (superclass/classes).
|
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> |
m_ListNames |
the list (superclass/classnames).
|
protected java.util.logging.Logger |
m_Logger |
the logger in use.
|
protected boolean |
m_OnlyDefaultConstructor |
whether to allow only classes with the default constructor.
|
protected boolean |
m_OnlySerializable |
whether to allow only serializable classes.
|
protected java.util.Properties |
m_Packages |
the properties (superclass/packages).
|
protected static ClassLister |
m_Singleton |
the singleton.
|
| Modifier | Constructor | Description |
|---|---|---|
protected |
ClassLister() |
Initializes the classlister.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addHierarchy(java.lang.String superclass,
java.lang.String[] packages) |
Adds/appends a class hierarchy.
|
java.lang.Class[] |
getClasses(java.lang.Class superclass) |
Returns all the classs that were found for this superclass.
|
java.lang.Class[] |
getClasses(java.lang.String superclass) |
Returns all the classes that were found for this superclass.
|
protected ClassLocator |
getClassLocator() |
Returns the
ClassLocator instance to use. |
java.lang.String[] |
getClassnames(java.lang.Class superclass) |
Returns all the classnames that were found for this superclass.
|
java.util.logging.Logger |
getLogger() |
Returns the logger in use.
|
java.util.Properties |
getPackages() |
Returns the superclass-packages relation.
|
java.lang.String[] |
getPackages(java.lang.Class superclass) |
Returns all the packages that were found for this superclass.
|
java.lang.String[] |
getPackages(java.lang.String superclass) |
Returns all the packages that were found for this superclass.
|
static ClassLister |
getSingleton() |
Returns the singleton instance of the class lister.
|
java.lang.String[] |
getSuperclasses() |
Returns the all superclasses that define class hierarchies.
|
java.lang.String[] |
getSuperclasses(java.lang.Class cls) |
Returns the superclasses that the specified classes was listed under.
|
java.lang.String[] |
getSuperclasses(java.lang.String cls) |
Returns the superclasses that the specified classes was listed under.
|
void |
initialize() |
loads the props file and interpretes it.
|
boolean |
isLoggingEnabled() |
Returns whether logging is enabled.
|
boolean |
isOnlyDefaultConstructor() |
Returns whether to allow only classes with default constructor.
|
boolean |
isOnlySerializable() |
Returns whether to allow only serializable classes.
|
static java.util.Properties |
load(java.lang.String props) |
Loads the properties from the classpath.
|
static java.util.Properties |
load(java.lang.String props,
java.util.Properties defProps) |
Loads the properties from the classpath.
|
void |
setBlacklist(java.util.Properties value) |
Sets the properties with the blacklisted classes.
|
void |
setOnlyDefaultConstructor(boolean value) |
Sets whether to allow only classes with default constructor.
|
void |
setOnlySerializable(boolean value) |
Sets whether to allow only serializable classes.
|
void |
setPackages(java.util.Properties value) |
Sets the properties with the superclass/packages relation.
|
java.lang.String |
toString() |
Only prints the generated props file with all the classnames, based on
the package names for the individual packages.
|
protected void |
updateClasses(java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.Class>> cache,
java.lang.String superclass,
java.util.HashSet<java.lang.Class> names) |
Updates cache for the superclass.
|
protected void |
updateClasses(java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> list,
java.lang.String superclass,
java.util.List<java.lang.Class> classes) |
Updates list for the superclass.
|
protected void |
updateClassnames(java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> cache,
java.lang.String superclass,
java.util.HashSet<java.lang.String> names) |
Updates cache for the superclass.
|
protected void |
updateClassnames(java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> list,
java.lang.String superclass,
java.util.List<java.lang.String> names) |
Updates list for the superclass.
|
protected transient java.util.logging.Logger m_Logger
protected java.util.Properties m_Packages
protected java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> m_CacheNames
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> m_ListNames
protected java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.Class>> m_CacheClasses
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> m_ListClasses
protected java.util.Properties m_Blacklist
protected boolean m_OnlyDefaultConstructor
protected boolean m_OnlySerializable
protected static ClassLister m_Singleton
public boolean isLoggingEnabled()
public java.util.logging.Logger getLogger()
public void setOnlyDefaultConstructor(boolean value)
value - true if only default allowedpublic boolean isOnlyDefaultConstructor()
public void setOnlySerializable(boolean value)
value - true if only serializablepublic boolean isOnlySerializable()
public void setPackages(java.util.Properties value)
value - the propertiespublic void setBlacklist(java.util.Properties value)
value - the propertiesprotected void updateClassnames(java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.String>> cache,
java.lang.String superclass,
java.util.HashSet<java.lang.String> names)
cache - the cache to updatesuperclass - the superclassnames - the names to addprotected void updateClassnames(java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> list,
java.lang.String superclass,
java.util.List<java.lang.String> names)
list - the list to updatesuperclass - the superclassnames - the names to addprotected void updateClasses(java.util.HashMap<java.lang.String,java.util.HashSet<java.lang.Class>> cache,
java.lang.String superclass,
java.util.HashSet<java.lang.Class> names)
cache - the cache to updatesuperclass - the superclassnames - the names to addprotected void updateClasses(java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> list,
java.lang.String superclass,
java.util.List<java.lang.Class> classes)
list - the list to updatesuperclass - the superclassclasses - the names to addprotected ClassLocator getClassLocator()
ClassLocator instance to use.public void addHierarchy(java.lang.String superclass,
java.lang.String[] packages)
superclass - the superclasspackages - the packagespublic void initialize()
public java.lang.String[] getClassnames(java.lang.Class superclass)
superclass - the superclass to return the derived classes forpublic java.lang.Class[] getClasses(java.lang.Class superclass)
superclass - the superclass to return the derived classes forpublic java.lang.Class[] getClasses(java.lang.String superclass)
superclass - the superclass to return the derived classes forpublic java.lang.String[] getSuperclasses(java.lang.Class cls)
cls - the class to look up its superclassespublic java.lang.String[] getSuperclasses(java.lang.String cls)
cls - the class to look up its superclassespublic java.lang.String[] getSuperclasses()
public java.lang.String[] getPackages(java.lang.Class superclass)
superclass - the superclass to return the packages forpublic java.lang.String[] getPackages(java.lang.String superclass)
superclass - the superclass to return the packages forpublic java.util.Properties getPackages()
public java.lang.String toString()
toString in class java.lang.Objectpublic static ClassLister getSingleton()
public static java.util.Properties load(java.lang.String props)
props - the path, e.g., "nz/ac/waikato/cms/locator/ClassLister.props"public static java.util.Properties load(java.lang.String props,
java.util.Properties defProps)
props - the path, e.g., "nz/ac/waikato/cms/locator/ClassLister.props"Copyright © 2018 University of Waikato, Hamilton, NZ. All Rights Reserved.