public 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 and 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 ClassTraversal |
m_ClassTraversal
the class traversal to use.
|
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 java.util.Set<java.lang.Class> |
m_ManagedClasses
cache for all managed classs.
|
protected java.util.Set<java.lang.String> |
m_ManagedClassnames
cache for all managed classnames.
|
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 java.util.Map<java.lang.Class<? extends ClassTraversal>,ClassLister> |
m_Singleton
the singleton.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ClassLister()
Initializes the classlister.
|
protected |
ClassLister(ClassTraversal traversal)
Initializes the classlister.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHierarchy(java.lang.Class superclass,
java.lang.Class[] classes)
Adds/appends a class hierarchy.
|
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.
|
ClassTraversal |
getClassTraversal()
Returns the underlying class traversal.
|
java.util.logging.Logger |
getLogger()
Returns the logger in use.
|
java.util.Set<java.lang.Class> |
getManagedClasses()
Returns the set of managed classes.
|
java.util.Set<java.lang.String> |
getManagedClassnames()
Returns the set of managed class names.
|
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.
|
static ClassLister |
getSingleton(ClassTraversal traversal)
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 |
isManaged(java.lang.Class cls)
Checks whether the class is listed in one of the hierarchies.
|
boolean |
isManaged(java.lang.String classname)
Checks whether the classname is listed in one of the hierarchies.
|
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.util.Properties |
toPackages()
Returns the class hierarchies as properties object, with the superclasses
as keys and the values representing comma-separated lists of packages.
|
java.util.Properties |
toProperties()
Returns the class hierarchies as properties object, with the superclasses
as keys and the values representing comma-separated lists of classnames.
|
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.Set<java.lang.String> m_ManagedClassnames
protected java.util.Set<java.lang.Class> m_ManagedClasses
protected java.util.Properties m_Blacklist
protected boolean m_OnlyDefaultConstructor
protected boolean m_OnlySerializable
protected ClassTraversal m_ClassTraversal
protected static java.util.Map<java.lang.Class<? extends ClassTraversal>,ClassLister> m_Singleton
protected ClassLister()
protected ClassLister(ClassTraversal traversal)
public boolean isLoggingEnabled()
public java.util.logging.Logger getLogger()
public ClassTraversal getClassTraversal()
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 addHierarchy(java.lang.Class superclass,
java.lang.Class[] classes)
superclass - the superclassclasses - the classespublic 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 boolean isManaged(java.lang.Class cls)
cls - the class to checkpublic java.util.Set<java.lang.Class> getManagedClasses()
public boolean isManaged(java.lang.String classname)
classname - the classname to checkpublic java.util.Set<java.lang.String> getManagedClassnames()
public java.util.Properties toProperties()
public java.util.Properties toPackages()
public java.lang.String toString()
toString in class java.lang.Objectpublic static ClassLister getSingleton()
public static ClassLister getSingleton(ClassTraversal traversal)
traversal - the class traversal to use, can be null for default onepublic 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 © 2021 University of Waikato, Hamilton, NZ. All Rights Reserved.