Commit 048da9da authored by Ryan Berkheimer's avatar Ryan Berkheimer

completed factoring of protocolrecord methods into standalone class

parent 81422908
......@@ -19,10 +19,10 @@ MessageApiEndpoint::MessageApiEndpoint(JNIEnv *env, jobject jendpoint, jobject j
this->typeUtils = new TypeUtils(this->jvm);
this->listUtils = new ListUtils(this->jvm, typeUtils);
this->endpointUtils = new EndpointUtils(this->jvm, this->endpoint, this->listUtils);
this->endpointUtils = new EndpointUtils(this->jvm, this->endpoint, this->typeUtils, this->listUtils);
this->protocolRecordUtils = new ProtocolRecordUtils(this->jvm, this->protocolRecord, this->typeUtils, this->listUtils);
this->packetUtils = new PacketUtils(this->jvm, this->listUtils);
this->loadProtocolRecordMethodIds();
this->loadRecordMethodIds();
this->loadRejectionMethodIds();
this->loadFieldMethodIds();
......@@ -34,6 +34,7 @@ MessageApiEndpoint::~MessageApiEndpoint()
try
{
delete this->endpointUtils;
delete this->protocolRecordUtils;
delete this->packetUtils;
delete this->listUtils;
delete this->typeUtils;
......@@ -51,6 +52,11 @@ EndpointUtils *MessageApiEndpoint::getEndpointUtils()
return this->endpointUtils;
}
ProtocolRecordUtils *MessageApiEndpoint::getProtocolRecordUtils()
{
return this->protocolRecordUtils;
}
PacketUtils *MessageApiEndpoint::getPacketUtils()
{
return this->packetUtils;
......@@ -67,17 +73,6 @@ TypeUtils *MessageApiEndpoint::getTypeUtils()
}
void MessageApiEndpoint::loadProtocolRecordMethodIds()
{
jclass protocolRecordClass = JniUtils::getObjectClass(this->jvm, this->protocolRecord);
this->getRecordsMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecords", this->getProtocolRecordMethodSignature("getRecords"), false);
this->getRecordsByCollectionMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByCollection", this->getProtocolRecordMethodSignature("getRecordsByCollection"), false);
this->getRecordsByUUIDMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByUUID", this->getProtocolRecordMethodSignature("getRecordsByUUID"), false);
this->getRecordsByTransformationMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByTransformation", this->getProtocolRecordMethodSignature("getRecordsByTransformation"), false);
this->getRecordsByClassifierMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByClassifier", this->getProtocolRecordMethodSignature("getRecordsByClassifier"), false);
this->jvm->DeleteLocalRef(protocolRecordClass);
}
void MessageApiEndpoint::loadRecordMethodIds()
{
......@@ -132,31 +127,6 @@ void MessageApiEndpoint::loadConditionMethodIds()
}
const char *MessageApiEndpoint::getProtocolRecordMethodSignature(const char* methodName)
{
if (strcmp(methodName, "getRecords") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByCollection") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByUUID") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByTransformation") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByClassifier") == 0)
{
return "(Ljava/lang/String;Ljava/lang/Object;)Ljava/util/List;";
}
return NULL;
}
const char *MessageApiEndpoint::getRecordMethodSignature(const char *methodName)
{
if (strcmp(methodName, "isValid") == 0)
......@@ -279,77 +249,6 @@ const char * MessageApiEndpoint::getConditionMethodSignature(const char *methodN
return NULL;
}
/**
* Factored method that handles all wrapped record retrieval methods including getRecords, getRecordsByCollection, getRecordsByTransformation,
* getRecordsByClassifier, and getRecordsbyUUID.
* This method takes a protocol reference which refers to the instance of the ProtocolRecord container as a java object,
* a methodId as a java method id that refers to the particular method instance, a method name as a string (const char pointer), and additional
* paramters of key and value as const char strings. The key and value arguments may or may not be used depending on the particular method called
* (referred to by the methodId). This method returns a protocolRecords java object that represents the return from the associated java object.
* To be used in a native context, this return object must be unpacked.
*/
jobject MessageApiEndpoint::getProtocolRecords(const char* method, const char* key, const char* val)
{
if (strcmp(method, "getRecords") == 0)
{
return this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsMethodId);
}
else if (strcmp(method, "getRecordsByCollection") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByCollectionMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByTransformation") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByTransformationMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByUUID") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByUUIDMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByClassifier") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jstring javaVal = this->typeUtils->toJavaString(val);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByClassifierMethodId, javaKey, javaVal);
this->jvm->DeleteLocalRef(javaKey);
this->jvm->DeleteLocalRef(javaVal);
return protocolRecords;
}
else
{
return NULL;
}
}
struct record_list * MessageApiEndpoint::getRecords(const char *recordMethod, const char *key, const char *val)
{
jobject jprotocolRecords = this->getProtocolRecords(recordMethod, key, val);
int recordCount = this->listUtils->getListLength(jprotocolRecords);
struct record_list *record_list = (struct record_list *) malloc(sizeof(struct record_list));
record_list->count = recordCount;
record_list->jrecords = jprotocolRecords;
return record_list;
}
struct record *MessageApiEndpoint::getRecord(struct record_list *record_list, int index)
{
jobject jrecord = this->jvm->CallObjectMethod(record_list->jrecords, this->listUtils->getListItemMethod(), index);
struct record *record = (struct record *) malloc(sizeof(struct record) + sizeof(jrecord));
record->jrecord = jrecord;
return record;
}
bool MessageApiEndpoint::getRecordIsValid(struct record *record)
{
return (bool)this->jvm->CallBooleanMethod(record->jrecord, this->getRecordIsValidMethodId);
......
......@@ -12,8 +12,9 @@
#include "JniUtils.h"
#include "ListUtils.h"
#include "PacketUtils.h"
#include "EndpointUtils.h"
#include "ProtocolRecordUtils.h"
#include "PacketUtils.h"
/**
* This is the header for the MessageApiEndpoint class - this class is the native side facility
......@@ -35,14 +36,11 @@ public:
/*Utils Accessors*/
EndpointUtils *getEndpointUtils();
ProtocolRecordUtils *getProtocolRecordUtils();
PacketUtils *getPacketUtils();
ListUtils *getListUtils();
TypeUtils *getTypeUtils();
/*Protocol Record Methods*/
jobject getProtocolRecords(const char *method, const char *key, const char *val);
struct record_list *getRecords(const char *method, const char *key = NULL, const char *val = NULL);
struct record *getRecord(struct record_list *record_list, int index);
/*Record Methods*/
struct record_list *createRecordList();
......@@ -127,17 +125,11 @@ private :
jobject endpoint;
jobject protocolRecord;
EndpointUtils *endpointUtils;
ProtocolRecordUtils *protocolRecordUtils;
PacketUtils *packetUtils;
TypeUtils *typeUtils;
ListUtils *listUtils;
PacketUtils *packetUtils;
EndpointUtils *endpointUtils;
/*Protocol Record Methods*/
jmethodID getRecordsMethodId;
jmethodID getRecordsByCollectionMethodId;
jmethodID getRecordsByUUIDMethodId;
jmethodID getRecordsByTransformationMethodId;
jmethodID getRecordsByClassifierMethodId;
/*Record Methods*/
jmethodID getRecordIsValidMethodId;
......@@ -174,14 +166,12 @@ private :
/*Load method IDS for reuse. MethodIDS do not count against the jref count and do need to be released.*/
void loadProtocolRecordMethodIds();
void loadRecordMethodIds();
void loadRejectionMethodIds();
void loadFieldMethodIds();
void loadConditionMethodIds();
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getProtocolRecordMethodSignature(const char *protocolRecordMethodName);
const char *getRecordMethodSignature(const char *recordMethodName);
const char *getRejectionMethodSignature(const char *rejectionMethodName);
const char *getFieldMethodSignature(const char *fieldMethodName);
......
......@@ -6,9 +6,9 @@
/**
Constructor for a ProtocolRecordUtils object.
*/
ProtocolRecordUtils::ProtocolRecordUtils(JNIEnv *jvm, ListUtils *listUtils)
ProtocolRecordUtils::ProtocolRecordUtils(JNIEnv *jvm, jobject protocolRecord, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->loadGlobalRefs(jvm, listUtils);
this->loadGlobalRefs(jvm, protocolRecord, typeUtils, listUtils);
this->loadMethodIds();
}
......@@ -22,12 +22,116 @@ ProtocolRecordUtils::~ProtocolRecordUtils()
}
}
void ProtocolRecordUtils::loadGlobalRefs(JNIEnv *jvm, ListUtils *listUtils)
/**
* Factored method that handles all wrapped record retrieval methods including getRecords, getRecordsByCollection, getRecordsByTransformation,
* getRecordsByClassifier, and getRecordsbyUUID.
* This method takes a protocol reference which refers to the instance of the ProtocolRecord container as a java object,
* a methodId as a java method id that refers to the particular method instance, a method name as a string (const char pointer), and additional
* paramters of key and value as const char strings. The key and value arguments may or may not be used depending on the particular method called
* (referred to by the methodId). This method returns a protocolRecords java object that represents the return from the associated java object.
* To be used in a native context, this return object must be unpacked.
*/
jobject ProtocolRecordUtils::getProtocolRecords(const char *method, const char *key, const char *val)
{
if (strcmp(method, "getRecords") == 0)
{
return this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsMethodId);
}
else if (strcmp(method, "getRecordsByCollection") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByCollectionMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByTransformation") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByTransformationMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByUUID") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByUUIDMethodId, javaKey);
this->jvm->DeleteLocalRef(javaKey);
return protocolRecords;
}
else if (strcmp(method, "getRecordsByClassifier") == 0)
{
jstring javaKey = this->typeUtils->toJavaString(key);
jstring javaVal = this->typeUtils->toJavaString(val);
jobject protocolRecords = this->jvm->CallObjectMethod(this->protocolRecord, this->getRecordsByClassifierMethodId, javaKey, javaVal);
this->jvm->DeleteLocalRef(javaKey);
this->jvm->DeleteLocalRef(javaVal);
return protocolRecords;
}
else
{
return NULL;
}
}
struct record_list *ProtocolRecordUtils::getRecords(const char *recordMethod, const char *key, const char *val)
{
jobject jprotocolRecords = this->getProtocolRecords(recordMethod, key, val);
int recordCount = this->listUtils->getListLength(jprotocolRecords);
struct record_list *record_list = (struct record_list *)malloc(sizeof(struct record_list));
record_list->count = recordCount;
record_list->jrecords = jprotocolRecords;
return record_list;
}
struct record *ProtocolRecordUtils::getRecord(struct record_list *record_list, int index)
{
jobject jrecord = this->jvm->CallObjectMethod(record_list->jrecords, this->listUtils->getListItemMethod(), index);
struct record *record = (struct record *)malloc(sizeof(struct record) + sizeof(jrecord));
record->jrecord = jrecord;
return record;
}
void ProtocolRecordUtils::loadGlobalRefs(JNIEnv *jvm, jobject protocolRecord, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->jvm = jvm;
this->protocolRecord = protocolRecord;
this->typeUtils = typeUtils;
this->listUtils = listUtils;
}
void ProtocolRecordUtils::loadMethodIds()
{
}
\ No newline at end of file
jclass protocolRecordClass = JniUtils::getObjectClass(this->jvm, this->protocolRecord);
this->getRecordsMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecords", this->getMethodSignature("getRecords"), false);
this->getRecordsByCollectionMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByCollection", this->getMethodSignature("getRecordsByCollection"), false);
this->getRecordsByUUIDMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByUUID", this->getMethodSignature("getRecordsByUUID"), false);
this->getRecordsByTransformationMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByTransformation", this->getMethodSignature("getRecordsByTransformation"), false);
this->getRecordsByClassifierMethodId = JniUtils::getMethod(this->jvm, protocolRecordClass, "getRecordsByClassifier", this->getMethodSignature("getRecordsByClassifier"), false);
this->jvm->DeleteLocalRef(protocolRecordClass);
}
const char *ProtocolRecordUtils::getMethodSignature(const char *methodName)
{
if (strcmp(methodName, "getRecords") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByCollection") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByUUID") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByTransformation") == 0)
{
return "(Ljava/lang/String;)Ljava/util/List;";
}
else if (strcmp(methodName, "getRecordsByClassifier") == 0)
{
return "(Ljava/lang/String;Ljava/lang/Object;)Ljava/util/List;";
}
return NULL;
}
......@@ -12,6 +12,7 @@
#include "JniUtils.h"
#include "ListUtils.h"
#include "TypeUtils.h"
/**
* This is the header for the ProtoclRecordUtils class.
......@@ -25,17 +26,31 @@ class ProtocolRecordUtils
public:
/*Default constructor/destructors*/
ProtocolRecordUtils(JNIEnv *javaEnv, ListUtils *listUtils);
ProtocolRecordUtils(JNIEnv *javaEnv, jobject protocolRecord, TypeUtils *typeUtils, ListUtils *listUtils);
~ProtocolRecordUtils();
/*Protocol Record Methods*/
jobject getProtocolRecords(const char *method, const char *key, const char *val);
struct record_list *getRecords(const char *method, const char *key = NULL, const char *val = NULL);
struct record *getRecord(struct record_list *record_list, int index);
private:
/*Vars*/
JNIEnv *jvm;
jobject protocolRecord;
TypeUtils *typeUtils;
ListUtils *listUtils;
/*Protocol Record Methods*/
jmethodID getRecordsMethodId;
jmethodID getRecordsByCollectionMethodId;
jmethodID getRecordsByUUIDMethodId;
jmethodID getRecordsByTransformationMethodId;
jmethodID getRecordsByClassifierMethodId;
/*Load method IDS for reuse. MethodIDS do not count against the jref count and do need to be released.*/
void loadMethodIds();
void loadGlobalRefs(JNIEnv *env, ListUtils *listUtils);
void loadGlobalRefs(JNIEnv *env, jobject protocolRecord, TypeUtils *typeUtils, ListUtils *listUtils);
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getMethodSignature(const char *methodName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment