[LutinJ2R-commits] r50 - in lutinj2r/trunk: . src/main/java/org/codelutin/j2r/jni src/main/java/org/codelutin/j2r/net src/test/java/org/codelutin/j2r
Author: jcouteau Date: 2009-02-24 11:30:12 +0000 (Tue, 24 Feb 2009) New Revision: 50 Modified: lutinj2r/trunk/pom.xml lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java lutinj2r/trunk/src/test/java/org/codelutin/j2r/TestConstants.java Log: Changing JRI version, changing dependency from JClient to REngine and Rserve Modified: lutinj2r/trunk/pom.xml =================================================================== --- lutinj2r/trunk/pom.xml 2009-02-23 08:48:26 UTC (rev 49) +++ lutinj2r/trunk/pom.xml 2009-02-24 11:30:12 UTC (rev 50) @@ -17,18 +17,30 @@ <version>0.3-SNAPSHOT</version> <dependencies> - <dependency> + <!-- dependency> <groupId>externallib</groupId> <artifactId>JRclient</artifactId> <version>RF503</version> <scope>compile</scope> - </dependency> + </dependency--> <dependency> <groupId>externallib</groupId> <artifactId>JRI</artifactId> - <version>0.2-4-cl</version> + <version>0.7-0</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>externallib</groupId> + <artifactId>REngine</artifactId> + <version>0.6-0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>externallib</groupId> + <artifactId>Rserve</artifactId> + <version>0.6-0</version> + <scope>compile</scope> + </dependency> </dependencies> <!-- ************************************************************* --> @@ -54,7 +66,7 @@ <labs.name>lutinj2r</labs.name> <!-- FIXME --> - <maven.test.skip>true</maven.test.skip> + <maven.test.skip>false</maven.test.skip> <!-- Jar main class --> <!--maven.jar.main.class>org.codelutin.j2r.RProxy</maven.jar.main.class--> Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java =================================================================== --- lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-02-23 08:48:26 UTC (rev 49) +++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/jni/RJniEngine.java 2009-02-24 11:30:12 UTC (rev 50) @@ -90,20 +90,20 @@ if (log.isDebugEnabled()) { log.debug("Converting : " + rexp.toString()); } - int type = rexp.xt; + int type = rexp.getType(); Object result = null; switch (type) { case REXP.XT_STR: result = rexp.asString(); break; - case REXP.XT_DOUBLEARRAY: + case REXP.XT_ARRAY_DOUBLE: result = rexp.asDoubleArray(); double[] doublearray = (double[]) result; if (doublearray.length == 1) { result = doublearray[0]; } break; - case REXP.XT_INTARRAY: + case REXP.XT_ARRAY_INT: result = rexp.asIntArray(); int[] intarray = (int[]) result; if (intarray.length == 1) { Modified: lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java =================================================================== --- lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-02-23 08:48:26 UTC (rev 49) +++ lutinj2r/trunk/src/main/java/org/codelutin/j2r/net/RNetEngine.java 2009-02-24 11:30:12 UTC (rev 50) @@ -16,16 +16,16 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * -* RNetEngine.java -* -* Created: 22 aout 06 -* -* @author Arnaud Thimel <thimel@codelutin.com> -* @version $Revision: $ -* -* Mise a jour: $Date: $ -* par : $Author: $ -*/ + * RNetEngine.java + * + * Created: 22 aout 06 + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @version $Revision: $ + * + * Mise a jour: $Date: $ + * par : $Author: $ + */ package org.codelutin.j2r.net; @@ -33,9 +33,11 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.j2r.REngine; import org.codelutin.j2r.RException; -import org.rosuda.JRclient.REXP; -import org.rosuda.JRclient.RSrvException; -import org.rosuda.JRclient.Rconnection; +import org.rosuda.REngine.Rserve.RConnection; +import org.rosuda.REngine.Rserve.RserveException; +import org.rosuda.REngine.REXP; +import org.rosuda.REngine.REXPInteger; +import org.rosuda.REngine.REXPMismatchException; /** * Cette classe represente le moteur reseau pour acceder a R. Par defaut, il @@ -49,122 +51,131 @@ */ public class RNetEngine implements REngine { - public static final int DEFAULT_PORT = 6311; - public static final String DEFAULT_HOST = "127.0.0.1"; + public static final int DEFAULT_PORT = 6311; + public static final String DEFAULT_HOST = "127.0.0.1"; private Log log = LogFactory.getLog(RNetEngine.class); - private Rconnection conn; + private RConnection conn; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.codelutin.j2r.REngine#init() */ public boolean init() { - String typeProp = System.getProperty("R.type", "net"); - int urlPos = typeProp.indexOf("net://"); - String host = null; - String portAsString = null; - if (urlPos != -1) { - String url = typeProp.substring(urlPos + 6); - int commaPos = url.indexOf(":"); - if (commaPos != -1) { - host = url.substring(0, commaPos); - portAsString = url.substring(commaPos + 1); - } else { - host = url; - } - } - if (host == null || "".equals(host)) { - host = DEFAULT_HOST; - } - int port = DEFAULT_PORT; - if (portAsString != null) { - try { - port = Integer.parseInt(portAsString); - } catch (NumberFormatException nfe) { - if (log.isWarnEnabled()) { - log.warn("Bad port format " + portAsString + ", using default" + - " port : " + port); - } - } - } + String typeProp = System.getProperty("R.type", "net"); + int urlPos = typeProp.indexOf("net://"); + String host = null; + String portAsString = null; + if (urlPos != -1) { + String url = typeProp.substring(urlPos + 6); + int commaPos = url.indexOf(":"); + if (commaPos != -1) { + host = url.substring(0, commaPos); + portAsString = url.substring(commaPos + 1); + } else { + host = url; + } + } + if (host == null || "".equals(host)) { + host = DEFAULT_HOST; + } + int port = DEFAULT_PORT; + if (portAsString != null) { + try { + port = Integer.parseInt(portAsString); + } catch (NumberFormatException nfe) { + if (log.isWarnEnabled()) { + log.warn("Bad port format " + portAsString + + ", using default" + " port : " + port); + } + } + } return init(host, port); } public boolean init(String host, int port) { - if (log.isInfoEnabled()) { - log.info("Trying to connect to the Rserve on '" + host + ":" + port + "'"); - } - try { - conn = new Rconnection(host, port); - } catch (RSrvException e) { - log.error("Unable to establish a connection to the R server. " + - "Maybe you forgot to start it. " + - "Try using the command \"R CMD Rserve\"."); - e.printStackTrace(); - return false; + if (log.isInfoEnabled()) { + log.info("Trying to connect to the Rserve on '" + host + ":" + port + + "'"); } + try { + conn = new RConnection(host, port); + } catch (RserveException e) { + log.error("Unable to establish a connection to the R server. " + + "Maybe you forgot to start it. " + + "Try using the command \"R CMD Rserve\"."); + e.printStackTrace(); + return false; + } return conn.isConnected(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.codelutin.R.REngine#eval(java.lang.String) */ public Object eval(String expr) throws RException { REXP result = null; try { result = conn.eval(expr); - } catch (RSrvException e) { + } catch (RserveException e) { throw new RException("An error occured during the eval method", e); } return convertResult(result); } private Object convertResult(REXP rexp) { - if (rexp == null) { - log.debug("Null returned"); - return null; - } + if (rexp == null) { + log.debug("Null returned"); + return null; + } if (log.isDebugEnabled()) { log.debug("Converting : " + rexp.toString()); } - int type = rexp.getType(); + Object result = null; - switch (type) { - case REXP.XT_BOOL: - result = rexp.asBool().isTRUE(); - break; - case REXP.XT_STR: + + try { + + if (rexp.isInteger()) { + result = rexp.asIntegers(); + int[] intarray = (int[]) result; + if (intarray.length == 1) { + result = intarray[0]; + } + } + + else if (rexp.isString()) { result = rexp.asString(); - break; - case REXP.XT_DOUBLE: - result = rexp.asDouble(); - break; - case REXP.XT_INT: - result = rexp.asInt(); - break; - case REXP.XT_ARRAY_DOUBLE: - result = rexp.asDoubleArray(); - double[] doublearray = (double[])result; + } + + else if (rexp.isFactor()) { + result = rexp.asFactor(); + } + + else if (rexp.isNumeric()) { + result = rexp.asDoubles(); + double[] doublearray = (double[]) result; if (doublearray.length == 1) { result = doublearray[0]; } - break; - case REXP.XT_ARRAY_INT: - result = rexp.asIntArray(); - int[] intarray = (int[])result; - if (intarray.length == 1) { - result = intarray[0]; - } - break; - default: - log.error("Unknown return type [" + type + "] " + - "on : " + rexp.toString()); + } + + else { + log.error("Unknown return type on : " + rexp.toString()); + } + } catch (REXPMismatchException e) { + e.printStackTrace(); } return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.codelutin.j2r.REngine#terminate() */ public void terminate() throws RException { @@ -173,15 +184,17 @@ } } - /* (non-Javadoc) - * @see org.codelutin.j2r.REngine#voidEval(java.lang.String) - */ - public void voidEval(String expr) throws RException { - try { - conn.voidEval(expr); - } catch (RSrvException rse) { - throw new RException("An error occured while voidEval on net", rse); - } - } + /* + * (non-Javadoc) + * + * @see org.codelutin.j2r.REngine#voidEval(java.lang.String) + */ + public void voidEval(String expr) throws RException { + try { + conn.voidEval(expr); + } catch (RserveException rse) { + throw new RException("An error occured while voidEval on net", rse); + } + } -} //RNetEngine +} // RNetEngine Modified: lutinj2r/trunk/src/test/java/org/codelutin/j2r/TestConstants.java =================================================================== --- lutinj2r/trunk/src/test/java/org/codelutin/j2r/TestConstants.java 2009-02-23 08:48:26 UTC (rev 49) +++ lutinj2r/trunk/src/test/java/org/codelutin/j2r/TestConstants.java 2009-02-24 11:30:12 UTC (rev 50) @@ -29,6 +29,9 @@ package org.codelutin.j2r; +import org.junit.Ignore; + +@Ignore public class TestConstants { /*
participants (1)
-
jcouteau@users.labs.libre-entreprise.org