Esempio n. 1
0
/**
 * Gets the method id matching the given arguments.
 *
 */
jmethodID JConstructor::getMethodID( const JClass* jClass, const JArguments& arguments ) {

  /* We cache the jmethodID locally, so if we've already found it,
   * we don't need to go looking for it again.
   */
  if ( mMethodID ) {
    return mMethodID;
  }

  /* If we don't already have the jmethodID, we need to determine
   * the signature of this method.
   */

  /* We construct this signature with a void return type,
   * because the return type for constructors is void.
   */
  JSignature signature( *JVoid::staticGetJavaJniClass() ); 
  typedef list<JValue*> ValueList;
  ValueList args = arguments.asList();
  
  ValueList::iterator i = args.begin();
  ValueList::iterator end = args.end();

  for ( ; i != end; ++i ) {
    JValue* value = *i;
    signature << *value->getJavaJniClass();
  }

  string methodSignature = signature.toString();

  /* Now that we have the signature for the method, we could look
   * in a global cache for the jmethodID corresponding to this method,
   * but for now, we'll always find it.
   */
  JNIEnv* env = helper::attach();

  mMethodID = env->GetMethodID( jClass->getClass(), "<init>", methodSignature.c_str() );

  if ( mMethodID == NULL ) {
    string msg = string( "JConstructor::getMethodID\n" ) +
                 "Unable to find a constructor for " + jClass->getName() + "\n" +
                 "The signature is <" + methodSignature + ">";
		try
		{
			helper::catchAndThrow();
		}
		catch (JNIException e)
		{
			msg.append("\ncaused by:\n");
			msg.append(e.what());
		}
    throw JNIException( msg );
  }

  return mMethodID;
}
Esempio n. 2
0
/**
 * Transforms a JArguments to a vector of jvalue's.
 */
vector<jvalue> toVector(const JArguments& arguments)
{
  typedef list<const JValue*> ValueList;
  vector<jvalue> argsVector;
  ValueList argsList = arguments.asList();

  ValueList::iterator end = argsList.end();
  for (ValueList::iterator i = argsList.begin(); i != end; ++i)
    argsVector.push_back(static_cast<jvalue>(**i));

  return argsVector;
}
Esempio n. 3
0
/**
 * Gets the method id matching the given arguments.
 */
jmethodID JConstructor::getMethodID(const JClass& jClass, const JArguments& arguments)
{
  // We cache the jmethodID locally, so if we've already found it,
  // we don't need to go looking for it again.
  if (mMethodID)
    return mMethodID;

  // If we don't already have the jmethodID, we need to determine
  // the signature of this method.

  // We construct this signature with a void return type,
  // because the return type for constructors is void.
  JSignature signature(JVoid::staticGetJavaJniClass());
  typedef list<const JValue*> ValueList;
  ValueList args = arguments.asList();

  ValueList::iterator i = args.begin();
  ValueList::iterator end = args.end();

  for (; i != end; ++i)
	{
    const JValue* value = *i;
    signature << value->getJavaJniClass();
  }

  string methodSignature = signature.toString();

  // Now that we have the signature for the method, we could look
  // in a global cache for the jmethodID corresponding to this method,
  // but for now, we'll always find it.
  JNIEnv* env = attach();

  mMethodID = env->GetMethodID(jClass.getClass(), "<init>", methodSignature.c_str());

  if (mMethodID == 0)
	{
		string msg = string("JConstructor::getMethodID(): ") +
                 "Unable to find constructor for " + jClass.getInternalName() + 
				 " with signature " + methodSignature;
		try
		{
			catchAndThrow();
		}
		catch (std::exception& e)
		{
			msg.append("\ncaused by:\n");
			msg.append(e.what());
		}
    throw JNIException(msg);
  }

  return mMethodID;
}