192 lines
7.7 KiB
OpenEdge ABL
192 lines
7.7 KiB
OpenEdge ABL
/* Copyright (c) 2015,2016 Sequence Logic Inc. All rights reserved
|
|
*
|
|
* SWIG interface for converting between sequencelogic::JSONObject and org.json.JSONObject
|
|
*
|
|
*/
|
|
|
|
%typemap(jni) sequencelogic::JSONObject, const sequencelogic::JSONObject & "jobject"
|
|
%typemap(jtype) sequencelogic::JSONObject, const sequencelogic::JSONObject & "org.json.JSONObject"
|
|
%typemap(jstype) sequencelogic::JSONObject, const sequencelogic::JSONObject & "org.json.JSONObject"
|
|
%typemap(javain) sequencelogic::JSONObject, const sequencelogic::JSONObject & "$javainput"
|
|
|
|
/* Convert from org.json.JSONObject to sequencelogic::JSONObject */
|
|
%typemap(in) const sequencelogic::JSONObject &, sequencelogic::JSONObject
|
|
{
|
|
if ($input != NULL)
|
|
{
|
|
// Convert $input (a org.json.JSONObject) to $1 (a sequencelogic::JSONObject)
|
|
jclass jObjClazz = jenv->GetObjectClass($input);
|
|
jmethodID toStringID = jenv->GetMethodID(jObjClazz, "toString", "()Ljava/lang/String;");
|
|
jstring jsonObjStr = static_cast<jstring>(jenv->CallObjectMethod($input, toStringID));
|
|
|
|
const char *pCJsonStr = jenv->GetStringUTFChars(jsonObjStr, 0);
|
|
if ((pCJsonStr != NULL) && (pCJsonStr[0] != '\0'))
|
|
$1 = new sequencelogic::JSONObject(pCJsonStr);
|
|
else
|
|
$1 = new sequencelogic::JSONObject();
|
|
|
|
jenv->ReleaseStringUTFChars(jsonObjStr, pCJsonStr);
|
|
}
|
|
}
|
|
%typemap(freearg) const sequencelogic::JSONObject &, sequencelogic::JSONObject
|
|
{
|
|
delete $1;
|
|
}
|
|
%typemap(argout) const sequencelogic::JSONObject &, sequencelogic::JSONObject { }
|
|
|
|
%typemap(jni) sequencelogic::JSONObjectPtr, JSONObjectPtr "jobject"
|
|
%typemap(jtype) sequencelogic::JSONObjectPtr, JSONObjectPtr "org.json.JSONObject"
|
|
%typemap(jstype) sequencelogic::JSONObjectPtr, JSONObjectPtr "org.json.JSONObject"
|
|
|
|
%typemap(javaout) sequencelogic::JSONObjectPtr, JSONObjectPtr
|
|
{
|
|
return $jnicall;
|
|
}
|
|
|
|
/* Convert from sequencelogic::JSONObjectPtr to org.json.JSONObject */
|
|
%typemap(out) sequencelogic::JSONObjectPtr, JSONObjectPtr
|
|
{
|
|
if ($1 != NULL)
|
|
{
|
|
// Convert from $1 to $result
|
|
jclass jJSONObjClazz = jenv->FindClass("org/json/JSONObject");
|
|
if (jJSONObjClazz == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find class 'org/json/JSONObject'");
|
|
return $null;
|
|
}
|
|
|
|
jmethodID jJSONCtor = jenv->GetMethodID(jJSONObjClazz, "<init>", "(Ljava/lang/String;)V");
|
|
if (jJSONCtor == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find constructor taking a string in 'org/json/JSONObject'");
|
|
return $null;
|
|
}
|
|
|
|
jstring jsonAsString = jenv->NewStringUTF($1->toString().c_str());
|
|
|
|
$result = jenv->NewObject(jJSONObjClazz, jJSONCtor, jsonAsString);
|
|
}
|
|
}
|
|
|
|
%typemap(jni) std::shared_ptr<sequencelogic::JSONArray>, std::shared_ptr<JSONArray> "jobject"
|
|
%typemap(jtype) std::shared_ptr<sequencelogic::JSONArray>, std::shared_ptr<JSONArray> "org.json.JSONArray"
|
|
%typemap(jstype) std::shared_ptr<sequencelogic::JSONArray>, std::shared_ptr<JSONArray> "org.json.JSONArray"
|
|
|
|
%typemap(javaout) std::shared_ptr<sequencelogic::JSONArray>, std::shared_ptr<JSONArray>
|
|
{
|
|
return $jnicall;
|
|
}
|
|
|
|
/* Convert from std::shared_ptr<sequencelogic::JSONArray> to org.json.JSONArray */
|
|
%typemap(out) std::shared_ptr<sequencelogic::JSONArray>, std::shared_ptr<JSONArray>
|
|
{
|
|
if ($1 != NULL)
|
|
{
|
|
// Convert from $1 to $result
|
|
jclass jJSONObjClazz = jenv->FindClass("org/json/JSONArray");
|
|
if (jJSONObjClazz == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find class 'org.json.JSONArray'");
|
|
return $null;
|
|
}
|
|
|
|
jmethodID jJSONCtor = jenv->GetMethodID(jJSONObjClazz, "<init>", "(Ljava/lang/String;)V");
|
|
if (jJSONCtor == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find constructor taking a string in 'org.json.JSONArray'");
|
|
return $null;
|
|
}
|
|
|
|
jstring jsonAsString = jenv->NewStringUTF($1->toString().c_str());
|
|
|
|
$result = jenv->NewObject(jJSONObjClazz, jJSONCtor, jsonAsString);
|
|
}
|
|
}
|
|
|
|
%typemap(jni) sequencelogic::JSONArray, JSONArray, const sequencelogic::JSONArray &, const JSONArray & "jobject"
|
|
%typemap(jtype) sequencelogic::JSONArray, JSONArray, const sequencelogic::JSONArray &, const JSONArray & "org.json.JSONArray"
|
|
%typemap(jstype) sequencelogic::JSONArray, JSONArray, const sequencelogic::JSONArray &, const JSONArray & "org.json.JSONArray"
|
|
%typemap(javain) sequencelogic::JSONArray, JSONArray, const sequencelogic::JSONArray &, const JSONArray & "$javainput"
|
|
|
|
%typemap(in) sequencelogic::JSONArray, JSONArray, const sequencelogic::JSONArray &, const JSONArray &
|
|
{
|
|
if ($input != NULL)
|
|
{
|
|
// Convert $input (a org.json.JSONArray) to $1 (a sequencelogic::JSONArray)
|
|
jclass jObjClazz = jenv->GetObjectClass($input);
|
|
jmethodID toStringID = jenv->GetMethodID(jObjClazz, "toString", "()Ljava/lang/String;");
|
|
jstring jsonObjStr = static_cast<jstring>(jenv->CallObjectMethod($input, toStringID));
|
|
|
|
const char *pCJsonStr = jenv->GetStringUTFChars(jsonObjStr, 0);
|
|
$1 = new sequencelogic::JSONArray(pCJsonStr);
|
|
|
|
jenv->ReleaseStringUTFChars(jsonObjStr, pCJsonStr);
|
|
|
|
}
|
|
}
|
|
%typemap(freearg) const sequencelogic::JSONObject &, sequencelogic::JSONObject
|
|
{
|
|
delete $1;
|
|
}
|
|
|
|
%typemap(jni) sequencelogic::JSONObject & "jobjectArray"
|
|
%typemap(jtype) sequencelogic::JSONObject & "org.json.JSONObject []"
|
|
%typemap(jstype) sequencelogic::JSONObject & "org.json.JSONObject []"
|
|
%typemap(javain) sequencelogic::JSONObject & "$javainput"
|
|
|
|
%typemap(in) sequencelogic::JSONObject &
|
|
{
|
|
if (!$input)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In ionu-json.i: NULL sequencelogic::JSONObject");
|
|
return $null;
|
|
}
|
|
if (jenv->GetArrayLength($input) == 0)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "In ionu-json.i: Array must contain at least 1 element");
|
|
return $null;
|
|
}
|
|
|
|
jobject tmpJObject = static_cast<jobject>(jenv->GetObjectArrayElement($input, 0));
|
|
jclass jObjClazz = jenv->GetObjectClass(tmpJObject);
|
|
jmethodID toStringID = jenv->GetMethodID(jObjClazz, "toString", "()Ljava/lang/String;");
|
|
jstring jsonObjStr = static_cast<jstring>(jenv->CallObjectMethod(tmpJObject, toStringID));
|
|
|
|
const char *pCJsonStr = jenv->GetStringUTFChars(jsonObjStr, 0);
|
|
if ((pCJsonStr != NULL) && (pCJsonStr[0] != '\0'))
|
|
$1 = new sequencelogic::JSONObject(pCJsonStr);
|
|
else
|
|
$1 = new sequencelogic::JSONObject();
|
|
|
|
jenv->ReleaseStringUTFChars(jsonObjStr, pCJsonStr);
|
|
}
|
|
|
|
%typemap(freearg) sequencelogic::JSONObject &
|
|
{
|
|
delete $1;
|
|
}
|
|
|
|
%typemap(argout) sequencelogic::JSONObject &
|
|
{
|
|
jclass jJSONObjClazz = jenv->FindClass("org/json/JSONObject");
|
|
if (jJSONObjClazz == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find class 'org/json/JSONObject'");
|
|
return $null;
|
|
}
|
|
|
|
jmethodID jJSONCtor = jenv->GetMethodID(jJSONObjClazz, "<init>", "(Ljava/lang/String;)V");
|
|
if (jJSONCtor == NULL)
|
|
{
|
|
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "In sequencelogic-json.i: Cannot find constructor taking a string in 'org/json/JSONObject'");
|
|
return $null;
|
|
}
|
|
|
|
jstring jsonAsString = jenv->NewStringUTF($1->toString().c_str());
|
|
|
|
jobject newJSONObj = jenv->NewObject(jJSONObjClazz, jJSONCtor, jsonAsString);
|
|
|
|
jenv->SetObjectArrayElement($input, 0, newJSONObj);
|
|
}
|