Access keys

ClassAlgorithm

Kind of class: class
Inherits from: BasicClass
Author: Simon Wacker
Classpath: org.as2lib.env.reflect.algorithm.ClassAlgorithm
File last modified: Tuesday, 16 August 2005, 18:09:58
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
org.as2lib.env.reflect.ClassInfo.forObject, org.as2lib.env.reflect.ClassInfo.forInstance, org.as2lib.env.reflect.ClassInfo.forClass
and org.as2lib.env.reflect.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.

Summary

Constructor

Constructor

ClassAlgorithm

function ClassAlgorithm (
Void)
Constructs a new ClassAlgorithm instance.

Instance methods

execute

function execute (
d)

executeByClass

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:


clazz

The class as Function that has been searched for, this is the
passed-in class d.

name

The name as String of the searched for class.

package

The package represented by a org.as2lib.env.reflect.PackageInfo instance the class is
a member of.

null will be returned if:

  • The passed-in class d is null or undefined.
  • The passed-in class d could not be found.

The search starts on the package returned by the org.as2lib.env.reflect.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.

Parameters:
d:
the class to return information about
Returns:
an object that contains information about the passed-in class d
See also:

executeByComparator

function executeByComparator (
v:Function)
Executes the search for a class and returns information about that class.

The returned object has the following properties:


clazz

The class as Function that has been searched for.

name

The name as String of the searched for class.

package

The package represented by a {@ling PackageInfo} instance the class is
a member of.

null will be returned if:

  • The passed-in comparator v method is null or undefined.
  • The searched for class could not be found.

The search starts on the package returned by the org.as2lib.env.reflect.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.

Parameters:
v:
the comparator to determine the correct class
Returns:
an object that contains information about the class
See also:

executeByInstance

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:


clazz

The class as Function that has been searched for.

name

The name as String of the searched for class.

package

The package represented by a org.as2lib.env.reflect.PackageInfo instance the class is
a member of.

null will be returned if:

  • The passed-in instance d is null or undefined.
  • The class of the passed-in instance could not be found.

The search starts on the package returned by the org.as2lib.env.reflect.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.

Parameters:
d:
the instance of the class to return information about
Returns:
an object that contains information about the class the passed-in object
d is an instance of
See also:

executeByName

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 org.as2lib.env.reflect.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.

Parameters:
n:
the fully qualified name of the class
Returns:
the class info representing the class corresponding to the passed-in name
Throws:
org.as2lib.env.except.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
org.as2lib.env.reflect.ClassNotFoundException if a class with the passed-in name could not be found

getCache

function getCache (
Void) : Cache
Returns the cache set via the setCache method or the default cache that
is returned by the org.as2lib.env.reflect.ReflectConfig.getCache method.
Returns:
the currently used cache

setCache

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.

Parameters:
cache:
the new cache