Class Loader

Class Loader — Class loading features.

Synopsis


#include <jclass/class_loader.h>


typedef     ClassFile;
typedef     ClassLoader;
ClassLoader* jclass_classloader_get_current (void);
ClassLoader* jclass_classloader_get_default (void);
void        jclass_classloader_set          (ClassLoader *classloader);
char*       jclass_classloader_get_class_filename
                                            (const char *class_name,
                                             const ClassPath *classpath);
ClassFile*  jclass_classloader_get_class_file
                                            (const char *class_name,
                                             const ClassPath *classpath);
ClassPath*  jclass_classloader_get_classpath
                                            (const char *classpath_string,
                                             const char *bootclasspath_string);
void        jclass_classloader_classpath_free
                                            (ClassPath *path);
#define     foreach_in_classpath            (node, path)

Description

libjclass can retrieve classes directly from .class files or from jar archives attempting to imitate the behaviour of the Sun Java VM. As of version 0.3 it is possible to override the default classloader.

Details

ClassFile

typedef struct {
	FILE* file_ptr;
	char* data;
} ClassFile;

A structure represending a loaded (but not yet parsed) class file.


ClassLoader

typedef struct  {
		/* A pointer to the function that returns the filename a class is in */
		char* (*get_class_filename) (const char*, const ClassPath*);
		/* A pointer to the function that returns a ClassFile struct for the given class */
		ClassFile* (*get_class_file) (const char*, const ClassPath*);
		ClassPath* (*get_classpath) (const char*, const char*);
} ClassLoader;

A structure represending a class loader.


jclass_classloader_get_current ()

ClassLoader* jclass_classloader_get_current (void);

Gives the current class loader.

Since: 0.3

Returns : A pointer to the current class loader.

jclass_classloader_get_default ()

ClassLoader* jclass_classloader_get_default (void);

Gives the default class loader.

Since: 0.3

Returns : A pointer to the default classloader.

jclass_classloader_set ()

void        jclass_classloader_set          (ClassLoader *classloader);

Overrides the classloader for the library. If NULL is passed then the default classloader will be used.

Since: 0.3

classloader : The new classloader or NULL to revert to the default.

jclass_classloader_get_class_filename ()

char*       jclass_classloader_get_class_filename
                                            (const char *class_name,
                                             const ClassPath *classpath);

Finds the URL that contains the class with the given name.

Since: 0.3

class_name : The fully qualified name of the class.
classpath : The classpath to use.
Returns : A string allocated with malloc.

jclass_classloader_get_class_file ()

ClassFile*  jclass_classloader_get_class_file
                                            (const char *class_name,
                                             const ClassPath *classpath);

Gives the given class in a file or a memory buffer.

Since: 0.3

class_name : The fully qualified name of the class.
classpath : The classpath to use.
Returns : A ClassFile struct allocated with malloc.

jclass_classloader_get_classpath ()

ClassPath*  jclass_classloader_get_classpath
                                            (const char *classpath_string,
                                             const char *bootclasspath_string);

Gives the classpath for the given classpath and bootstrap claspath strings.

Since: 0.4

classpath_string : The classpathe.
bootclasspath_string : The classpath for bootstrap classes.
Returns : A ClassPath struct.

jclass_classloader_classpath_free ()

void        jclass_classloader_classpath_free
                                            (ClassPath *path);

Frees the given classpath struct.

path : The classpath to free.

foreach_in_classpath()

#define foreach_in_classpath(node, path) for(node = path; node; node = node->next)

Convenience macro to traverse a classpath struct.

node :The node struct to store the current node.
path :The path to traverse.