Commit 66a2d087 authored by George Nash's avatar George Nash

Add OCEndpointParseException

This adds OCEndpointParseException that will be thrown
if stringToEndpoint fails to parse the passed in string.

Initially I would have liked to use the java.text.ParseException
but it expects the errorOffset value which is the position where
the parse error occured in the source string. We don't have a
mechanism for discovering the errorOffset so a regular exception
with a error message has been used instead.

Additionally updated the NullPointerException code for setDi
to use the C/C++ abstraction macros for Java method calls.

Change-Id: I76442508c0b5b6c84d8c5ba303f0d982d550e5b6
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 42483dd5
package org.iotivity;
public class OCEndpointParseException extends Exception {
private static final long serialVersionUID = -7550359826963961621L;
public OCEndpointParseException(String message) {
super(message);
}
}
......@@ -67,40 +67,20 @@ void jni_free_endpoint(oc_endpoint_t *endpoint) {
/* The `oc_endpoint_t *endpoint` parameter is jarg1, the name is generated by SWIG. */
if(jarg1 == NULL) {
OC_DBG("JNI: OCEndpoint cannot be null.\n");
jclass clazz = (*jenv)->FindClass(jenv, "java/lang/NullPointerException");
(*jenv)->ThrowNew(jenv, clazz, "OCEndpoint cannot be null.");
jclass clazz = JCALL1(FindClass, jenv, "java/lang/NullPointerException");
JCALL2(ThrowNew, jenv, clazz, "OCEndpoint cannot be null.");
return;
}
/* The `oc_uuid_t *di` parameter is jarg2, the name is generated by SWIG. */
if(jarg2 == NULL) {
OC_DBG("JNI: OCUuid cannot be null.\n");
jclass clazz = (*jenv)->FindClass(jenv, "java/lang/NullPointerException");
(*jenv)->ThrowNew(jenv, clazz, "OCUuid cannot be null.");
jclass clazz = JCALL1(FindClass, jenv, "java/lang/NullPointerException");
JCALL2(ThrowNew, jenv, clazz, "OCUuid cannot be null.");
return;
}
$action
}
%rename(setDi) oc_endpoint_set_di;
/*
%inline %{
void jni_endpoint_set_di(oc_endpoint_t *endpoint, oc_uuid_t *di) {
if(endpoint == NULL) {
OC_DBG("JNI: OCEndpoint cannot be null.\n", __func__);
jclass clazz = (*jenv)->FindClass(jenv, "java/lang/IllegalArgumentException");
(*jenv)->ThrowNew(jenv, clazz, "OCEndpoint cannot be null.");
return;
}
if(di == NULL) {
OC_DBG("JNI: OCUuid cannot be null.\n", __func__);
jclass clazz = (*jenv)->FindClass(jenv, "java/lang/IllegalArgumentException");
(*jenv)->ThrowNew(jenv, clazz, "OCUuid cannot be null.");
return;
}
oc_endpoint_set_di(endpoint, di);
}
%}
*/
%ignore oc_endpoint_to_string;
%typemap(jni) jobject toString "jobject";
......@@ -144,6 +124,23 @@ SWIGEXPORT jobject JNICALL Java_org_iotivity_OCEndpointUtilJNI_toString(JNIEnv *
%apply oc_string_t *INPUT { oc_string_t *endpoint_str };
%apply oc_string_t *OUTPUT { oc_string_t *uri };
%javaexception("OCEndpointParseException") jni_string_to_endpoint {
$action
if(result == NULL) {
OC_DBG("JNI: String can not be parsed.");
jclass cls_OCEndpointParseException = JCALL1(FindClass, jenv, "org/iotivity/OCEndpointParseException");
assert(cls_OCEndpointParseException);
oc_string_t exception_message_part1;
oc_concat_strings(&exception_message_part1, "The \"", oc_string(*arg1));
oc_string_t exception_message;
oc_concat_strings(&exception_message, oc_string(exception_message_part1), "\" string cannot be parsed.");
JCALL2(ThrowNew, jenv, cls_OCEndpointParseException, ((char *)oc_string(exception_message)));
oc_free_string(&exception_message_part1);
oc_free_string(&exception_message);
return $null;
}
}
/* TODO figure out a clean way to return the uri param not as an array value */
%ignore oc_string_to_endpoint;
%rename(stringToEndpoint) jni_string_to_endpoint;
......
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