@@ -38,51 +38,15 @@ REPC SEXP RgetObjectArrayCont(SEXP e) {
3838 return ar ;
3939}
4040
41- /** get contents of the object array in the form of int* */
41+ /** get contents of the object array in the form of STRSXP vector */
4242REPC SEXP RgetStringArrayCont (SEXP e ) {
43- SEXP ar ;
44- jarray o ;
45- int l ,i ;
46- const char * c ;
47- JNIEnv * env = getJNIEnv ();
48-
49- profStart ();
43+ SEXP ar = R_NilValue ;
5044 if (e == R_NilValue ) return R_NilValue ;
5145 if (TYPEOF (e )== EXTPTRSXP ) {
5246 jverify (e );
53- o = ( jobject )EXTPTR_PTR (e );
47+ ar = getStringArrayCont ( ( jarray )EXTPTR_PTR (e ) ) ;
5448 } else
5549 error ("invalid object parameter" );
56- _dbg (rjprintf ("RgetStringArrayCont: jarray %x\n" ,o ));
57- if (!o ) return R_NilValue ;
58- l = (int )(* env )-> GetArrayLength (env , o );
59- _dbg (rjprintf (" convert string array of length %d\n" ,l ));
60- if (l < 0 ) return R_NilValue ;
61- PROTECT (ar = allocVector (STRSXP ,l ));
62- i = 0 ;
63- while (i < l ) {
64- jobject sobj = (* env )-> GetObjectArrayElement (env , o , i );
65- _mp (MEM_PROF_OUT (" %08x LNEW object array element [%d]\n" , (int ) sobj , i ))
66- c = 0 ;
67- if (sobj ) {
68- /* we could (should?) check the type here ...
69- if (!(*env)->IsInstanceOf(env, sobj, javaStringClass)) {
70- printf(" not a String\n");
71- } else
72- */
73- c = (* env )-> GetStringUTFChars (env , sobj , 0 );
74- }
75- if (!c )
76- SET_STRING_ELT (ar , i , R_NaString );
77- else {
78- SET_STRING_ELT (ar , i , mkCharUTF8 (c ));
79- (* env )-> ReleaseStringUTFChars (env , sobj , c );
80- }
81- if (sobj ) releaseObject (env , sobj );
82- i ++ ;
83- }
84- UNPROTECT (1 );
85- _prof (profReport ("RgetStringArrayCont[%d]:" ,o ))
8650 return ar ;
8751}
8852
@@ -357,3 +321,114 @@ REPC SEXP RgetLongArrayCont(SEXP e) {
357321 _prof (profReport ("RgetLongArrayCont[%d]:" ,o ));
358322 return ar ;
359323}
324+
325+
326+ /* these below have been factored out of the ones above so that they
327+ can also be used internally in jni code */
328+
329+ /**
330+ * get contents of the String array in the form of STRSXP vector
331+ *
332+ * @param e a pointer to a String[] object
333+ *
334+ * @return a STRSXP vector mirroring the java array
335+ */
336+ HIDE SEXP getStringArrayCont (jarray o ) {
337+ SEXP ar ;
338+ int l ,i ;
339+ const char * c ;
340+ JNIEnv * env = getJNIEnv ();
341+
342+ profStart ();
343+
344+ _dbg (rjprintf ("RgetStringArrayCont: jarray %x\n" ,o ));
345+ if (!o ) return R_NilValue ;
346+ l = (int )(* env )-> GetArrayLength (env , o );
347+ _dbg (rjprintf (" convert string array of length %d\n" ,l ));
348+ if (l < 0 ) return R_NilValue ;
349+ PROTECT (ar = allocVector (STRSXP ,l ));
350+ i = 0 ;
351+ while (i < l ) {
352+ jobject sobj = (* env )-> GetObjectArrayElement (env , o , i );
353+ _mp (MEM_PROF_OUT (" %08x LNEW object array element [%d]\n" , (int ) sobj , i ))
354+ c = 0 ;
355+ if (sobj ) {
356+ /* we could (should?) check the type here ...
357+ if (!(*env)->IsInstanceOf(env, sobj, javaStringClass)) {
358+ printf(" not a String\n");
359+ } else
360+ */
361+ c = (* env )-> GetStringUTFChars (env , sobj , 0 );
362+ }
363+ if (!c )
364+ SET_STRING_ELT (ar , i , R_NaString );
365+ else {
366+ SET_STRING_ELT (ar , i , mkCharUTF8 (c ));
367+ (* env )-> ReleaseStringUTFChars (env , sobj , c );
368+ }
369+ if (sobj ) releaseObject (env , sobj );
370+ i ++ ;
371+ }
372+ UNPROTECT (1 );
373+ _prof (profReport ("RgetStringArrayCont[%d]:" ,o ))
374+ return ar ;
375+ }
376+
377+
378+ /**
379+ * Get the list of class names of a java object
380+ * This is a jni wrapper around the RJavaTools.getSimpleClassNames method
381+ */
382+ HIDE jarray getSimpleClassNames ( jobject o , jboolean addConditionClasses ){
383+
384+ JNIEnv * env = getJNIEnv ();
385+ jarray a ;
386+
387+ profStart ();
388+ a = (jarray ) (* env )-> CallStaticObjectMethod (env ,
389+ rj_RJavaTools_Class , mid_rj_getSimpleClassNames ,
390+ o , addConditionClasses ) ;
391+ _prof (profReport ("getSimpleClassNames[%d]:" ,o )) ;
392+ return a ;
393+ }
394+
395+ /**
396+ * Get the list of class names of a java object, and
397+ * structure it as a STRSXP vector
398+ */
399+ HIDE SEXP getSimpleClassNames_asSEXP ( jobject o , jboolean addConditionClasses ){
400+ return getStringArrayCont ( getSimpleClassNames ( o , addConditionClasses ) );
401+ }
402+
403+ /**
404+ * Returns the STRSXP vector of simple class names of the object o
405+ */
406+ REPC SEXP RgetSimpleClassNames ( SEXP e , SEXP addConditionClasses ){
407+
408+ SEXP ar = R_NilValue ;
409+ if (e == R_NilValue ) return R_NilValue ;
410+ jobject jobj ;
411+ if (TYPEOF (e )== EXTPTRSXP ) {
412+ jverify (e );
413+ jobj = (jobject )EXTPTR_PTR (e ) ;
414+ } else {
415+ error ("invalid object parameter" );
416+ }
417+
418+ Rboolean add ;
419+ switch (TYPEOF (addConditionClasses )) {
420+ case LGLSXP :
421+ add = LOGICAL (addConditionClasses )[0 ];
422+ break ;
423+ case INTSXP :
424+ add = INTEGER (addConditionClasses )[0 ];
425+ break ;
426+ default :
427+ add = asLogical (addConditionClasses );
428+ }
429+
430+ ar = getSimpleClassNames_asSEXP ( jobj , (jboolean )add ) ;
431+
432+ return ar ;
433+ }
434+
0 commit comments