Commit 116634de authored by Ryan Berkheimer's avatar Ryan Berkheimer

completed factoring of record methods into record utils

parent 048da9da
This diff is collapsed.
......@@ -14,6 +14,7 @@
#include "ListUtils.h"
#include "EndpointUtils.h"
#include "ProtocolRecordUtils.h"
#include "RecordUtils.h"
#include "PacketUtils.h"
/**
......@@ -37,27 +38,11 @@ public:
/*Utils Accessors*/
EndpointUtils *getEndpointUtils();
ProtocolRecordUtils *getProtocolRecordUtils();
RecordUtils *getRecordUtils();
PacketUtils *getPacketUtils();
ListUtils *getListUtils();
TypeUtils *getTypeUtils();
/*Record Methods*/
struct record_list *createRecordList();
void addRecord(struct record_list *record_list, struct record *record);
struct record *getRecordCopy(struct record *record);
bool getRecordIsValid(struct record *record);
bool getRecordHasField(struct record *record, const char *fieldId);
struct string_list *getFieldIds(struct record *record);
struct field_list *getFields(struct record *record);
struct field *getField(struct record *record, const char* fieldId);
bool getRecordHasCondition(struct record *record, const char *conditionId);
struct string_list *getConditionIds(struct record *record);
struct condition_list *getConditions(struct record *record);
struct condition *getCondition(struct record *record, const char *conditionId);
/*Rejection Methods*/
struct rejection_list *createRejectionList();
void addRejection(struct rejection_list *rejection_list, struct rejection *rejection);
......@@ -127,22 +112,11 @@ private :
EndpointUtils *endpointUtils;
ProtocolRecordUtils *protocolRecordUtils;
RecordUtils *recordUtils;
PacketUtils *packetUtils;
TypeUtils *typeUtils;
ListUtils *listUtils;
/*Record Methods*/
jmethodID getRecordIsValidMethodId;
jmethodID getRecordCopyMethodId;
jmethodID getRecordFieldIdsMethodId;
jmethodID getRecordFieldsMethodId;
jmethodID getRecordFieldMethodId;
jmethodID getRecordHasFieldMethodId;
jmethodID getRecordConditionIdsMethodId;
jmethodID getRecordConditionsMethodId;
jmethodID getRecordHasConditionMethodId;
jmethodID getRecordConditionMethodId;
/*Rejection Methods*/
jmethodID getRejectionCopyMethodId;
jmethodID getRejectionReasonsMethodId;
......@@ -166,13 +140,11 @@ private :
/*Load method IDS for reuse. MethodIDS do not count against the jref count and do need to be released.*/
void loadRecordMethodIds();
void loadRejectionMethodIds();
void loadFieldMethodIds();
void loadConditionMethodIds();
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getRecordMethodSignature(const char *recordMethodName);
const char *getRejectionMethodSignature(const char *rejectionMethodName);
const char *getFieldMethodSignature(const char *fieldMethodName);
const char *getConditionMethodSignature(const char *conditionMethodName);
......
......@@ -6,9 +6,9 @@
/**
Constructor for the RecordUtils object.
*/
RecordUtils::RecordUtils(JNIEnv *jvm, ListUtils *listUtils)
RecordUtils::RecordUtils(JNIEnv *jvm, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->loadGlobalRefs(jvm, listUtils);
this->loadGlobalRefs(jvm, typeUtils, listUtils);
this->loadMethodIds();
}
......@@ -22,12 +22,198 @@ RecordUtils::~RecordUtils()
}
}
void RecordUtils::loadGlobalRefs(JNIEnv *jvm, ListUtils *listUtils)
/*Public API*/
bool RecordUtils::isValid(struct record *record)
{
return (bool)this->jvm->CallBooleanMethod(record->jrecord, this->isValidMethodId);
}
struct record *RecordUtils::getCopy(struct record *record)
{
jobject jRecordCopy = this->jvm->CallObjectMethod(record->jrecord, this->getCopyMethodId);
struct record *recordCopy = (struct record *)malloc(sizeof(struct record) + sizeof(jRecordCopy));
recordCopy->jrecord = jRecordCopy;
return recordCopy;
}
bool RecordUtils::hasField(struct record *record, const char *fieldId)
{
jstring jFieldId = this->typeUtils->toJavaString(fieldId);
bool hasJField = (bool)this->jvm->CallBooleanMethod(record->jrecord, this->hasFieldMethodId, jFieldId);
this->jvm->DeleteLocalRef(jFieldId);
return hasJField;
}
struct string_list *RecordUtils::getFieldIds(struct record *record)
{
jobject jFieldIdList = this->jvm->CallObjectMethod(record->jrecord, this->getFieldIdsMethodId);
struct string_list *field_ids = this->listUtils->translateStringList(jFieldIdList);
this->jvm->DeleteLocalRef(jFieldIdList);
return field_ids;
}
struct field_list *RecordUtils::getFields(struct record *record)
{
jobject jFieldList = this->jvm->CallObjectMethod(record->jrecord, this->getFieldsMethodId);
int fieldCount = this->listUtils->getListLength(jFieldList);
struct field **fields = (struct field **)malloc(sizeof(struct field *) * fieldCount);
for (int i = 0; i < fieldCount; i++)
{
jobject jfield = static_cast<jobject>(this->jvm->CallObjectMethod(jFieldList, this->listUtils->getListItemMethod(), i));
struct field *field = (struct field *)malloc(sizeof(field) + sizeof(jfield));
field->jfield = (jobject)jfield;
fields[i] = field;
}
struct field_list *field_list = (struct field_list *)malloc(sizeof(struct field_list) + sizeof(fields));
field_list->count = fieldCount;
field_list->fields = fields;
return field_list;
}
struct field *RecordUtils::getField(struct record *record, const char *fieldId)
{
jstring jFieldId = this->typeUtils->toJavaString(fieldId);
jobject jField = this->jvm->CallObjectMethod(record->jrecord, this->getFieldMethodId, jFieldId);
struct field *field = (struct field *)malloc(sizeof(struct field) + sizeof(jField));
field->jfield = jField;
this->jvm->DeleteLocalRef(jFieldId);
return field;
}
bool RecordUtils::hasCondition(struct record *record, const char *conditionId)
{
jstring jConditionId = this->typeUtils->toJavaString(conditionId);
bool hasJCondition = (bool)this->jvm->CallBooleanMethod(record->jrecord, this->hasConditionMethodId, jConditionId);
this->jvm->DeleteLocalRef(jConditionId);
return hasJCondition;
}
struct string_list *RecordUtils::getConditionIds(struct record *record)
{
jobject jConditionIdList = this->jvm->CallObjectMethod(record->jrecord, this->getConditionIdsMethodId);
struct string_list *condition_ids = this->listUtils->translateStringList(jConditionIdList);
this->jvm->DeleteLocalRef(jConditionIdList);
return condition_ids;
}
struct condition_list *RecordUtils::getConditions(struct record *record)
{
jobject jConditionList = this->jvm->CallObjectMethod(record->jrecord, this->getConditionsMethodId);
int conditionCount = this->listUtils->getListLength(jConditionList);
struct condition **conditions = (struct condition **)malloc(sizeof(struct condition *) * conditionCount);
for (int i = 0; i < conditionCount; i++)
{
jobject jcondition = static_cast<jobject>(this->jvm->CallObjectMethod(jConditionList, this->listUtils->getListItemMethod(), i));
struct condition *condition = (struct condition *)malloc(sizeof(condition) + sizeof(jcondition));
condition->jcondition = (jobject)jcondition;
conditions[i] = condition;
}
struct condition_list *condition_list = (struct condition_list *)malloc(sizeof(struct condition_list) + sizeof(conditions));
condition_list->count = conditionCount;
condition_list->conditions = conditions;
return condition_list;
}
struct condition *RecordUtils::getCondition(struct record *record, const char *conditionId)
{
jstring jConditionId = this->typeUtils->toJavaString(conditionId);
jobject jCondition = this->jvm->CallObjectMethod(record->jrecord, this->getConditionMethodId, jConditionId);
struct condition *condition = (struct condition *)malloc(sizeof(struct condition) + sizeof(jCondition));
condition->jcondition = jCondition;
this->jvm->DeleteLocalRef(jConditionId);
return condition;
}
struct record_list *RecordUtils::createRecordList()
{
jobject jList = this->jvm->NewObject(this->typeUtils->getListClass(), this->listUtils->createListMethod());
struct record_list *record_list = (struct record_list *)malloc(sizeof(struct record_list));
record_list->count = 0;
record_list->jrecords = jList;
return record_list;
}
void RecordUtils::addRecord(struct record_list *record_list, struct record *record)
{
this->jvm->CallVoidMethod(record_list->jrecords, this->listUtils->addListItemMethod(), record->jrecord);
record_list->count += 1;
}
/*Private methods*/
void RecordUtils::loadGlobalRefs(JNIEnv *jvm, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->jvm = jvm;
this->typeUtils = typeUtils;
this->listUtils = listUtils;
}
void RecordUtils::loadMethodIds()
{
}
\ No newline at end of file
jclass recordClass = JniUtils::getNamedClass(this->jvm, "gov/noaa/messageapi/interfaces/IRecord");
/*Intrinsic Methods*/
this->isValidMethodId = JniUtils::getMethod(this->jvm, recordClass, "isValid", this->getMethodSignature("isValid"), false);
this->getCopyMethodId = JniUtils::getMethod(this->jvm, recordClass, "getCopy", this->getMethodSignature("getCopy"), false);
/*Field Related Methods*/
this->getFieldIdsMethodId = JniUtils::getMethod(this->jvm, recordClass, "getFieldIds", this->getMethodSignature("getFieldIds"), false);
this->getFieldsMethodId = JniUtils::getMethod(this->jvm, recordClass, "getFields", this->getMethodSignature("getFields"), false);
this->hasFieldMethodId = JniUtils::getMethod(this->jvm, recordClass, "hasField", this->getMethodSignature("hasField"), false);
this->getFieldMethodId = JniUtils::getMethod(this->jvm, recordClass, "getField", this->getMethodSignature("getField"), false);
/*Condition Related Methods*/
this->getConditionIdsMethodId = JniUtils::getMethod(this->jvm, recordClass, "getConditionIds", this->getMethodSignature("getConditionIds"), false);
this->getConditionsMethodId = JniUtils::getMethod(this->jvm, recordClass, "getConditions", this->getMethodSignature("getConditions"), false);
this->hasConditionMethodId = JniUtils::getMethod(this->jvm, recordClass, "hasCondition", this->getMethodSignature("hasCondition"), false);
this->getConditionMethodId = JniUtils::getMethod(this->jvm, recordClass, "getCondition", this->getMethodSignature("getCondition"), false);
this->jvm->DeleteLocalRef(recordClass);
}
const char *RecordUtils::getMethodSignature(const char *methodName)
{
if (strcmp(methodName, "isValid") == 0)
{
return "()Ljava/lang/Boolean;";
}
else if (strcmp(methodName, "getCopy") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRecord;";
}
else if (strcmp(methodName, "getFieldIds") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "hasField") == 0)
{
return "(Ljava/lang/String;)Ljava/lang/Boolean;";
}
else if (strcmp(methodName, "getFields") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getField") == 0)
{
return "(Ljava/lang/String;)Lgov/noaa/messageapi/interfaces/IField;";
}
else if (strcmp(methodName, "getConditionIds") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "hasCondition") == 0)
{
return "(Ljava/lang/String;)Ljava/lang/Boolean;";
}
else if (strcmp(methodName, "getConditions") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getCondition") == 0)
{
return "(Ljava/lang/String;)Lgov/noaa/messageapi/interfaces/ICondition;";
}
return NULL;
}
......@@ -12,6 +12,7 @@
#include "JniUtils.h"
#include "ListUtils.h"
#include "TypeUtils.h"
/**
* This is the header for the RecordUtils class.
......@@ -22,17 +23,46 @@ class RecordUtils
public:
/*Default constructor/destructors*/
RecordUtils(JNIEnv *javaEnv, ListUtils *listUtils);
RecordUtils(JNIEnv *javaEnv, TypeUtils *typeUtils, ListUtils *listUtils);
~RecordUtils();
/*Record Methods*/
struct record_list *createRecordList();
void addRecord(struct record_list *record_list, struct record *record);
struct record *getCopy(struct record *record);
bool isValid(struct record *record);
bool hasField(struct record *record, const char *fieldId);
struct string_list *getFieldIds(struct record *record);
struct field_list *getFields(struct record *record);
struct field *getField(struct record *record, const char *fieldId);
bool hasCondition(struct record *record, const char *conditionId);
struct string_list *getConditionIds(struct record *record);
struct condition_list *getConditions(struct record *record);
struct condition *getCondition(struct record *record, const char *conditionId);
private:
/*Vars*/
JNIEnv *jvm;
ListUtils *listUtils;
TypeUtils *typeUtils;
/*Record Methods*/
jmethodID isValidMethodId;
jmethodID getCopyMethodId;
jmethodID getFieldIdsMethodId;
jmethodID getFieldsMethodId;
jmethodID getFieldMethodId;
jmethodID hasFieldMethodId;
jmethodID getConditionIdsMethodId;
jmethodID getConditionsMethodId;
jmethodID hasConditionMethodId;
jmethodID getConditionMethodId;
/*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, 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