Commit 94b35bfe authored by Ryan Berkheimer's avatar Ryan Berkheimer

finished factoring rejection utils into standalone class

parent 116634de
......@@ -22,9 +22,9 @@ MessageApiEndpoint::MessageApiEndpoint(JNIEnv *env, jobject jendpoint, jobject j
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->recordUtils = new RecordUtils(this->jvm, this->typeUtils, this->listUtils);
this->rejectionUtils = new RejectionUtils(this->jvm, this->typeUtils, this->listUtils);
this->packetUtils = new PacketUtils(this->jvm, this->listUtils);
this->loadRejectionMethodIds();
this->loadFieldMethodIds();
this->loadConditionMethodIds();
}
......@@ -36,6 +36,7 @@ MessageApiEndpoint::~MessageApiEndpoint()
delete this->endpointUtils;
delete this->protocolRecordUtils;
delete this->recordUtils;
delete this->rejectionUtils;
delete this->packetUtils;
delete this->listUtils;
delete this->typeUtils;
......@@ -63,6 +64,11 @@ RecordUtils *MessageApiEndpoint::getRecordUtils()
return this->recordUtils;
}
RejectionUtils *MessageApiEndpoint::getRejectionUtils()
{
return this->rejectionUtils;
}
PacketUtils *MessageApiEndpoint::getPacketUtils()
{
return this->packetUtils;
......@@ -79,18 +85,6 @@ TypeUtils *MessageApiEndpoint::getTypeUtils()
}
void MessageApiEndpoint::loadRejectionMethodIds()
{
jclass rejectionClass = JniUtils::getNamedClass(this->jvm, "gov/noaa/messageapi/interfaces/IRejection");
this->getRejectionCopyMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getCopy", this->getRejectionMethodSignature("getCopy"), false);
this->getRejectionReasonsMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getReasons", this->getRejectionMethodSignature("getReasons"), false);
this->getRejectionRecordMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getRecord", this->getRejectionMethodSignature("getRecord"), false);
this->addRejectionReasonMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "addReason", this->getRejectionMethodSignature("addReason"), false);
this->jvm->DeleteLocalRef(rejectionClass);
}
void MessageApiEndpoint::loadFieldMethodIds()
{
jclass fieldClass = JniUtils::getNamedClass(this->jvm, "gov/noaa/messageapi/interfaces/IField");
......@@ -114,29 +108,6 @@ void MessageApiEndpoint::loadConditionMethodIds()
this->jvm->DeleteLocalRef(conditionClass);
}
const char *MessageApiEndpoint::getRejectionMethodSignature(const char *methodName)
{
if (strcmp(methodName, "getCopy") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRejection;";
}
else if (strcmp(methodName, "getReasons") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getRecord") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRecord;";
}
else if (strcmp(methodName, "addReason") == 0)
{
return "(Ljava/lang/String;)V";
}
return NULL;
}
const char *MessageApiEndpoint::getFieldMethodSignature(const char *methodName)
{
if (strcmp(methodName, "getId") == 0)
......@@ -552,47 +523,4 @@ void MessageApiEndpoint::setConditionListVal(struct condition *condition, struct
this->jvm->CallVoidMethod(condition->jcondition, this->setConditionValueMethodId, value->jlist);
}
struct rejection_list *MessageApiEndpoint::createRejectionList()
{
jobject jList = this->jvm->NewObject(this->typeUtils->getListClass(), this->listUtils->createListMethod());
struct rejection_list *rejection_list = (struct rejection_list *)malloc(sizeof(struct rejection_list));
rejection_list->count = 0;
rejection_list->jrejections = jList;
return rejection_list;
}
void MessageApiEndpoint::addRejection(struct rejection_list *rejection_list, struct rejection *rejection)
{
this->jvm->CallVoidMethod(rejection_list->jrejections, this->listUtils->addListItemMethod(), rejection->jrejection);
rejection_list->count += 1;
}
struct rejection *MessageApiEndpoint::getRejectionCopy(struct rejection *rejection)
{
jobject jRejectionCopy = this->jvm->CallObjectMethod(rejection->jrejection, this->getRejectionCopyMethodId);
struct rejection *rejectionCopy = (struct rejection *)malloc(sizeof(struct rejection) + sizeof(jRejectionCopy));
rejectionCopy->jrejection = jRejectionCopy;
return rejectionCopy;
}
struct record *MessageApiEndpoint::getRejectionRecord(struct rejection *rejection)
{
jobject jRecord = this->jvm->CallObjectMethod(rejection->jrejection, this->getRejectionRecordMethodId);
struct record *record = (struct record *)malloc(sizeof(struct record) + sizeof(jRecord));
record->jrecord = jRecord;
return record;
}
struct string_list *MessageApiEndpoint::getRejectionReasons(struct rejection *rejection)
{
jobject jReasons = this->jvm->CallObjectMethod(rejection->jrejection, this->getRejectionReasonsMethodId);
struct string_list *reasons = this->listUtils->translateStringList(jReasons);
return reasons;
}
void MessageApiEndpoint::addRejectionReason(struct rejection *rejection, const char *reason)
{
jstring jReason = this->typeUtils->toJavaString(reason);
this->jvm->CallVoidMethod(rejection->jrejection, this->addRejectionReasonMethodId, jReason);
}
......@@ -15,6 +15,7 @@
#include "EndpointUtils.h"
#include "ProtocolRecordUtils.h"
#include "RecordUtils.h"
#include "RejectionUtils.h"
#include "PacketUtils.h"
/**
......@@ -39,18 +40,11 @@ public:
EndpointUtils *getEndpointUtils();
ProtocolRecordUtils *getProtocolRecordUtils();
RecordUtils *getRecordUtils();
RejectionUtils *getRejectionUtils();
PacketUtils *getPacketUtils();
ListUtils *getListUtils();
TypeUtils *getTypeUtils();
/*Rejection Methods*/
struct rejection_list *createRejectionList();
void addRejection(struct rejection_list *rejection_list, struct rejection *rejection);
struct rejection *getRejectionCopy(struct rejection *rejection);
struct record *getRejectionRecord(struct rejection *rejection);
struct string_list *getRejectionReasons(struct rejection *rejection);
void addRejectionReason(struct rejection *rejection, const char *reason);
/*Field Methods*/
const char *getFieldId(struct field *field);
const char *getFieldType(struct field *field);
......@@ -113,16 +107,11 @@ private :
EndpointUtils *endpointUtils;
ProtocolRecordUtils *protocolRecordUtils;
RecordUtils *recordUtils;
RejectionUtils *rejectionUtils;
PacketUtils *packetUtils;
TypeUtils *typeUtils;
ListUtils *listUtils;
/*Rejection Methods*/
jmethodID getRejectionCopyMethodId;
jmethodID getRejectionReasonsMethodId;
jmethodID getRejectionRecordMethodId;
jmethodID addRejectionReasonMethodId;
/*Field Methods*/
jmethodID getFieldIdMethodId;
jmethodID getFieldTypeMethodId;
......@@ -140,12 +129,10 @@ private :
/*Load method IDS for reuse. MethodIDS do not count against the jref count and do need to be released.*/
void loadRejectionMethodIds();
void loadFieldMethodIds();
void loadConditionMethodIds();
/*Grouped methods for returning the matching method signature string for a given interface*/
const char *getRejectionMethodSignature(const char *rejectionMethodName);
const char *getFieldMethodSignature(const char *fieldMethodName);
const char *getConditionMethodSignature(const char *conditionMethodName);
};
......
......@@ -3,15 +3,16 @@
#include <jni.h>
/**
Constructor for the RejectionUtils object.
*/
RejectionUtils::RejectionUtils(JNIEnv *jvm, ListUtils *listUtils)
/*Constructor*/
RejectionUtils::RejectionUtils(JNIEnv *jvm, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->loadGlobalRefs(jvm, listUtils);
this->loadGlobalRefs(jvm, typeUtils, listUtils);
this->loadMethodIds();
}
/*Destructor*/
RejectionUtils::~RejectionUtils()
{
try
......@@ -22,12 +23,88 @@ RejectionUtils::~RejectionUtils()
}
}
void RejectionUtils::loadGlobalRefs(JNIEnv *jvm, ListUtils *listUtils)
/*Public API*/
struct rejection_list *RejectionUtils::createRejectionList()
{
jobject jList = this->jvm->NewObject(this->typeUtils->getListClass(), this->listUtils->createListMethod());
struct rejection_list *rejection_list = (struct rejection_list *)malloc(sizeof(struct rejection_list));
rejection_list->count = 0;
rejection_list->jrejections = jList;
return rejection_list;
}
void RejectionUtils::addRejection(struct rejection_list *rejection_list, struct rejection *rejection)
{
this->jvm->CallVoidMethod(rejection_list->jrejections, this->listUtils->addListItemMethod(), rejection->jrejection);
rejection_list->count += 1;
}
struct rejection *RejectionUtils::getCopy(struct rejection *rejection)
{
jobject jRejectionCopy = this->jvm->CallObjectMethod(rejection->jrejection, this->getCopyMethodId);
struct rejection *rejectionCopy = (struct rejection *)malloc(sizeof(struct rejection) + sizeof(jRejectionCopy));
rejectionCopy->jrejection = jRejectionCopy;
return rejectionCopy;
}
struct record *RejectionUtils::getRecord(struct rejection *rejection)
{
jobject jRecord = this->jvm->CallObjectMethod(rejection->jrejection, this->getRecordMethodId);
struct record *record = (struct record *)malloc(sizeof(struct record) + sizeof(jRecord));
record->jrecord = jRecord;
return record;
}
struct string_list *RejectionUtils::getReasons(struct rejection *rejection)
{
jobject jReasons = this->jvm->CallObjectMethod(rejection->jrejection, this->getReasonsMethodId);
struct string_list *reasons = this->listUtils->translateStringList(jReasons);
return reasons;
}
void RejectionUtils::addReason(struct rejection *rejection, const char *reason)
{
jstring jReason = this->typeUtils->toJavaString(reason);
this->jvm->CallVoidMethod(rejection->jrejection, this->addReasonMethodId, jReason);
}
/*Private Methods*/
void RejectionUtils::loadGlobalRefs(JNIEnv *jvm, TypeUtils *typeUtils, ListUtils *listUtils)
{
this->jvm = jvm;
this->typeUtils = typeUtils;
this->listUtils = listUtils;
}
void RejectionUtils::loadMethodIds()
{
jclass rejectionClass = JniUtils::getNamedClass(this->jvm, "gov/noaa/messageapi/interfaces/IRejection");
this->getCopyMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getCopy", this->getMethodSignature("getCopy"), false);
this->getReasonsMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getReasons", this->getMethodSignature("getReasons"), false);
this->getRecordMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "getRecord", this->getMethodSignature("getRecord"), false);
this->addReasonMethodId = JniUtils::getMethod(this->jvm, rejectionClass, "addReason", this->getMethodSignature("addReason"), false);
this->jvm->DeleteLocalRef(rejectionClass);
}
const char *RejectionUtils::getMethodSignature(const char *methodName)
{
if (strcmp(methodName, "getCopy") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRejection;";
}
else if (strcmp(methodName, "getReasons") == 0)
{
return "()Ljava/util/List;";
}
else if (strcmp(methodName, "getRecord") == 0)
{
return "()Lgov/noaa/messageapi/interfaces/IRecord;";
}
else if (strcmp(methodName, "addReason") == 0)
{
return "(Ljava/lang/String;)V";
}
return NULL;
}
\ No newline at end of file
......@@ -12,6 +12,7 @@
#include "JniUtils.h"
#include "ListUtils.h"
#include "TypeUtils.h"
/**
* This is the header for the RejectionUtils class.
......@@ -22,17 +23,32 @@ class RejectionUtils
public:
/*Default constructor/destructors*/
RejectionUtils(JNIEnv *javaEnv, ListUtils *listUtils);
RejectionUtils(JNIEnv *javaEnv, TypeUtils *typeUtils, ListUtils *listUtils);
~RejectionUtils();
/*Rejection Methods*/
struct rejection_list *createRejectionList();
void addRejection(struct rejection_list *rejection_list, struct rejection *rejection);
struct rejection *getCopy(struct rejection *rejection);
struct record *getRecord(struct rejection *rejection);
struct string_list *getReasons(struct rejection *rejection);
void addReason(struct rejection *rejection, const char *reason);
private:
/*Vars*/
JNIEnv *jvm;
TypeUtils *typeUtils;
ListUtils *listUtils;
/*Rejection Methods*/
jmethodID getCopyMethodId;
jmethodID getReasonsMethodId;
jmethodID getRecordMethodId;
jmethodID addReasonMethodId;
/*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