org.as2lib.core.BasicClass +--org.as2lib.env.reflect.algorithm.ClassAlgorithm
ClassAlgorithm
searches for the class of a specific instance or class
and returns information about that class.
This class is rather cumbersome to use. It is recommended to use the static
ClassInfo.forObject, ClassInfo.forInstance, ClassInfo.forClass
and ClassInfo.forName methods instead. They offer more sophisticated
return values and do also store ClassInfo
instances retrieved by classes
or instances and not only those by name like this algorithm does.
To obtain information corresponding to an instance or a class you can use
this class as follows.
var myInstance:MyClass = new MyClass();
var classAlgorithm:ClassAlgorithm = new ClassAlgorithm();
var infoByInstance:Object = classAlgorithm.execute(myInstance);
var infoByClass:Object = classAlgorithm.execute(MyClass);
It is also possible to retrieve a class info by name.
classInfoByName:ClassInfo = classAlgorithm.executeByName("MyClass");
If the class is not contained in the root/default package you must specify
the whole path / its namespace.
classInfoByName:ClassInfo = classAlgorithm.executeByName("org.as2lib.MyClass");
Already retrieved class infos are stored in a cache. There thus exists only
one ClassInfo
instance per class. Note that the execute method
does not return ClassInfo
instances and does thus not store the found
information.
new ClassAlgorithm()
public function setCache(cache:Cache):Void
Sets the cache that is used by the executeByName method to look whether the class the shall be found is already stored.
This cache also determines where the search for a class starts.
cache | the new cache |
public function getCache(Void):Cache
Returns the cache set via the setCache method or the default cache that is returned by the ReflectConfig.getCache method.
the currently used cache
public function executeByClass(d:Function)
Executes the search for the passed-in class d
and returns information
about this class.
The returned object has the following properties:
Function
that has been searched for, this is the
passed-in class d
. String
of the searched for class. null
will be returned if:
d
is null
or undefined
. d
could not be found.The search starts on the package returned by the Cache.getRoot method
of the set cache. If this method returns a package info whose getPackage
method returns null
or undefined
_global
is used instead.
d | the class to return information about |
an object that contains information about the passed-in class d
public function executeByInstance(d)
Executes the search for the class the passed-in object d
is an instance
of and returns information about that class.
The returned object has the following properties:
Function
that has been searched for. String
of the searched for class. null
will be returned if:
d
is null
or undefined
.The search starts on the package returned by the Cache.getRoot method
of the set cache. If this method returns a package info whose getPackage
method returns null
or undefined
_global
is used instead.
d | the instance of the class to return information about |
an object that contains information about the class the passed-in object
d
is an instance of
public function executeByComparator(v:Function)
Executes the search for a class and returns information about that class.
The returned object has the following properties:
Function
that has been searched for. String
of the searched for class. null
will be returned if:
v
method is null
or undefined
.The search starts on the package returned by the Cache.getRoot method
of the set cache. If this method returns a package info whose getPackage
method returns null
or undefined
_global
is used instead.
The passed-in comparator is invoked for every found class to determine whether
it is the right one or not. The comparator method gets passed the found class and
must return true
or false
. If it returns true
the
algorithm stops and returns the information about this class.
v | the comparator to determine the correct class |
an object that contains information about the class
public function executeByName(n:String):ClassInfo
Returns the class info representing the class corresponding to the passed-in
class name n
.
The class name must be fully qualified, that means it must consist of the class's path (namespace) as well as its name. For example 'org.as2lib.core.BasicClass'.
The search starts on the package returned by the Cache.getRoot method
of the set cache. If this method returns a package info whose getFullName
method returns null
or undefined
"_global"
is used instead.
n | the fully qualified name of the class |
the class info representing the class corresponding to the passed-in name
IllegalArgumentException | if the passed-in name is null , undefined
or an empty string or if the object corresponding to the passed-in name is not of
type function
|
ClassNotFoundException | if a class with the passed-in name could not be found |