Codemesh Runtime v3 C++ API Reference  3.9.205
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
xmog_java_class Class Reference

A C++ wrapper for Java types. More...

#include <xmog_java_class.h>

Inheritance diagram for xmog_java_class:
Inheritance graph
[legend]
Collaboration diagram for xmog_java_class:
Collaboration graph
[legend]

Public Types

enum  xmog_interceptor_result { IcpDoneWithResult = 1, IcpContinue = 0, IcpError = -1 }
 A value used to signal further interceptor processing requirements. More...
 
enum  xmog_interceptor_when { IcpBefore = 0, IcpAfter = 1 }
 A value used to signal the interceptor call reason. More...
 
enum  xmog_interceptor_what {
  IcpFieldGet = 0, IcpFieldSet = 1, IcpMethod = 2, IcpCtor = 3,
  IcpArrayCreate = 4, IcpArrayGet = 5, IcpArraySet = 6, IcpStringFromNativeChars = 7,
  IcpNativeCharsFromString = 8, IcpIsNull = 9, IcpIsInstanceOf = 10, IcpSpecial = 16
}
 A value used to signal the interceptor type. More...
 
typedef void(XMOG_CALLING_CONVENTION * XMOG_THROW_METHOD) (jobject exc, xmog_flags flags)
 A typedef for the method that can be used to throw an exception. More...
 
typedef xmog_java_ref *(XMOG_CALLING_CONVENTION * XMOG_FACTORY_METHOD) (jobject obj, xmog_flags src, xmog_flags dest, const char *classNameUTF, xmog_localenv *env)
 A typedef for the method that can be used to return a heap-allocated instance of a proxy type based on a JNI reference. More...
 
typedef xmog_java_ref *(XMOG_CALLING_CONVENTION * XMOG_TOJAVA_METHOD) (xmog_java_ref *nobj, xmog_localenv *env)
 A typedef for the method that can be used to perform custom object conversion for a native type that is being transformed into a Java object. More...
 
typedef xmog_java_ref *(XMOG_CALLING_CONVENTION * XMOG_FROMJAVA_METHOD) (xmog_java_ref *jobj, xmog_localenv *env)
 A typedef for the method that can be used to perform custom object initialization for a proxy type that is being created for an existing Java object. More...
 
typedef xmog_interceptor_result(XMOG_CALLING_CONVENTION * XMOG_INTERCEPTOR) (xmog_base *obj, xmog_java_dynamic *dyn, xmog_java_values *vals, xmog_interceptor_when when, xmog_interceptor_what what, xmog_java_value *result, xmog_localenv *env, xmog_flags &flags)
 A typedef for a method that can be registered to handle or augment the processing of proxy API calls. More...
 
- Public Types inherited from xmog_base
enum  flags {
  STAND_ALONE = 1, ARRAY_ELEMENT = 2, DYNAMIC = 4, DELEGATE = 8,
  LOCAL = 16, WEAK_GLOBAL = 32, GLOBAL = 64, REMOTE = 128,
  CACHING = 256, CACHE_INVALID = 512, CACHE_DIRTY = 1024, CACHE_LAZY_WRITE = 2048,
  OWNS_DELEGATE = 4096, STRING_DIRTY = 8192, STRING_PTR = 16384, STRING_WPTR = 32768,
  INDIRECT = 65536, NONVIRT = 131072, SUPPRESS_LOGGING = 262144, CATEGORY = 15,
  TYPE = 240, CACHE = 3840
}
 The possible flag values. More...
 

Public Member Functions

 xmog_java_class ()
 The default constructor.
 
 xmog_java_class (const char *classNameUTF, bool bDelayInit=false, XMOG_FACTORY_METHOD factoryMethod=NULL_FACTORY_METHOD, XMOG_THROW_METHOD throwMethod=NULL_THROW_METHOD, XMOG_TOJAVA_METHOD toJavaMethod=NULL_TOJAVA_METHOD, XMOG_FROMJAVA_METHOD fromJavaMethod=NULL_FROMJAVA_METHOD, xmog_localenv *env=NULL)
 The constructor that creates an instance based on the classname. More...
 
 xmog_java_class (const char *classNameUTF, const char *version, const char *config, bool bDelayInit=false, XMOG_FACTORY_METHOD factoryMethod=NULL_FACTORY_METHOD, XMOG_THROW_METHOD throwMethod=NULL_THROW_METHOD, XMOG_TOJAVA_METHOD toJavaMethod=NULL_TOJAVA_METHOD, XMOG_FROMJAVA_METHOD fromJavaMethod=NULL_FROMJAVA_METHOD, xmog_localenv *env=NULL)
 The constructor that creates an instance based on the classname and a named configuration. More...
 
 xmog_java_class (const char *classNameUTF, jbyte *bytes, jint length, bool bDelayInit=false, XMOG_FACTORY_METHOD factoryMethod=NULL_FACTORY_METHOD, XMOG_THROW_METHOD throwMethod=NULL_THROW_METHOD, XMOG_TOJAVA_METHOD toJavaMethod=NULL_TOJAVA_METHOD, XMOG_FROMJAVA_METHOD fromJavaMethod=NULL_FROMJAVA_METHOD, xmog_localenv *env=NULL)
 The constructor that creates an instance based on class bytes. More...
 
 xmog_java_class (const char *classNameUTF, jbyte *bytes, jint length, jbyte *stubBytes, jint stubLength, jbyte *skelBytes, jint skelLength, bool bDelayInit=false, XMOG_FACTORY_METHOD factoryMethod=NULL_FACTORY_METHOD, XMOG_THROW_METHOD throwMethod=NULL_THROW_METHOD, XMOG_TOJAVA_METHOD toJavaMethod=NULL_TOJAVA_METHOD, XMOG_FROMJAVA_METHOD fromJavaMethod=NULL_FROMJAVA_METHOD, xmog_localenv *env=NULL)
 The constructor that creates an instance based on class bytes. More...
 
 xmog_java_class (jclass _local, xmog_flags _flags, const char *classNameUTF=NULL, xmog_localenv *env=NULL)
 The constructor that creates an instance based on an existing JNI reference. More...
 
void * operator new (size_t)
 An overloaded operator new to support the automatic detection of whether or not the object is heap-allocated.
 
void operator delete (void *)
 An overloaded operator delete to support the safe cleanup of instances independent of whether they are allcoated on the heap or not.
 
void has_peer_unmarshaller (bool bHPU)
 Sets the flag that indicates that the class has at least one peer unmarshaller registered for it. More...
 
bool has_peer_unmarshaller () const
 Returns true if the class has at least one peer unmarshaller registered. More...
 
jint get_hashcode (xmog_localenv *env=NULL)
 Returns the instance's hashcode. More...
 
jclass get_jclass (xmog_localenv *env=NULL)
 Returns the internal JNI reference to the type. More...
 
jclass get_jclass (xmog_localenv *env, bool bSuppressExceptions)
 Returns the internal JNI reference to the type. More...
 
const char * get_class_name () const
 Returns the class name.
 
const char * getClassName (xmog_localenv *env=NULL)
 Returns the classname. More...
 
void add_field (xmog_java_field *_field)
 Adds a field to the list of fields that this instance is aware of. More...
 
xmog_java_fieldget_fields ()
 Returns a pointer to the first field.
 
void remove_field (xmog_java_field *_field)
 Removes a field from the list of field that this instance is aware of. More...
 
void add_method (xmog_java_method *_method)
 Adds a method to the list of methods that this instance is aware of. More...
 
xmog_java_methodget_methods ()
 Returns a pointer to the first method or constructor.
 
void remove_method (xmog_java_method *_method)
 Removes a method from the list of methods that this instance is aware of. More...
 
void throw_ (jthrowable throwable, xmog_flags flags, int error_code=0, xmog_localenv *env=NULL)
 Throws an instance of the proxy type represented by this instance. More...
 
xmog_java_classget_array_class ()
 Returns the xmog_java_class instance that represents the array type for this instance's represented type.
 
jobject from (const xmog_base &srcInstance, xmog_flags flags=xmog_base::GLOBAL, xmog_localenv *env=NULL)
 Returns an object reference or null if the given instance is incompatible with this class. More...
 
void setInterceptor (XMOG_INTERCEPTOR icp)
 Sets an API interceptor for the Java type represented by this instance. More...
 
void setOwnsClassName ()
 Used internally for housekeeping.
 
xmog_java_class::XMOG_INTERCEPTOR getInterceptor () const
 Returns an installed interceptor or NULL if there is none.
 
- Public Member Functions inherited from xmog_java_ref
 xmog_java_ref ()
 The default constructor.
 
 xmog_java_ref (const xmog_null &)
 The from null constructor. More...
 
 xmog_java_ref (xmog_java_array *_arr, jint _index)
 The array element constructor. More...
 
 xmog_java_ref (xmog_java_class *_clazz, xmog_java_dynamic *_dynamic, xmog_flags _flags)
 The constructor that allows the dynamic resolution of class-related information. More...
 
XMOG_EXPLICIT xmog_java_ref (xmog_base *_delegate, bool _owns_delegate=true)
 The constructor that allows the creation of an instance to handle all requests by delegating to another instance. More...
 
 xmog_java_ref (xmog_java_ref *_ref, xmog_java_dynamic *_dynamic, xmog_flags _flags)
 The constructor that allows the dynamic resolution of instance-related information. More...
 
 xmog_java_ref (jobject _local, xmog_flags _flags)
 The constructor that sets an existing JNI reference into a wrapper instance. More...
 
 ~xmog_java_ref ()
 Deletes the reference we hold to the wrapped Java instance.
 
bool operator== (const xmog_null &) const
 Compares the instance for equality with null.
 
bool operator== (const xmog_java_ref &) const
 Compares the instance for equality with another instance. More...
 
bool operator!= (const xmog_null &) const
 Compares the instance for inequality with null.
 
bool operator!= (const xmog_java_ref &) const
 Compares the instance for inequality with another instance. More...
 
bool operator! () const
 Returns true if the instance refers to null, false otherwise.
 
jboolean xmog_equals (const xmog_java_ref &_rhs, xmog_localenv *env=NULL)
 Returns true if both instances are null or satisfy the equality test. More...
 
jint xmog_hashCode (xmog_localenv *env=NULL)
 Returns the Java instance's hashCode. More...
 
jobject xmog_toString (xmog_localenv *env=NULL)
 Returns the Java instance's toString() valus as a global reference. More...
 
virtual jobject get_jobject_ (xmog_localenv *env=NULL) const
 Returns this instance's object reference. More...
 
virtual void xmog_monitor_enter (xmog_localenv *env=NULL) const
 Attempts to enter into a lock on the object.
 
virtual void xmog_monitor_exit (xmog_localenv *env=NULL) const
 Leaves a lock in the object.
 
- Public Member Functions inherited from xmog_base
 xmog_base ()
 The default contructor. More...
 
 xmog_base (xmog_java_array *_ref, jint _index)
 The constructor for Java array elements. More...
 
 xmog_base (xmog_java_ref *_ref, xmog_java_dynamic *_dynamic, xmog_flags _flags)
 The constructor for indirect and user-defined types. More...
 
 xmog_base (xmog_java_class *_clazz, xmog_java_dynamic *_dynamic, xmog_flags _flags)
 The constructor for indirect and user-defined types. More...
 
XMOG_EXPLICIT xmog_base (xmog_base *_delegate, bool _owns_delegate=true)
 The constructor for delegating objects. More...
 
 xmog_base (jobject _local, xmog_flags _flags)
 The constructor for direct types. More...
 
virtual ~xmog_base ()
 The virtual destructor.
 
virtual void copy_jobject_ (xmog_base *_rhs, xmog_localenv *env=NULL)
 Sets this instance's object reference to a duplicate of the given object's reference. More...
 
virtual jobject get_owning_jobject_ (xmog_localenv *env=NULL)
 Returns this instance's owner. More...
 
virtual jobject get_released_local_jobject_ (xmog_localenv *env=NULL) const
 Returns this instance's object reference as a local reference and removes it from this instance's ownership. More...
 
virtual bool is_null_ (xmog_localenv *env=NULL) const
 Tests the instance for null.
 
virtual bool is_same_ (const xmog_base &_rhs, xmog_localenv *env=NULL) const
 Tests whether this instance references the same instance as the other instance.
 
virtual jobject duplicate_jobject_ (xmog_localenv *env=NULL) const
 Returns a duplicate of this instance's object reference. More...
 
virtual void set_jobject_ (xmog_base *_rhs, xmog_localenv *env=NULL)
 Sets this instance's object reference to the given object's reference. More...
 
virtual void transfer_jobject_ (xmog_base *_rhs, xmog_localenv *env=NULL)
 Sets this instance's object reference to the given object's reference and removes ownership from the other object. More...
 
virtual xmog_basexmog_to_ (xmog_flags flags, xmog_localenv *env=NULL)
 Converts a reference from one reference type to another. More...
 
virtual xmog_basexmog_fill_with_standalone_for_ (xmog_base *_rhs, xmog_localenv *env=NULL)
 Populates the object with a stand-alone reference based on another object. More...
 
virtual xmog_java_classxmog_get_java_peer (xmog_localenv *env=NULL)
 Returns NULL if the type does not have a Java peer type, a pointer to the type's xmog_java_class otherwise. More...
 
virtual int xmog_create_java_peer (xmog_java_class *clazz, xmog_localenv *env=NULL, xmog_flags flags=xmog_base::GLOBAL)
 Creates a Java peer instance for this type.
More...
 
virtual int xmog_to_java_peer (xmog_localenv *env=NULL)
 Sets the native instance's state into the Java peer instance. More...
 
virtual void xmog_lazy_write (xmog_localenv *env=NULL)
 Performs a lazy write operation on the instance. More...
 
virtual void xmog_invalidate (xmog_localenv *env=NULL)
 Invalidates any cached values in the instance. More...
 
void release_standalone (xmog_localenv *env=NULL)
 Releases the internally maintained object if the instance is a stand-alone (direct) instance and not an indirect instance. More...
 
void release_delegate ()
 Releases the internally maintained delegate.
 

Static Public Member Functions

static jint calculate_hashcode (const char *_classNameUTF)
 A utility method for calculating the hashcode of a classname. More...
 
static jobject get_bootstrap_classloader (xmog_localenv *env=NULL)
 Returns the classloader used by the Codemesh framework. This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.
More...
 
static void bootstrap (xmog_localenv *env=NULL)
 Injects the custom classloader types into the JVM. More...
 
static void initThread (xmog_localenv *env=NULL)
 Performs per-thread initialization in relation with the custom classloader. More...
 
static void add_class (xmog_java_class *clazz)
 Adds a proxy class to the proper list of classes. More...
 
static void remove_class (xmog_java_class *clazz)
 Removes a proxy class from the proper list of classes. More...
 
static xmog_java_classget_classes ()
 Returns the first class in the list of regular types.
 
static xmog_java_classget_throwables ()
 Returns the first class in the list of throwable types.
 
static char * getClassName (jobject inst, xmog_localenv *env=NULL)
 Returns the classname of the given instance. More...
 
static char * getClassClassName (jclass clazz, xmog_localenv *env=NULL)
 Returns the classname of a given class instance. More...
 
static xmog_java_classget_exact_throwable_for (const char *classNameUTF)
 Returns the exact xmog_java_class instance for the given name that has a non-NULL exception factory method. More...
 
static xmog_java_classget_best_throwable_for (xmog_base *throwable, bool bRemote, xmog_localenv *env=NULL)
 Returns the best matching xmog_java_class instance for the given throwable and that has a non-NULL exception factory method. More...
 
static xmog_java_classget_class_named (const char *classNameUTF)
 Returns the xmog_java_class instance for the given name
that has a non-NULL instance factory method. More...
 
static jbyte calculateMaximumSupportedClassVersion ()
 Calculates the maximum supported class version.
 
static void addLocalResourceRoot (const char *filenameUTF, bool preferred=false, xmog_localenv *env=NULL)
 Adds a file to the classpath used by the custom classloader. More...
 
static void addInMemoryResourceRoot (const jbyte *bytes, size_t len, bool preferred=false, xmog_localenv *env=NULL)
 Adds the embedded classes to the classpath used by the custom classloader. More...
 
static void addDirectoryJarFiles (const char *dirnameUTF, bool preferred=false, xmog_localenv *env=NULL)
 Adds all jarfiles in the specified directory to the classpath used by the custom classloader. More...
 
static void setSecurityManager (xmog_java_method &mSSM, const xmog_java_ref &sm, xmog_localenv *env)
 Returns the method used to set the security manager.
 
static bool call_bool_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jboolean call_boolean_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jbyte call_byte_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jchar call_char_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jdouble call_double_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jfloat call_float_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jint call_int_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jlong call_long_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jshort call_short_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static jobject call_object_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static void call_void_indirect (xmog_java_method *method, jobject instance, xmog_java_values *values, xmog_localenv *env)
 Calls a Java method indirectly. More...
 
static xmog_java_methodgetClass_method ()
 Returns a reference to a method wrapping around getClass().
 
static xmog_java_methodisInstance_method ()
 Returns a reference to a method wrapping around isInstance().
 
static int getInterceptorCount ()
 Returns the total number of interceptors registered with all types.
 

Static Public Attributes

static XMOG_THROW_METHOD NULL_THROW_METHOD
 An instance that can be used in places where no exception factory is required.
 
static XMOG_FACTORY_METHOD NULL_FACTORY_METHOD
 An instance that can be used in places where no instance factory is required.
 
static XMOG_TOJAVA_METHOD NULL_TOJAVA_METHOD
 An instance that can be used in places where no to-Java specialization is required.
 
static XMOG_FROMJAVA_METHOD NULL_FROMJAVA_METHOD
 An instance that can be used in places where no from-Java specialization is required.
 

Additional Inherited Members

- Public Attributes inherited from xmog_base
XMOG_JOBJECT_HOLDER owner_
 The owner or identity of the object. More...
 
union {
   xmog_java_dynamic *   dynamic_
 A pointer to an object that can access indirectly specified information.
 
   jint   index_
 The index of an array element.
 
}; 
 Data or object that provides assistance in accessing indirectly specified elements. More...
 
xmog_flags flags_
 The flags governing the type and other housekeeping information.
 

Detailed Description

A C++ wrapper for Java types.

This class provides basic proxy services for Java types. It has a number of constructors that allow the instantiation of a wrapper object based on a classname or on an existing JNI reference. It also utility methods that bootstrap a classloader that will be used by the native application and allow the efficient lookup of a class wrapper instance based on its classname.

Member Typedef Documentation

◆ XMOG_FACTORY_METHOD

typedef xmog_java_ref*(XMOG_CALLING_CONVENTION * xmog_java_class::XMOG_FACTORY_METHOD) (jobject obj, xmog_flags src, xmog_flags dest, const char *classNameUTF, xmog_localenv *env)

A typedef for the method that can be used to return a heap-allocated instance of a proxy type based on a JNI reference.

Every generated proxy class maintains a pointer to a function of this type that can be used as a factory method for instances of that proxy type. This method can then be used to dynamically create a proxy instance solely based on the type of the Java object (or additional factors).

Parameters
excan existing JNI reference to a Java instance.
srcbitflags describing the type of reference we have.
destbitflags describing the type of reference we want.
classNameUTFthe classname of the exception instance.
enva local environment pointer.

◆ XMOG_FROMJAVA_METHOD

typedef xmog_java_ref*(XMOG_CALLING_CONVENTION * xmog_java_class::XMOG_FROMJAVA_METHOD) (xmog_java_ref *jobj, xmog_localenv *env)

A typedef for the method that can be used to perform custom object initialization for a proxy type that is being created for an existing Java object.

When a Java method returns a reference as a result of its invocation, we usually simply wrap the reference in the proxy type for the declared return type. This is not always sufficient. For example: a user might wish to derive custom data types from a proxy type on the C++ side. These data types may contain data fields that should be persisted to the Java side and that should be read from the Java side when such a persisted instance is given back as the result of a method call. There are two issues to solve. The first involves creating an instance of the proper type and the second involves initializing that instance with the correct data.

◆ XMOG_INTERCEPTOR

typedef xmog_interceptor_result(XMOG_CALLING_CONVENTION * xmog_java_class::XMOG_INTERCEPTOR) (xmog_base *obj, xmog_java_dynamic *dyn, xmog_java_values *vals, xmog_interceptor_when when, xmog_interceptor_what what, xmog_java_value *result, xmog_localenv *env, xmog_flags &flags)

A typedef for a method that can be registered to handle or augment the processing of proxy API calls.

Parameters
objthe instance on which the API is performed (may be NULL for static APIs).
dynthe element representing the API that is being performed.
valsthe arguments that are passed to the API.
whenthe interceptor call time (can be called before and/or after the proxy operation).
whatthe interceptor call reason. This argument helps us in casting the dyn argument to the correct concrete type, for example xmog_java_field or xmog_java_method.
resultthe result value of the interceptor call. Only used if the interceptor returns IcpDone.
envthe local call environment passed to the API.
flagsa reference to the flags that are passed to the API.

◆ XMOG_TOJAVA_METHOD

typedef xmog_java_ref*(XMOG_CALLING_CONVENTION * xmog_java_class::XMOG_TOJAVA_METHOD) (xmog_java_ref *nobj, xmog_localenv *env)

A typedef for the method that can be used to perform custom object conversion for a native type that is being transformed into a Java object.

When a Java method returns a reference as a result of its invocation, we usually simply wrap the reference in the proxy type for the declared return type. This is not always sufficient. For example: a user might wish to derive custom data types from a proxy type on the C++ side. These data types may contain data fields that should be persisted to the Java side and that should be retrievable from the Java side when such a persisted instance is given back as the result of another method call.

This method is responsible for instantiating a proper Java peer object and for persisting the native instance in that Java object. The act of persisting the native object needs to include both the object's state and enough type information to allow the framework to instantiate the correct native type when the object is read back from Java. It is assumed that the native object is a subtype of a proxy type, thereby allowing its use with the generated typesystem.

Member Enumeration Documentation

◆ xmog_interceptor_result

A value used to signal further interceptor processing requirements.

Enumerator
IcpContinue 

Signals that the interceptor is supplying the result and no further processing should be done.

IcpError 

Signals that normal processing of the request should continue.

◆ xmog_interceptor_what

A value used to signal the interceptor type.

Enumerator
IcpFieldSet 

A 'get field value' request is being processed. The dyn argument will refer to an xmog_java_field instance.

IcpMethod 

A 'set field value' request is being processed. The dyn argument will refer to an xmog_java_field instance.

IcpCtor 

A 'call method' request is being processed. The dyn argument will refer to an xmog_java_method instance.

IcpArrayCreate 

A 'invoke constructor' request is being processed. The dyn argument will refer to an xmog_java_method instance.

◆ xmog_interceptor_when

A value used to signal the interceptor call reason.

Enumerator
IcpAfter 

Signals that we're being invoked before the actual API is being invoked.

Constructor & Destructor Documentation

◆ xmog_java_class() [1/5]

xmog_java_class::xmog_java_class ( const char *  classNameUTF,
bool  bDelayInit = false,
XMOG_FACTORY_METHOD  factoryMethod = NULL_FACTORY_METHOD,
XMOG_THROW_METHOD  throwMethod = NULL_THROW_METHOD,
XMOG_TOJAVA_METHOD  toJavaMethod = NULL_TOJAVA_METHOD,
XMOG_FROMJAVA_METHOD  fromJavaMethod = NULL_FROMJAVA_METHOD,
xmog_localenv env = NULL 
)

The constructor that creates an instance based on the classname.

This constructor can be used to easily create a wrapper instance that is not associated with a named configuration (for example for a built-in Java framework type that is always available, no matter what the classpath is).

Parameters
classNameUTFthe UTF representation of the classname. The classname should be provided in slash-separated (internal) format.
bDelayInittrue if the wrapper instance should immediately try to load the Java type, false if not. A generated framework typically uses delayed initialization to give the programmer a chance to control the time at which the JVM is loaded. The default value is false.
factoryMethodthe method that returns a dynamically allocated instance of a proxy type based on an existing JNI reference.
throwMethodthe method that throws an exception of a proxy type based on an existing JNI reference.
toJavaMethodthe method that creates and initializes a Java object for a native object.
fromJavaMethodthe method that creates and initializes a native object for a Java object.
envthe local environment to use. The default value is NULL.

◆ xmog_java_class() [2/5]

xmog_java_class::xmog_java_class ( const char *  classNameUTF,
const char *  version,
const char *  config,
bool  bDelayInit = false,
XMOG_FACTORY_METHOD  factoryMethod = NULL_FACTORY_METHOD,
XMOG_THROW_METHOD  throwMethod = NULL_THROW_METHOD,
XMOG_TOJAVA_METHOD  toJavaMethod = NULL_TOJAVA_METHOD,
XMOG_FROMJAVA_METHOD  fromJavaMethod = NULL_FROMJAVA_METHOD,
xmog_localenv env = NULL 
)

The constructor that creates an instance based on the classname and a named configuration.

This constructor can be used to easily create a wrapper instance that is associated with a named configuration (the named configuration would contain classpath information necessary to locate the type). The code generator will tpyically use this form of the constructor to associate a Java type with configuration information. Depending on the configuration mechanism you are using, this information might be used or not.

Parameters
classNameUTFthe UTF representation of the classname. The classname should be provided in slash-separated (internal) format.
versionthe version number of the named configuration.
configthe name of the named configuration.
bDelayInittrue if the wrapper instance should immediately try to load the Java type, false if not. A generated framework typically uses delayed initialization to give the programmer a chance to control the time at which the JVM is loaded. The default value is false.
factoryMethodthe method that returns a dynamically allocated instance of a proxy type based on an existing JNI reference.
throwMethodthe method that throws an exception of a proxy type based on an existing JNI reference.
toJavaMethodthe method that creates and initializes a Java object for a native object.
fromJavaMethodthe method that creates and initializes a native object for a Java object.
envthe local environment to use. The default value is NULL.

◆ xmog_java_class() [3/5]

xmog_java_class::xmog_java_class ( const char *  classNameUTF,
jbyte *  bytes,
jint  length,
bool  bDelayInit = false,
XMOG_FACTORY_METHOD  factoryMethod = NULL_FACTORY_METHOD,
XMOG_THROW_METHOD  throwMethod = NULL_THROW_METHOD,
XMOG_TOJAVA_METHOD  toJavaMethod = NULL_TOJAVA_METHOD,
XMOG_FROMJAVA_METHOD  fromJavaMethod = NULL_FROMJAVA_METHOD,
xmog_localenv env = NULL 
)

The constructor that creates an instance based on class bytes.

This constructor can be used to easily create a wrapper instance that injects a Java type defined in native code into the JVM.

Parameters
classNameUTFthe UTF representation of the classname. The classname should be provided in slash-separated (internal) format.
bytesthe class bytes.
lengththe number of bytes that represent the type.
bDelayInittrue if the wrapper instance should immediately try to load the Java type, false if not. A generated framework typically uses delayed initialization to give the programmer a chance to control the time at which the JVM is loaded. The default value is false.
factoryMethodthe method that returns a dynamically allocated instance of a proxy type based on an existing JNI reference.
throwMethodthe method that throws an exception of a proxy type based on an existing JNI reference.
toJavaMethodthe method that creates and initializes a Java object for a native object.
fromJavaMethodthe method that creates and initializes a native object for a Java object.
envthe local environment to use. The default value is NULL.

◆ xmog_java_class() [4/5]

xmog_java_class::xmog_java_class ( const char *  classNameUTF,
jbyte *  bytes,
jint  length,
jbyte *  stubBytes,
jint  stubLength,
jbyte *  skelBytes,
jint  skelLength,
bool  bDelayInit = false,
XMOG_FACTORY_METHOD  factoryMethod = NULL_FACTORY_METHOD,
XMOG_THROW_METHOD  throwMethod = NULL_THROW_METHOD,
XMOG_TOJAVA_METHOD  toJavaMethod = NULL_TOJAVA_METHOD,
XMOG_FROMJAVA_METHOD  fromJavaMethod = NULL_FROMJAVA_METHOD,
xmog_localenv env = NULL 
)

The constructor that creates an instance based on class bytes.

This constructor can be used to easily create a wrapper instance that injects a Java type defined in native code into the JVM.

Parameters
classNameUTFthe UTF representation of the classname. The classname should be provided in slash-separated (internal) format.
bytesthe class bytes.
lengththe number of bytes that represent the type.
stubBytesthe class bytes of the RMI stub type.
stubLengththe number of bytes that represent the RMI stub type.
skelBytesthe RMI skeleton class bytes.
skelLengththe number of bytes that represent the RMI skeleton type.
bDelayInittrue if the wrapper instance should immediately try to load the Java type, false if not. A generated framework typically uses delayed initialization to give the programmer a chance to control the time at which the JVM is loaded. The default value is false.
factoryMethodthe method that returns a dynamically allocated instance of a proxy type based on an existing JNI reference.
throwMethodthe method that throws an exception of a proxy type based on an existing JNI reference.
toJavaMethodthe method that creates and initializes a Java object for a native object.
fromJavaMethodthe method that creates and initializes a native object for a Java object.
envthe local environment to use. The default value is NULL.

◆ xmog_java_class() [5/5]

xmog_java_class::xmog_java_class ( jclass  _local,
xmog_flags  _flags,
const char *  classNameUTF = NULL,
xmog_localenv env = NULL 
)

The constructor that creates an instance based on an existing JNI reference.

This constructor can be used to easily create a wrapper instance that wraps around a JNI reference to a class.

Parameters
_localthe JNI reference. This can be any type of reference but the _flags field needs to have the corresponding type bit set.
_flagsthe reference type information.
classNameUTFthe UTF representation of the classname. The classname should be provided in slash-separated (internal) format. The default value is NULL, in which case the name will be calculated.
envthe local environment to use. The default value is NULL.

Member Function Documentation

◆ add_class()

static void xmog_java_class::add_class ( xmog_java_class clazz)
static

Adds a proxy class to the proper list of classes.

Depending on the value of teh various factory methods, the class instance gets added to the list of types and possibly to the list of exception types.

Parameters
clazzthe class to add.

◆ add_field()

void xmog_java_class::add_field ( xmog_java_field _field)

Adds a field to the list of fields that this instance is aware of.

This method does not perform any searches to prevent the insertion of duplicate entries. The developer is in charge of making sure that fields are not added more than once. Problems would arise if the same dynamically allocated instance were added more than once because the corresponding remove method will call delete() on the instance and any removal after the first one would cause memory corruption.

Parameters
_fieldthe field wrapper instance to add.

◆ add_method()

void xmog_java_class::add_method ( xmog_java_method _method)

Adds a method to the list of methods that this instance is aware of.

This method does not perform any searches to prevent the insertion of duplicate entries. The developer is in charge of making sure that fields are not added more than once. Problems would arise if the same dynamically allocated instance were added more than once because the corresponding remove method will call delete() on the instance and any removal after the first one would cause memory corruption.

Parameters
_methodthe method wrapper instance to add.

◆ addDirectoryJarFiles()

static void xmog_java_class::addDirectoryJarFiles ( const char *  dirnameUTF,
bool  preferred = false,
xmog_localenv env = NULL 
)
static

Adds all jarfiles in the specified directory to the classpath used by the custom classloader.

This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
dirnameUTFthe name of the directory in which we look for jarfiles that will be added to the classpath.
preferredtrue if the classes in that classpath root should override classes. that might already be loaded by a parent classloader. The default value is false.
envthe local environment to use. The default value is NULL.

◆ addInMemoryResourceRoot()

static void xmog_java_class::addInMemoryResourceRoot ( const jbyte *  bytes,
size_t  len,
bool  preferred = false,
xmog_localenv env = NULL 
)
static

Adds the embedded classes to the classpath used by the custom classloader.

This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
bytespointer to the beginning of the memory area that contains the embedded jarfile.
lenthe number of bytes in the embedded jarfile.
preferredtrue if the classes in that classpath root should override classes. that might already be loaded by a parent classloader. The default value is false.
envthe local environment to use. The default value is NULL.

◆ addLocalResourceRoot()

static void xmog_java_class::addLocalResourceRoot ( const char *  filenameUTF,
bool  preferred = false,
xmog_localenv env = NULL 
)
static

Adds a file to the classpath used by the custom classloader.

This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
filenameUTFthe full path of the directory or file that should be added to the classpath.
preferredtrue if the classes in that classpath root should override classes that might already be loaded by a parent classloader. The default value is false.
envthe local environment to use. The default value is NULL.

◆ bootstrap()

static void xmog_java_class::bootstrap ( xmog_localenv env = NULL)
static

Injects the custom classloader types into the JVM.

This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
envthe local environment to use. The default value is NULL.

◆ calculate_hashcode()

static jint xmog_java_class::calculate_hashcode ( const char *  _classNameUTF)
static

A utility method for calculating the hashcode of a classname.

This method replaces periods in the name with slashes when calculating the hashcode. This removes a potential source of hashcode mismatches when internal and external classname representations are mixed up.

Parameters
_classNameUTFthe classname for which we wish to calculate a hash.

◆ call_bool_indirect()

static bool xmog_java_class::call_bool_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_boolean_indirect()

static jboolean xmog_java_class::call_boolean_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_byte_indirect()

static jbyte xmog_java_class::call_byte_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_char_indirect()

static jchar xmog_java_class::call_char_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_double_indirect()

static jdouble xmog_java_class::call_double_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_float_indirect()

static jfloat xmog_java_class::call_float_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_int_indirect()

static jint xmog_java_class::call_int_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_long_indirect()

static jlong xmog_java_class::call_long_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_object_indirect()

static jobject xmog_java_class::call_object_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_short_indirect()

static jshort xmog_java_class::call_short_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ call_void_indirect()

static void xmog_java_class::call_void_indirect ( xmog_java_method method,
jobject  instance,
xmog_java_values values,
xmog_localenv env 
)
static

Calls a Java method indirectly.

Parameters
methodthe method to call.
instancethe instance pointer on which to call the method. May be NULL for static methods.
valuesthe method arguments.
envthe local call environment.

◆ from()

jobject xmog_java_class::from ( const xmog_base srcInstance,
xmog_flags  flags = xmog_base::GLOBAL,
xmog_localenv env = NULL 
)

Returns an object reference or null if the given instance is incompatible with this class.

This method represents the heart of the casting mechanism in the framework. It takes one proxy instance as input and returns a proper reference if the original instance was type compatible.

Parameters
srcInstancethe instance that we wish to "convert" to the type represented by this class.
flagsthe reference type of the target instance. The default value is GLOBAL.
envthe local call environment to use. The default valus is NULL.

◆ get_best_throwable_for()

static xmog_java_class* xmog_java_class::get_best_throwable_for ( xmog_base throwable,
bool  bRemote,
xmog_localenv env = NULL 
)
static

Returns the best matching xmog_java_class instance for the given throwable and that has a non-NULL exception factory method.

This method is used to find the best available proxy type for a given exception. We don't always have the exact exception type that was thrown in Java available as a C++ proxy type. Because of that, we want to throw the best matching exception, which means that we search for the most derived type in the exception type's inheritance hierarchy.

Parameters
throwablethe exception that was thrown in Java.
bRemotetrue if the JVM is out-of-process, false otherwise.
envthe local environment to use. The default value is NULL.

◆ get_bootstrap_classloader()

static jobject xmog_java_class::get_bootstrap_classloader ( xmog_localenv env = NULL)
static

Returns the classloader used by the Codemesh framework. This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
envthe local environment to use. The default value is NULL.

◆ get_class_named()

static xmog_java_class* xmog_java_class::get_class_named ( const char *  classNameUTF)
static

Returns the xmog_java_class instance for the given name
that has a non-NULL instance factory method.

This method is used to find the proxy class for a Java class of a given name. Such a lookup is useful for scenarios where all we have is a Java classname and what we need is the proxy instance that provides

Parameters
classNameUTFthe classname in slash form, for example java/lang/String.

◆ get_exact_throwable_for()

static xmog_java_class* xmog_java_class::get_exact_throwable_for ( const char *  classNameUTF)
static

Returns the exact xmog_java_class instance for the given name that has a non-NULL exception factory method.

This method is used to find the exact exception type by name and is useful because we can easily compare based on the hashvalue.

Parameters
classNameUTFthe classname in slash form, for example java/lang/String.

◆ get_hashcode()

jint xmog_java_class::get_hashcode ( xmog_localenv env = NULL)

Returns the instance's hashcode.

The hashcode is based on the classname.

Parameters
envthe local environment pointer. The default value is NULL.

◆ get_jclass() [1/2]

jclass xmog_java_class::get_jclass ( xmog_localenv env,
bool  bSuppressExceptions 
)

Returns the internal JNI reference to the type.

Parameters
envthe local environment pointer.
bSuppressExceptionspassed to distinguish this method from the regular version of this method.

◆ get_jclass() [2/2]

jclass xmog_java_class::get_jclass ( xmog_localenv env = NULL)

Returns the internal JNI reference to the type.

Parameters
envthe local environment pointer. The default value is NULL.

◆ getClassClassName()

static char* xmog_java_class::getClassClassName ( jclass  clazz,
xmog_localenv env = NULL 
)
static

Returns the classname of a given class instance.

Parameters
clazzthe JNI class handle for which we want a classname.
envthe local environment pointer. The default value is NULL.

◆ getClassName() [1/2]

static char* xmog_java_class::getClassName ( jobject  inst,
xmog_localenv env = NULL 
)
static

Returns the classname of the given instance.

This is implemented internally by invoking getClass().getName() on the given object.

Parameters
instthe object in whose classname we;re interested.
enva local environment pointer.
Returns
the classname. The caller is responsible for cleaning up the returned value via xmog_util::setString(NULL).

◆ getClassName() [2/2]

const char* xmog_java_class::getClassName ( xmog_localenv env = NULL)

Returns the classname.

Parameters
envthe local environment pointer. The default value is NULL.

◆ has_peer_unmarshaller() [1/2]

bool xmog_java_class::has_peer_unmarshaller ( ) const

Returns true if the class has at least one peer unmarshaller registered.

Peer unmarshallers are registered using the xmog_peer::register_unmarshaller() method. Every peer unmarshaller is not just dependent on the Java type but also on the C++ type identifier.

◆ has_peer_unmarshaller() [2/2]

void xmog_java_class::has_peer_unmarshaller ( bool  bHPU)

Sets the flag that indicates that the class has at least one peer unmarshaller registered for it.

Peer unmarshallers are registered using the xmog_peer::register_unmarshaller() method. Every peer unmarshaller is not just dependent on the Java type but also on the C++ type identifier.

Parameters
bHPUtrue if the class has at least one peer unmarshaller.

◆ initThread()

static void xmog_java_class::initThread ( xmog_localenv env = NULL)
static

Performs per-thread initialization in relation with the custom classloader.

This method only works for 1.2 or later JVMs because it relies on the post 1.1 classloader specification.

Parameters
envthe local environment to use. The default value is NULL.

◆ remove_class()

static void xmog_java_class::remove_class ( xmog_java_class clazz)
static

Removes a proxy class from the proper list of classes.

Depending on the value of teh various factory methods, the class instance gets removed from the list of types and possibly from the list of exception types.

Parameters
clazzthe class to remove.

◆ remove_field()

void xmog_java_class::remove_field ( xmog_java_field _field)

Removes a field from the list of field that this instance is aware of.

The developer is in charge of making sure that fields are not added more than once. Problems would arise if the same dynamically allocated instance were added more than once because the remove method will call delete() on the instance and any removal after the first one would cause memory corruption.

Parameters
_fieldthe field wrapper instance to remove.

◆ remove_method()

void xmog_java_class::remove_method ( xmog_java_method _method)

Removes a method from the list of methods that this instance is aware of.

The developer is in charge of making sure that fields are not added more than once. Problems would arise if the same dynamically allocated instance were added more than once because the remove method will call delete() on the instance and any removal after the first one would cause memory corruption.

Parameters
_methodthe method wrapper instance to remove.

◆ setInterceptor()

void xmog_java_class::setInterceptor ( XMOG_INTERCEPTOR  icp)

Sets an API interceptor for the Java type represented by this instance.

API interceptors allow the overriding of proxy API invocations on a per-type basis. This allows you to customize the way a C++ proxy type interacts with its corresponding Java type. You could for example implement caching schemes using an interceptor or you could implement schemes that translate field accesses into method invocations.

Parameters
icpan interceptor that will handle certain kinds of accesses for this type.

The documentation for this class was generated from the following file:

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.