Class org.as2lib.env.reflect.algorithm.ClassAlgorithm

org.as2lib.core.BasicClass
   +--org.as2lib.env.reflect.algorithm.ClassAlgorithm

Description

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.

Method Index

new ClassAlgorithm()

execute(), executeByClass(), executeByComparator(), executeByInstance(), executeByName(), getCache(), setCache()

Inherited from BasicClass

toString()

Constructor Detail

ClassAlgorithm

public function ClassAlgorithm(Void)

Constructs a new ClassAlgorithm instance.

Method Detail

setCache

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.

Parameters

cachethe new cache

getCache

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.

Return

the currently used cache

execute

public function execute(d)

executeByClass

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:

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 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 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

dthe class to return information about

Return

an object that contains information about the passed-in class d

executeByInstance

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:

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 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 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

dthe instance of the class to return information about

Return

an object that contains information about the class the passed-in object d is an instance of

executeByComparator

public 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 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 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

vthe comparator to determine the correct class

Return

an object that contains information about the class

executeByName

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.

Parameters

nthe fully qualified name of the class

Return

the class info representing the class corresponding to the passed-in name

Throws

IllegalArgumentExceptionif 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
ClassNotFoundExceptionif a class with the passed-in name could not be found