in language-extensions/java/src/JavaDataset.cpp [319:388]
void JavaDataset::Init(JNIEnv *env, const string &className)
{
LOG("JavaDataset::Init");
if (env != nullptr)
{
m_env = env;
// Max number of local references for this function are 2:
// 1 for the dataset class
// 1 for the object created
//
AutoJniLocalFrame jFrame(m_env, 2);
jclass classLocalRef = m_env->FindClass(className.c_str());
if (classLocalRef != nullptr)
{
m_class = static_cast<jclass>(m_env->NewGlobalRef(classLocalRef));
if (m_class != nullptr)
{
jmethodID method = FindDatasetMethod("<init>", "()V");
if (method != nullptr)
{
// Create the Dataset object
//
jobject data = m_env->NewObject(m_class, method);
if (data != nullptr)
{
// Create a global reference on the new Dataset object
//
m_object = m_env->NewGlobalRef(data);
if (m_object == nullptr)
{
throw runtime_error(
"Could not create global reference for dataset object");
}
}
else
{
JniHelper::ThrowOnJavaException(m_env, "Could not create dataset object");
throw runtime_error("Could not create dataset object");
}
}
else
{
JniHelper::ThrowOnJavaException(m_env, "Could not find dataset constructor");
throw runtime_error("Could not find dataset constructor");
}
}
else
{
throw runtime_error("Could not create global reference for dataset class");
}
}
else
{
JniHelper::ThrowOnJavaException(m_env, "Could not find dataset class");
throw runtime_error("Could not find dataset class");
}
}
else
{
throw runtime_error("Invalid JNI enviroment");
}
}