public class ClassLocator
extends java.lang.Object
implements java.io.Serializable
weka.core.ClassDiscovery class.
StringCompare,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected java.util.HashSet<java.lang.String> |
m_BlackListed
for caching failed instantiations (classnames).
|
protected ClassCache |
m_Cache
the overall class cache.
|
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> |
m_CacheClasses
for caching queries (classname-packagename <-> List with classes).
|
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> |
m_CacheNames
for caching queries (classname-packagename <-> List with classnames).
|
protected static java.util.Map<java.lang.String,java.lang.Boolean> |
m_CheckInterface
the cache for interface checks.
|
protected static java.util.Map<java.lang.String,java.lang.Boolean> |
m_CheckSubClass
the cache for subclass checks.
|
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 static java.util.Map<java.lang.Class<? extends ClassTraversal>,ClassLocator> |
m_Singleton
the singleton.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ClassLocator()
Initializes the class locator.
|
protected |
ClassLocator(ClassTraversal traversal)
Initializes the class locator.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCache(java.lang.Class cls,
java.lang.String pkgname,
java.util.List<java.lang.String> classnames,
java.util.List<java.lang.Class> classes)
adds the list of classnames to the cache.
|
protected void |
blacklist(java.lang.String classname)
Blacklists the given classname.
|
java.util.List<java.net.URL> |
classpathPartsForClass(java.lang.Class cls)
Returns the classpath parts that contain the specified class (eg to find duplicates).
|
java.util.List<java.net.URL> |
classpathPartsForClass(java.lang.String classname)
Returns the classpath parts that contain the specified class (eg to find duplicates).
|
java.util.List<java.lang.Class> |
findClasses(java.lang.Class cls,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.Class> |
findClasses(java.lang.String classname,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.Class> |
findClassesInPackage(java.lang.Class cls,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.Class> |
findClassesInPackage(java.lang.String classname,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.String> |
findNames(java.lang.Class cls,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.String> |
findNames(java.lang.String classname,
java.lang.String[] pkgnames)
Checks the given packages for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.String> |
findNamesInPackage(java.lang.Class cls,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.String> |
findNamesInPackage(java.lang.String classname,
java.lang.String pkgname)
Checks the given package for classes that inherited from the given class,
in case it's a class, or implement this class, in case it's an interface.
|
java.util.List<java.lang.String> |
findPackages()
Lists all packages it can find in the classpath.
|
ClassCache |
getCache()
Returns the class cache.
|
protected java.util.List<java.lang.Class> |
getClassCache(java.lang.Class cls,
java.lang.String pkgname)
returns the list of classes associated with this class and package, if
available, otherwise null.
|
java.util.logging.Logger |
getLogger()
Returns the logger in use.
|
protected java.util.List<java.lang.String> |
getNameCache(java.lang.Class cls,
java.lang.String pkgname)
returns the list of classnames associated with this class and package, if
available, otherwise null.
|
static ClassLocator |
getSingleton()
Returns the singleton, instantiates it if necessary.
|
static ClassLocator |
getSingleton(ClassTraversal traversal)
Returns the singleton, instantiates it if necessary.
|
static boolean |
hasInterface(java.lang.Class intf,
java.lang.Class cls)
Checks whether the given class implements the given interface.
|
static boolean |
hasInterface(java.lang.String intf,
java.lang.String cls)
Checks whether the given class implements the given interface.
|
protected void |
initCache(ClassTraversal traversal)
initializes the cache for the classnames.
|
boolean |
isBlacklisted(java.lang.String classname)
Returns whether this classname has been blacklisted.
|
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 boolean |
isSubclass(java.lang.Class superclass,
java.lang.Class otherclass)
Checks whether the "otherclass" is a subclass of the given "superclass".
|
static boolean |
isSubclass(java.lang.String superclass,
java.lang.String otherclass)
Checks whether the "otherclass" is a subclass of the given "superclass".
|
static void |
main(java.lang.String[] args)
Possible calls:
adams.core.ClassLocator <packages>
Prints all the packages in the current classpath adams.core.ClassLocator <classname> <packagename(s)> Prints the classes it found. |
static boolean |
matches(java.lang.Class superclassOrIntf,
java.lang.Class otherclass)
Checks whether the "otherclass" is a subclass of the given "superclassOrIntf"
or whether it implements "superclassOrIntf".
|
static boolean |
matches(java.lang.String superclassOrIntf,
java.lang.String otherclass)
Checks whether the "otherclass" is a subclass of the given "superclassOrIntf"
or whether it implements "superclassOrIntf".
|
protected ClassCache |
newClassCache(ClassTraversal traversal)
Returns a new instance of the
ClassCache. |
void |
setOnlyDefaultConstructor(boolean value)
Sets whether to allow only classes with default constructor.
|
void |
setOnlySerializable(boolean value)
Sets whether to allow only serializable classes.
|
protected static java.util.Map<java.lang.String,java.lang.Boolean> m_CheckSubClass
protected static java.util.Map<java.lang.String,java.lang.Boolean> m_CheckInterface
protected transient java.util.logging.Logger m_Logger
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.String>> m_CacheNames
protected java.util.HashMap<java.lang.String,java.util.List<java.lang.Class>> m_CacheClasses
protected java.util.HashSet<java.lang.String> m_BlackListed
protected ClassCache m_Cache
protected boolean m_OnlyDefaultConstructor
protected boolean m_OnlySerializable
protected static java.util.Map<java.lang.Class<? extends ClassTraversal>,ClassLocator> m_Singleton
protected ClassLocator()
protected ClassLocator(ClassTraversal traversal)
traversal - the traversal instance to use, can be nullpublic 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 java.util.List<java.lang.String> findNames(java.lang.String classname,
java.lang.String[] pkgnames)
classname - the class/interface to look forpkgnames - the packages to search inpublic java.util.List<java.lang.Class> findClasses(java.lang.String classname,
java.lang.String[] pkgnames)
classname - the class/interface to look forpkgnames - the packages to search inpublic java.util.List<java.lang.String> findNames(java.lang.Class cls,
java.lang.String[] pkgnames)
cls - the class/interface to look forpkgnames - the packages to search inpublic java.util.List<java.lang.Class> findClasses(java.lang.Class cls,
java.lang.String[] pkgnames)
cls - the class/interface to look forpkgnames - the packages to search inpublic java.util.List<java.lang.String> findNamesInPackage(java.lang.String classname,
java.lang.String pkgname)
classname - the class/interface to look forpkgname - the package to search inpublic java.util.List<java.lang.Class> findClassesInPackage(java.lang.String classname,
java.lang.String pkgname)
classname - the class/interface to look forpkgname - the package to search inpublic java.util.List<java.lang.String> findNamesInPackage(java.lang.Class cls,
java.lang.String pkgname)
cls - the class/interface to look forpkgname - the package to search inpublic java.util.List<java.lang.Class> findClassesInPackage(java.lang.Class cls,
java.lang.String pkgname)
cls - the class/interface to look forpkgname - the package to search inpublic java.util.List<java.lang.String> findPackages()
public java.util.List<java.net.URL> classpathPartsForClass(java.lang.Class cls)
cls - the class to look forpublic java.util.List<java.net.URL> classpathPartsForClass(java.lang.String classname)
classname - the class to look forprotected ClassCache newClassCache(ClassTraversal traversal)
ClassCache.traversal - how to traverse the classes, can be nullprotected void initCache(ClassTraversal traversal)
traversal - how to traverse the classes, can be nullprotected void addCache(java.lang.Class cls,
java.lang.String pkgname,
java.util.List<java.lang.String> classnames,
java.util.List<java.lang.Class> classes)
cls - the class to cache the classnames forpkgname - the package name the classes were found inclassnames - the list of classnames to cacheprotected java.util.List<java.lang.String> getNameCache(java.lang.Class cls,
java.lang.String pkgname)
cls - the class to get the classnames forpkgname - the package name for the classesprotected java.util.List<java.lang.Class> getClassCache(java.lang.Class cls,
java.lang.String pkgname)
cls - the class to get the classes forpkgname - the package name for the classesprotected void blacklist(java.lang.String classname)
classname - the classname to blacklistpublic boolean isBlacklisted(java.lang.String classname)
classname - the classname to checkpublic ClassCache getCache()
public static ClassLocator getSingleton()
public static ClassLocator getSingleton(ClassTraversal traversal)
traversal - the class traversal scheme to use, can be null for default onepublic static boolean isSubclass(java.lang.String superclass,
java.lang.String otherclass)
superclass - the superclass to check againstotherclass - this class is checked whether it is a subclass
of the the superclasspublic static boolean isSubclass(java.lang.Class superclass,
java.lang.Class otherclass)
superclass - the superclass to check againstotherclass - this class is checked whether it is a subclass
of the the superclasspublic static boolean hasInterface(java.lang.String intf,
java.lang.String cls)
intf - the interface to look for in the given classcls - the class to check for the interfacepublic static boolean hasInterface(java.lang.Class intf,
java.lang.Class cls)
intf - the interface to look for in the given classcls - the class to check for the interfacepublic static boolean matches(java.lang.String superclassOrIntf,
java.lang.String otherclass)
superclassOrIntf - the superclass/interface to check againstotherclass - this class is checked whether it is a subclass
of the the superclasspublic static boolean matches(java.lang.Class superclassOrIntf,
java.lang.Class otherclass)
superclassOrIntf - the superclass/interface to check againstotherclass - this class is checked whether it is a subclass
of the the superclasspublic static void main(java.lang.String[] args)
args - the commandline argumentsCopyright © 2021 University of Waikato, Hamilton, NZ. All Rights Reserved.