00001
00002
00003
00004
00005 #ifndef xmog_java_class_inc
00006 #define xmog_java_class_inc
00007
00008
00009 class xmog_localenv;
00010 class xmog_java_field;
00011 class xmog_java_method;
00012 struct xmog_java_values;
00013
00014
00015 #include "xmog_java_ref.h"
00016
00017
00030 class XMOG_DECLSPEC xmog_java_class : public xmog_java_ref
00031 {
00032 public:
00033
00045 typedef void (XMOG_CALLING_CONVENTION *XMOG_THROW_METHOD)( jobject exc, xmog_flags flags );
00046
00052 static XMOG_THROW_METHOD NULL_THROW_METHOD;
00053
00068 typedef xmog_java_ref * (XMOG_CALLING_CONVENTION *XMOG_FACTORY_METHOD)( jobject obj, xmog_flags src, xmog_flags dest, const char * classNameUTF, xmog_localenv * env );
00069
00073 static XMOG_FACTORY_METHOD NULL_FACTORY_METHOD;
00074
00092 typedef xmog_java_ref * (XMOG_CALLING_CONVENTION *XMOG_TOJAVA_METHOD)( xmog_java_ref * nobj, xmog_localenv * env );
00093
00097 static XMOG_TOJAVA_METHOD NULL_TOJAVA_METHOD;
00098
00112 typedef xmog_java_ref * (XMOG_CALLING_CONVENTION *XMOG_FROMJAVA_METHOD)( xmog_java_ref * jobj, xmog_localenv * env );
00113
00117 static XMOG_FROMJAVA_METHOD NULL_FROMJAVA_METHOD;
00118
00122 enum xmog_interceptor_result
00123 {
00124 IcpDoneWithResult = 1,
00125 IcpContinue = 0,
00126 IcpError = -1
00127 };
00128
00132 enum xmog_interceptor_when
00133 {
00134 IcpBefore = 0,
00135 IcpAfter = 1
00136 };
00137
00141 enum xmog_interceptor_what
00142 {
00143 IcpFieldGet = 0,
00144 IcpFieldSet = 1,
00145 IcpMethod = 2,
00146 IcpCtor = 3,
00147 IcpArrayCreate = 4,
00148 IcpArrayGet = 5,
00149 IcpArraySet = 6,
00150 IcpStringFromNativeChars = 7,
00151 IcpNativeCharsFromString = 8,
00152 IcpIsNull = 9,
00153 IcpIsInstanceOf = 10,
00154 IcpSpecial = 16
00155 };
00156
00173 typedef xmog_interceptor_result (XMOG_CALLING_CONVENTION *XMOG_INTERCEPTOR)(
00174 xmog_base * obj,
00175 xmog_java_dynamic * dyn,
00176 xmog_java_values * vals,
00177 xmog_interceptor_when when,
00178 xmog_interceptor_what what,
00179 xmog_java_value * result,
00180 xmog_localenv * env,
00181 xmog_flags & flags );
00182
00183 private:
00184
00188 static jbyte MAXIMUM_SUPPORTED_MAJOR_VERSION;
00189
00190 XMOG_FACTORY_METHOD factoryMethod_;
00191
00192 XMOG_THROW_METHOD throwMethod_;
00193
00194 XMOG_TOJAVA_METHOD toJavaMethod_;
00195
00196 XMOG_FROMJAVA_METHOD fromJavaMethod_;
00197
00198 char * classNameUTF_;
00199
00200 char * version_;
00201
00202 char * config_;
00203
00204 jbyte * bytes_;
00205
00206 jint length_;
00207
00208 jbyte * stubBytes_;
00209
00210 jint stubLength_;
00211
00212 jbyte * skelBytes_;
00213
00214 jint skelLength_;
00215
00216 jint hash_code_;
00217
00218 jint array_dim_;
00219
00220 bool bDelayInit_;
00221
00222 bool bOwnsClassName_;
00223
00224 bool bIsException_;
00225
00226 bool bInRemove_;
00227
00228 bool bHasUnmarshaller_;
00229
00230 xmog_java_field * fields_;
00231
00232 xmog_java_method * methods_;
00233
00234 xmog_java_class * array_class_;
00235
00236 xmog_java_class * next_class_;
00237
00238 xmog_java_class * next_throwable_;
00239
00240
00241 XMOG_INTERCEPTOR icp_;
00242
00243
00244 static int ICP_COUNT;
00245
00246 void initClassFromClassName( xmog_localenv * env = NULL, bool bSuppressExceptions = false );
00247
00248 void initClassNameFromRef( xmog_localenv * env = NULL );
00249
00250 public:
00251
00255 xmog_java_class();
00256
00277 xmog_java_class( const char * classNameUTF,
00278 bool bDelayInit = false,
00279 XMOG_FACTORY_METHOD factoryMethod = NULL_FACTORY_METHOD,
00280 XMOG_THROW_METHOD throwMethod = NULL_THROW_METHOD,
00281 XMOG_TOJAVA_METHOD toJavaMethod = NULL_TOJAVA_METHOD,
00282 XMOG_FROMJAVA_METHOD fromJavaMethod = NULL_FROMJAVA_METHOD,
00283 xmog_localenv * env = NULL );
00284
00310 xmog_java_class( const char * classNameUTF,
00311 const char * version,
00312 const char * config,
00313 bool bDelayInit = false,
00314 XMOG_FACTORY_METHOD factoryMethod = NULL_FACTORY_METHOD,
00315 XMOG_THROW_METHOD throwMethod = NULL_THROW_METHOD,
00316 XMOG_TOJAVA_METHOD toJavaMethod = NULL_TOJAVA_METHOD,
00317 XMOG_FROMJAVA_METHOD fromJavaMethod = NULL_FROMJAVA_METHOD,
00318 xmog_localenv * env = NULL );
00319
00342 xmog_java_class( const char * classNameUTF,
00343 jbyte * bytes,
00344 jint length,
00345 bool bDelayInit = false,
00346 XMOG_FACTORY_METHOD factoryMethod = NULL_FACTORY_METHOD,
00347 XMOG_THROW_METHOD throwMethod = NULL_THROW_METHOD,
00348 XMOG_TOJAVA_METHOD toJavaMethod = NULL_TOJAVA_METHOD,
00349 XMOG_FROMJAVA_METHOD fromJavaMethod = NULL_FROMJAVA_METHOD,
00350 xmog_localenv * env = NULL );
00351
00378 xmog_java_class( const char * classNameUTF,
00379 jbyte * bytes,
00380 jint length,
00381 jbyte * stubBytes,
00382 jint stubLength,
00383 jbyte * skelBytes,
00384 jint skelLength,
00385 bool bDelayInit = false,
00386 XMOG_FACTORY_METHOD factoryMethod = NULL_FACTORY_METHOD,
00387 XMOG_THROW_METHOD throwMethod = NULL_THROW_METHOD,
00388 XMOG_TOJAVA_METHOD toJavaMethod = NULL_TOJAVA_METHOD,
00389 XMOG_FROMJAVA_METHOD fromJavaMethod = NULL_FROMJAVA_METHOD,
00390 xmog_localenv * env = NULL );
00391
00406 xmog_java_class( jclass _local, xmog_flags _flags, const char * classNameUTF = NULL, xmog_localenv * env = NULL );
00407
00412 void * operator new ( size_t );
00413
00418 void operator delete( void * );
00419
00420 virtual ~xmog_java_class();
00421
00432 void has_peer_unmarshaller( bool bHPU );
00433
00442 bool has_peer_unmarshaller() const;
00443
00450 jint get_hashcode( xmog_localenv * env = NULL );
00451
00457 jclass get_jclass( xmog_localenv * env = NULL );
00458
00466 jclass get_jclass( xmog_localenv * env, bool bSuppressExceptions );
00467
00471 const char * get_class_name() const;
00472
00478 const char * getClassName( xmog_localenv * env = NULL );
00479
00491 void add_field( xmog_java_field * _field );
00492
00496 xmog_java_field * get_fields();
00497
00508 void remove_field( xmog_java_field * _field );
00509
00521 void add_method( xmog_java_method * _method );
00522
00526 xmog_java_method * get_methods();
00527
00538 void remove_method( xmog_java_method * _method );
00539
00549 static jint calculate_hashcode( const char * _classNameUTF );
00550
00557 static jobject get_bootstrap_classloader( xmog_localenv * env = NULL );
00558
00567 static void bootstrap( xmog_localenv * env = NULL );
00568
00576 static void initThread( xmog_localenv * env = NULL );
00577
00586 static void add_class( xmog_java_class * clazz );
00587
00596 static void remove_class( xmog_java_class * clazz );
00597
00601 static xmog_java_class * get_classes();
00602
00606 static xmog_java_class * get_throwables();
00607
00621 void throw_( jthrowable throwable, xmog_flags flags, int error_code = 0, xmog_localenv * env = NULL );
00622
00634 static char * getClassName( jobject inst, xmog_localenv * env = NULL );
00635
00642 static char * getClassClassName( jclass clazz, xmog_localenv * env = NULL );
00643
00653 static xmog_java_class * get_exact_throwable_for( const char * classNameUTF );
00654
00669 static xmog_java_class * get_best_throwable_for( xmog_base * throwable, bool bRemote, xmog_localenv * env = NULL );
00670
00681 static xmog_java_class * get_class_named( const char * classNameUTF );
00682
00687 xmog_java_class * get_array_class();
00688
00701 jobject from( const xmog_base & srcInstance, xmog_flags flags = xmog_base::GLOBAL, xmog_localenv * env = NULL );
00702
00706 static jbyte calculateMaximumSupportedClassVersion();
00707
00719 static void addLocalResourceRoot( const char * filenameUTF, bool preferred = false, xmog_localenv * env = NULL );
00720
00732 static void addInMemoryResourceRoot( const jbyte * bytes, size_t len, bool preferred = false, xmog_localenv * env = NULL );
00733
00745 static void addDirectoryJarFiles( const char * dirnameUTF, bool preferred = false, xmog_localenv * env = NULL );
00746
00750 static void setSecurityManager( xmog_java_method & mSSM, const xmog_java_ref & sm, xmog_localenv * env );
00751
00760 static bool call_bool_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00761
00770 static jboolean call_boolean_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00771
00780 static jbyte call_byte_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00781
00790 static jchar call_char_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00791
00800 static jdouble call_double_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00801
00810 static jfloat call_float_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00811
00820 static jint call_int_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00821
00830 static jlong call_long_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00831
00840 static jshort call_short_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00841
00850 static jobject call_object_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00851
00860 static void call_void_indirect( xmog_java_method * method, jobject instance, xmog_java_values * values, xmog_localenv * env );
00861
00865 static xmog_java_method & getClass_method();
00866
00870 static xmog_java_method & isInstance_method();
00871
00884 void setInterceptor( XMOG_INTERCEPTOR icp );
00885
00889 xmog_java_class::XMOG_INTERCEPTOR getInterceptor() const;
00890
00894 static int getInterceptorCount();
00895 };
00896
00897
00898 #if !defined (XMOG_LACKS_INLINE_FUNCTIONS)
00899 # include "xmog_java_class.inl"
00900 #endif
00901
00902
00903
00904 #endif