示例#1
0
/**
 * Invokes the constructor with the given JArguments.
 * Allocates a new local reference.
 *
 * @throws JNIException if an error occurs while trying to invoke the constructor.
 * @throws a matching C++ proxy, if a java exception is thrown by the constructor.
 *
 */
jobject JConstructor::invoke( const JArguments& arguments ) {


  /* Get the methodID for the constructor matching the given arguments.
   */
//  cout << "JConstructor::invoke - Retrieving the methodID..." << endl;
  jmethodID methodID = getMethodID( mClass, arguments );
//  cout << "JConstructor::invoke - Retrieved the methodID." << endl;

  /* Call the constructor
   */
//  cout << "JConstructor::invoke - Attaching..." << endl;
  JNIEnv* env = helper::attach();
//  cout << "JConstructor::invoke - Attached." << endl;
 
//  cout << "JConstructor::invoke - Creating the object..." << endl;
  jobject result;
	vector<jvalue> argArray = toVector( arguments );

	if (argArray.size() > 0)
		result = env->NewObjectA( mClass->getClass(), methodID, &argArray[ 0 ] );
	else
		result = env->NewObject( mClass->getClass(), methodID );
//  cout << "JConstructor::invoke - Created the object..." << endl;

  /* Catch any java exception that occured during the method call,
   * and throw it as a C++ exception.
   */
//  cout << "JConstructor::invoke - Checking for exceptions..." << endl;
  helper::catchAndThrow();
//  cout << "JConstructor::invoke - Found no exceptions." << endl;

  return result;
}
示例#2
0
jmethodID CJNIUtil::getMethodID(char *className, char *methodName, char *methodSig)
{
	jclass c = getClass(className);
	if (!c) return NULL;

	return getMethodID(c, methodName, methodSig);
}
示例#3
0
jobjectArray CJNIUtil::X3DParser_getDefNames(jobject x3dParser)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return NULL;
	}

	if (!x3dParser) return NULL;

	// -----------------------------------------------
	//	get method id
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "getDefNames";
	char *methodSig = "()[Ljava/lang/String;";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return NULL;
	}

	// -----------------------------------------------
	//	call java's method
	// -----------------------------------------------
	jobjectArray defNames = (jobjectArray)(m_env->CallObjectMethod(x3dParser, mid));

	return defNames;
}
示例#4
0
jobjectArray CJNIUtil::X3DParser_getChildrenOfRootNode(jobject x3dParser)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return NULL;
	}

	if (!x3dParser) return NULL;

	// -----------------------------------------------
	//	get method id
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "getChildrenOfRootNode";
	char *methodSig = "()[Lorg/web3d/vrml/lang/VRMLNode;";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return NULL;
	}

	// -----------------------------------------------
	//	call java's method
	// -----------------------------------------------
	jobjectArray vrmlNodeArray = (jobjectArray)(m_env->CallObjectMethod(x3dParser, mid));

	return vrmlNodeArray;
}
示例#5
0
// -----------------------------------------------
// -----------------------------------------------
bool CJNIUtil::X3DParser_parse(jobject x3dParser, char *fname)
{
	if (!m_env)
	{
		CX3DParser::printLog("java vm haven't started\n");
		return false;
	}

	if (!x3dParser) return false;

	// -----------------------------------------------
	//	get method id of X3DParse.parse()
	// -----------------------------------------------
	char *className = "X3DParser";
	char *methodName = "parse";
	char *methodSig = "(Ljava/lang/String;)Z";

	jmethodID mid = getMethodID(className, methodName, methodSig);
	if (!mid)
	{
		CX3DParser::printLog("cannot get methodID of %s", methodName);
		return false;
	}

	// -----------------------------------------------
	//	make argument
	// -----------------------------------------------
	jstring utf8_fname = m_env->NewStringUTF(fname);

	// -----------------------------------------------
	//	call java's parser
	// -----------------------------------------------
	return (m_env->CallBooleanMethod(x3dParser, mid, utf8_fname) == JNI_TRUE) ? true : false;
}
KDint xmPlatformSoundOpen ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundOpen", "(IILjava/lang/String;)I" );

	if ( method )
	{	
		jstring  jpath  = 0;
		jint     jasset = 0;
		
		if ( !kdStrcmp ( sound->vpath, "/res" ) )
		{
			jpath  = (*l_env)->NewStringUTF ( l_env, &sound->path [ 5 ] );
			jasset = 1;
		}
		else
		{
			jpath = (*l_env)->NewStringUTF ( l_env, sound->fpath );
			jasset = 0;
		}

		sound->device = (KDvoid*) (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) ( sound->mode & XM_SOUND_EFFECT ), jasset, jpath );
	}

	return sound->device ? 0 : -1;
}
/* This returns a new java.awt.Rectangle object if everything goes
   right, with the supplied x, y, width, and height.  If anything goes
   wrong we will call handleError and return NULL. */
static jobject newRectangle(JNIEnv *env, 
			    jint x, jint y, jint width, jint height)
{
  jclass    rectangleClass;
  jmethodID rectangleConstructor;
  jobject   newRectangle;

  rectangleClass = getClass(env, "java/awt/Rectangle", 
			    "Unable to get the java.awt.Rectangle class");
  if (rectangleClass == 0) {
    return NULL;
  }

  rectangleConstructor = getMethodID(env, rectangleClass,
				     "<init>", "(IIII)V", 
				     "Unable to get the init method for the "
				     "java.awt.Rectangle class");
  if (rectangleConstructor == 0) {
    return NULL;
  }

  newRectangle = (*env)->NewObject(env, rectangleClass,
				   rectangleConstructor, x, y, width, height);
  if (newRectangle == 0) {
    handleError(env, "OpenGL/OpenGLNativeException",
		"Unable to create new Rectangle");
    return NULL;
  }
  return newRectangle;
}
示例#8
0
jobject JavaClass::newInstance() 
{
    jmethodID constructor = getMethodID("<init>", "()V");
	JNI_ASSERT_NOT_NULL(constructor,"JavaClass::newInstance, failed to retrieve default constructor");	
    jobject javaObject = env->NewObject(javaClass, constructor);
    JNI_ASSERT_NOT_NULL(javaObject,"JavaClass::newInstance, failed to create instance");	
    return javaObject;
}
void Soprano::Sesame2::RepositoryConnection::close()
{
    jmethodID closeMethodId = getMethodID( "close", "()V" );
    if ( closeMethodId ) {
        callVoidMethod( closeMethodId );
        JNIWrapper::instance()->debugException();
    }
}
示例#10
0
u32 JdwpWalker::getMethodID(const QString& cls_name, const QString& name, const QString& signature) {
    u64 cls_id = getClassID(cls_name);
    u32 ret = 0;
    if (cls_id != 0) {
        ret = getMethodID(cls_id, name, signature);
    }
    return ret;
}
KDvoid xmPlatformEventDetach ( KDenum mode )
{
	jmethodID  method = getMethodID ( "SetDetach", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, (jint) mode );
	}	    
}
KDvoid xmPlatformSetFullScreen ( KDbool enable )
{
    jmethodID  method = getMethodID ( "SetFullScreen", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, enable );
	}
}
KDvoid xmPlatformVibrate ( KDuint msec )
{
    jmethodID  method = getMethodID ( "Vibrate", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, msec );
	}
}
KDvoid xmPlatformSetIMEKeyboardState ( KDbool show )
{
	jmethodID  method = getMethodID ( "SetIMEKeyboardState", "(I)I" );
	
	if ( method )
	{
		(*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) show );
	}	
}
// xmPlatformSetFrameInterval : Set Frame Interval.
// If input value is 0 then no interval timing.
KDvoid xmPlatformSetFrameInterval ( KDdouble interval )
{
	jmethodID  method = getMethodID ( "SetFrameInterval", "(D)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, interval );
	}	
}
KDvoid xmPlatformExit ( KDint status )
{
	jmethodID  method = getMethodID ( "Exit", "(I)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, status );
	}
}
KDvoid xmPlatformSetBrightness ( KDfloat value )
{
    jmethodID  method = getMethodID ( "SetBrightness", "(F)V" );

	if ( method )
	{
		(*l_env)->CallStaticVoidMethod ( l_env, l_class, method, value );
	}
}
	void stopBackgroundMusicJNI()
	{
		// void stopBackgroundMusic()
		jmethodID stopBackgroundMusicMethodID = getMethodID("stopBackgroundMusic", "()V");

		if (stopBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, stopBackgroundMusicMethodID);
		}
	}
	void endJNI()
	{
		// void end()
		jmethodID endMethodID = getMethodID("end", "()V");

		if (endMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, endMethodID);
		}
	}
	void setEffectsVolumeJNI(float volume)
	{
		// void setEffectsVolume(float)
		jmethodID setEffectsVolumeMethodID = getMethodID("setEffectsVolume", "(F)V");

		if (setEffectsVolumeMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, setEffectsVolumeMethodID, volume);
		}
	}
	void rewindBackgroundMusicJNI()
	{
		// void rewindBackgroundMusic()
		jmethodID rewindBackgroundMusicMethodID = getMethodID("rewindBackgroundMusic", "()V");

		if (rewindBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, rewindBackgroundMusicMethodID);
		}
	}
	void stopEffectJNI(unsigned int nSoundId)
	{
		// void stopEffect(int)
		jmethodID stopEffectMethodID = getMethodID("stopEffect", "(I)V");

		if (stopEffectMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, stopEffectMethodID, (int)nSoundId);
		}
	}
	void pauseBackgroundMusicJNI()
	{
		// void pauseBackgroundMusic()
		jmethodID pauseBackgroundMusicMethodID = getMethodID("pauseBackgroundMusic", "()V");

		if (pauseBackgroundMusicMethodID)
		{
			env->CallStaticVoidMethod(classOfCocos2dxActivity, pauseBackgroundMusicMethodID);
		}
	}
KDint xmPlatformTTSSetPitch ( KDfloat pitch )
{
    jmethodID  method = getMethodID ( "TTSSetPitch", "(F)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, pitch );
	}

	return -1;
}
KDint xmPlatformSoundSetPosition ( XMSound* sound, KDint pos )
{
	jmethodID  method = getMethodID ( "SoundSetPosition", "(II)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device, (jint) pos );
	}

	return -1;
}
KDint xmPlatformTTSStop ( KDvoid )
{
    jmethodID  method = getMethodID ( "TTSStop", "()I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method );
	}

	return -1;
}
KDint xmPlatformSoundGetDuration ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundGetDuration", "(I)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device );
	}

	return -1;
}
KDint xmPlatformTTSSetLocale ( KDint locale )
{
    jmethodID  method = getMethodID ( "TTSSetLocale", "(I)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, locale );
	}

	return -1;
}
KDint xmPlatformTTSSetRate ( KDfloat rate )
{
    jmethodID  method = getMethodID ( "TTSSetRate", "(F)I" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, rate );
	}

	return -1;
}
KDfloat xmPlatformSoundGetVolume ( XMSound* sound )
{
	jmethodID  method = getMethodID ( "SoundGetVolume", "(I)F" );

	if ( method )
	{
		return (*l_env)->CallStaticIntMethod ( l_env, l_class, method, (jint) sound->device );
	}

	return -1;
}