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 d42d0aa62fddcd83131d15abb7797ab7f4b8fee2..86882361b7a142f77db2e875b47d2d0732d3170e 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 f5f2296642918140627a15ed9b9c29e5c074987b..8cf75d5e93ad6cc8962d3ed8d14242e80e1d0d89 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 5ba7948c306018540a3c2a6bf2a9bdc986a4e7ed..6e2da4e3fa6b4da7272890212fd12bb3ebf93fd9 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 7528f00348f68a963bccc66d2fea40e6f7937c9b..37e6946a402b82693e88588118d46f881c743c53 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) {