ACDK ClassLoader


| Introduction | How to use | ClassLoader | Serialization | Reflection | Attributes | Mechanism |

Through the build in Metainformation of ACDK classes can be loacated and loaded by name.

Content of this chapter:

   Find classes with acdk::lang::Class
   Find classes in shared libraries / DLLs
   Define aliases for shared library


To load a class via name at runtime, the class has to be compiled with meta info.
See also:  man acdkmc.

 Find classes with acdk::lang::Class

With the method static  acdk::lang::Class::forName(IN(RString) className); a class can be located.

With the method RObject acdk::lang::Class::newInstance(); a new Instance of this object can be created as long there is a public default constructor or the class implements the method static RObject create_instance().

 Find classes in shared libraries / DLLs

Classes of one branch in the namespace are organized in a package and compiled in to one shared library / DLL can be found and loaded at runtime.

The standard  acdk::lang::ClassLoader of ACDK try to locate the shared library in the ACDKHOME/bin directory.
For instance you can load a Class this way:
Class::forName look if class already loaded. In this case returns the Class.
If not try to find a acdk_security_SHAMessageDigest.dll/.so.
If not found this library then try to find acdk_security.dll/.so.

In case acdk_security.dll/.so can be found in $ACDKHOME/bin the library will be loaded. At load time all ACDK classes are registered into the local ACDK class registry.

The Class can be returned.

RClass digestclass = Class::forName("acdk/security/SHAMessageDigest");

  With the Class instance a new object instance can be created,
  and can be casted to a known interface (here MessageDigest).
RMessageDigest digest = (RMessageDigest)digestclass->newInstance();

 Define aliases for shared library

Sometime the name of a shared library doesn't reflect the class name.

For example the class org::w3c::dom::Node cannot be found in a shared library named like org_w3c*, but in the shared library org_xml*.

Therefore aliases can be defined in the acdk.cfg (located at $ACDKHOME/cfg) as a map
# define an alias for a given namespace to a library name
# used by the classloader to find the shared library for
# a given class. This sample load the libary org_xml if searching
# for mapped org.w3c.*