void JavaSession::GetUserClassInfo()

in language-extensions/java/src/JavaSession.cpp [420:503]


void JavaSession::GetUserClassInfo()
{
	AutoJniLocalFrame jFrame(m_env, 4);

	jfieldID versionId =
		m_env->GetFieldID(m_userClass, x_javaExtensionVersionMemberName.c_str(), "I");
	jfieldID inputDatasetClassId = m_env->GetFieldID(m_userClass,
													 x_inputDatasetMemberName.c_str(),
													 "Ljava/lang/String;");
	jfieldID outputDatasetClassId = m_env->GetFieldID(m_userClass,
													  x_outputDatasetMemberName.c_str(),
													  "Ljava/lang/String;");

	if (versionId == nullptr || inputDatasetClassId == nullptr || outputDatasetClassId == nullptr)
	{
		// Since these are members of the abstract executor class, and we verified the user class
		// derives the base class this is unlikely to happen.
		//
		JniHelper::ThrowOnJavaException(
			m_env,
			"Failed to find class members " + x_javaExtensionVersionMemberName + "," + x_inputDatasetMemberName + "," +
			x_outputDatasetMemberName);

		throw runtime_error(
			"Failed to find class members " + x_javaExtensionVersionMemberName + "," + x_inputDatasetMemberName + "," +
			x_outputDatasetMemberName);
	}

	jint version = m_env->GetIntField(m_userObject, versionId);

	// Check the version supplied is supported
	//
	if (version != x_javaExtensionVersion1)
	{
		throw runtime_error("Unsupported executor version encountered " + to_string(version));
	}

	// Get the class to use for input data set
	//
	jstring jInputDataClassStr =
		static_cast<jstring>(m_env->GetObjectField(m_userObject, inputDatasetClassId));

	if (jInputDataClassStr == nullptr)
	{
		throw runtime_error(
				  "Invalid value encountered for executorInputDatasetClassName in class " +
				  m_mainClassName);
	}

	jsize sizeInBytes = m_env->GetStringUTFLength(jInputDataClassStr);
	const char *value = m_env->GetStringUTFChars(jInputDataClassStr, nullptr);
	JniHelper::ThrowOnJavaException(m_env);

	m_inputDatasetClassName = regex_replace(string(value, sizeInBytes), regex("\\."), "/");

	m_env->ReleaseStringUTFChars(jInputDataClassStr, value);

	// Get the class to use for output data set
	//
	// NOTE:
	// This class is only used for determining the function signature,
	// so null is acceptable. As the object is allocated and return to
	// the extension from execute()
	//
	jstring jOutputDataClassStr =
		static_cast<jstring>(m_env->GetObjectField(m_userObject, outputDatasetClassId));

	if (jOutputDataClassStr != nullptr)
	{
		sizeInBytes = m_env->GetStringUTFLength(jOutputDataClassStr);
		value = m_env->GetStringUTFChars(jOutputDataClassStr, nullptr);
		JniHelper::ThrowOnJavaException(m_env);

		m_outputDatasetClassName = regex_replace(string(value, sizeInBytes), regex("\\."), "/");

		m_env->ReleaseStringUTFChars(jOutputDataClassStr, value);
	}
	else
	{
		// Set to the default data set class
		//
		m_outputDatasetClassName = x_javaSdkBaseDatasetClass;
	}
}