From 44abbf09efeef5ca2ec890016e81b1c858c55831 Mon Sep 17 00:00:00 2001 From: pompert <sdos@astron.nl> Date: Mon, 10 Jul 2006 08:14:11 +0000 Subject: [PATCH] 701 getHistory function added to jParmFacade --- .../java/cep/jparmfacade/jParmFacade.java | 7 ++ .../cep/jparmfacade/jParmFacadeAdapter.java | 16 ++++ .../cep/jparmfacade/jParmFacadeInterface.java | 8 +- ..._lofar_java_cep_jparmfacade_jParmFacade.cc | 82 ++++++++++++++++++- 4 files changed, 110 insertions(+), 3 deletions(-) diff --git a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacade.java b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacade.java index d42d0aa62fd..86882361b7a 100644 --- a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacade.java +++ b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacade.java @@ -61,4 +61,11 @@ public class jParmFacade { double startx, double endx, int nx, double starty, double endy, int ny) throws Exception; + // Get the parameter values for the given parameters and timeframe. + // The domain is given by the start and end values, while the time is + // given by startSolvTime and endSolveTime. + public native HashMap<String,Vector<Double>> getHistory(String parmNamePattern, + double startx, double endx, double starty, + double endy, double startSolveTime, double endSolveTime) throws Exception; + } diff --git a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeAdapter.java b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeAdapter.java index f5f22966429..8cf75d5e93a 100644 --- a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeAdapter.java +++ b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeAdapter.java @@ -86,5 +86,21 @@ public class jParmFacadeAdapter extends UnicastRemoteObject implements jParmFaca return aM; } + // Get the parameter values for the given parameters and timeframe. + // The domain is given by the start and end values, while the time is + // given by startSolvTime and endSolveTime. + public HashMap<String,Vector<Double>> getHistory(String parmNamePattern, + double startx, double endx, double starty, + double endy, double startSolveTime, double endSolveTime) throws RemoteException { + HashMap<String,Vector<Double>> aM=null; + try { + aM=adaptee.getHistory(parmNamePattern,startx,endx,starty,endy,startSolveTime,endSolveTime); + } catch (Exception ex) { + RemoteException anEx=new RemoteException("JNI getHistory error caused by: " + ex.getMessage()); + //anEx.initCause(ex); + throw anEx; + } + return aM; + } protected jParmFacade adaptee; } diff --git a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeInterface.java b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeInterface.java index 5ba7948c306..6e2da4e3fa6 100644 --- a/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeInterface.java +++ b/JAVA/CEP/jParmFacade/src/nl/astron/lofar/java/cep/jparmfacade/jParmFacadeInterface.java @@ -44,11 +44,17 @@ public interface jParmFacadeInterface extends Remote // An empty name pattern is the same as * (all parm names). public Vector<String> getNames(String parmNamePattern) throws RemoteException; - // Get the parameter values for the given parameters and domain. // The domain is given by the start and end values, while the grid is // given by nx and ny. public HashMap<String,Vector<Double>> getValues(String parmNamePattern, double startx, double endx, int nx, double starty, double endy, int ny) throws RemoteException; + + // Get the parameter values for the given parameters and timeframe. + // The domain is given by the start and end values, while the time is + // given by startSolveTime and endSolveTime. + public HashMap<String,Vector<Double>> getHistory(String parmNamePattern, + double startx, double endx, double starty, + double endy, double startSolveTime, double endSolveTime) throws RemoteException; } diff --git a/JAVA/CEP/jParmFacade/src/nl_astron_lofar_java_cep_jparmfacade_jParmFacade.cc b/JAVA/CEP/jParmFacade/src/nl_astron_lofar_java_cep_jparmfacade_jParmFacade.cc index 7528f00348f..37e6946a402 100644 --- a/JAVA/CEP/jParmFacade/src/nl_astron_lofar_java_cep_jparmfacade_jParmFacade.cc +++ b/JAVA/CEP/jParmFacade/src/nl_astron_lofar_java_cep_jparmfacade_jParmFacade.cc @@ -127,8 +127,6 @@ JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_ return nameVector; } - - /* * Class: nl_astron_lofar_java_cep_jparmfacade_jParmFacade * Method: getValues @@ -209,6 +207,86 @@ JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_ return result; } +/* + * Class: nl_astron_lofar_java_cep_jparmfacade_jParmFacade + * Method: getHistory + * Signature: (Ljava/lang/String;DDIDDI)Ljava/util/HashMap; + */ +JNIEXPORT jobject JNICALL Java_nl_astron_lofar_java_cep_jparmfacade_jParmFacade_getHistory (JNIEnv *env, jobject obj, jstring parmNamePattern, jdouble startx, jdouble endx, jdouble starty, jdouble endy, jdouble startSolveTime, jdouble endSolveTime) { + + jboolean isCopy; + jobject result; + + // create the connection with the ParmDB + setParmDBConnection(env,obj); + + + const char* pattern = env->GetStringUTFChars (parmNamePattern, &isCopy); + map<string,vector<double> > valMap; + try { + valMap = theirPF->getHistory(pattern,startx,endx,starty,endy,startSolveTime,endSolveTime); + env->ReleaseStringUTFChars (parmNamePattern, pattern); + + // Construct java Map + jclass mapClass, doubleClass, vectorClass; + jmethodID mapInit, mapPut, vectorAdd, doubleInit, vectorInit; + + mapClass = env->FindClass("java/util/HashMap"); + mapInit = env->GetMethodID(mapClass, "<init>", "()V"); + result = env->NewObject(mapClass, mapInit); + mapPut= env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + + // Construct java Double + jobject jDouble; + doubleClass = env->FindClass ("java/lang/Double"); + doubleInit = env->GetMethodID (doubleClass, "<init>", "(D)V"); + + + // Loop through map and convert to HashMap + + for (map<string,vector<double> >::const_iterator valIter=valMap.begin(); + valIter != valMap.end(); + valIter++) { + + // Construct java Vector + jobject valVector; + vectorClass = env->FindClass("java/util/Vector"); + vectorInit = env->GetMethodID(vectorClass, "<init>", "()V"); + valVector = env->NewObject(vectorClass, vectorInit); + vectorAdd = env->GetMethodID(vectorClass, "add", "(Ljava/lang/Object;)Z"); + + + for (vector<double>::const_iterator iter=valIter->second.begin(); + iter != valIter->second.end(); + iter++) { + + jDouble = env->NewObject (doubleClass, doubleInit, *iter); + + env->CallObjectMethod(valVector, vectorAdd, jDouble); + } + + + env->CallObjectMethod(result, mapPut, env->NewStringUTF(valIter->first.c_str()),valVector); + + } + } catch (exception &ex) { + cout << "Exception during getHistory("<< pattern << "," << startx << "," + << endx << "," << starty << "," << endy << "," << startSolveTime << "," + << endSolveTime << ") : "<< ex.what() << endl; + string aStr= (string)ex.what(); + jclass newExcCls = env->FindClass("java/lang/Exception"); + if (newExcCls == 0) { + cout << "Unable to find the new exception class, give up." << endl; + // env->ReleaseStringUTFChars (parmNamePattern, pattern); + return result; + } + + env->ThrowNew(newExcCls,aStr.c_str()); + } + + return result; +} + void setParmDBConnection(JNIEnv *env, jobject callerObject) { -- GitLab