Changeset 1990
- Timestamp:
- 02/02/09 09:01:22 (3 years ago)
- Location:
- trunk/simexplorer/simexplorer-methods/src/main/java/org/simexplorer/methods/plan
- Files:
-
- 1 added
- 1 modified
-
InputDesignMexicoPlan.java (modified) (3 diffs)
-
InputDesignMexicoPlanPanel.java (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/simexplorer/simexplorer-methods/src/main/java/org/simexplorer/methods/plan/InputDesignMexicoPlan.java
r1884 r1990 1 1 /* 2 2 * 3 * Copyright (c)2008, Cemagref3 * Copyright © 2008, Cemagref 4 4 * 5 5 * This program is free software; you can redistribute it and/or … … 20 20 package org.simexplorer.methods.plan; 21 21 22 import groovy.lang.GroovyShell; 23 import groovy.lang.Script; 24 22 25 import java.util.ArrayList; 23 26 import java.util.List; … … 25 28 import org.simexplorer.core.processors.AbstractArrayPlan; 26 29 import org.simexplorer.core.processors.ApplicativeContext; 27 import org.simexplorer.methods.processors.GroovyProcessor;28 30 import org.simexplorer.core.data.factors.ExperimentalFactor; 29 31 import org.simexplorer.core.data.factors.ExperimentalFactorsValues; 30 import org.simexplorer.exception.InternalProcessingError; 31 import org.simexplorer.exception.UserBadDataError; 32 import org.simexplorer.core.processors.annotations.Constant; 32 33 33 import java.util.logging.Level;34 import java.util.logging.Logger;35 34 36 35 public class InputDesignMexicoPlan extends AbstractArrayPlan { 37 36 38 private String inputFileName = "inputDesign.xml"; 37 @Constant 38 private String inputFileURI; //= "http://cfp6040.clermont.cemagref.fr/~florent.chuffart/hdpp_inputs/inputDesign1V5.xml"; // <-- example 39 39 40 41 42 //TODO ude grovy code editor instead, of processor43 40 @Override 44 41 protected void computeValues(ApplicativeContext context, List<ExperimentalFactor> factors) { 42 45 43 this.listOfListOfValues = new ArrayList<ExperimentalFactorsValues>(); 46 //this.size = 3;//null;//new Int(); 47 String groovycode = new StringBuilder().append("import org.simexplorer.core.data.factors.ExperimentalFactorsValues;\n") 48 .append("inputDesign = new XmlParser().parse(new File(inputFileName));\n") 49 .append("factorsNames = inputDesign.scenario[0].d.'@name';\n") 50 .append("inputDesign.scenario.each {listOfListOfValues << new ExperimentalFactorsValues (factorsNames, it.d.collect{it.value()[0]})};\n") 44 String groovyCode = new StringBuilder() 45 .append("import org.simexplorer.core.data.factors.ExperimentalFactorsValues\n") 46 .append("import org.simexplorer.efsfile.EFSFile\n") 47 .append("inputDesign = new XmlParser().parse( new EFSFile(inputFileURI).cache())\n") 48 .append("factorsNames = inputDesign.scenario[0].d.'@name'\n") 49 .append("inputDesign.scenario.each {listOfListOfValues << new ExperimentalFactorsValues (factorsNames, (it.d.collect{(it.value()[0]).toInteger()}))}\n") 51 50 .toString(); 52 // TODO don't use a GroovyProcessor, see #58 53 try { 54 GroovyProcessor groovyProcessor = new GroovyProcessor("xml parser"); 55 56 groovyProcessor.setVariable("inputFileName", inputFileName); 57 groovyProcessor.setVariable("listOfListOfValues", listOfListOfValues); 58 59 groovyProcessor.setCode(groovycode); 60 groovyProcessor.process(context); 61 62 63 } catch (InternalProcessingError ex) { 64 Logger.getLogger(InputDesignMexicoPlan.class.getName()).log(Level.SEVERE, null, ex); 65 } catch (UserBadDataError ex) { 66 Logger.getLogger(InputDesignMexicoPlan.class.getName()).log(Level.SEVERE, null, ex); 67 } 51 GroovyShell groovyShell = new GroovyShell(); 52 groovyShell.setVariable("inputFileURI",inputFileURI); 53 groovyShell.setVariable("listOfListOfValues", listOfListOfValues); 54 Script compiledScript = groovyShell.parse(groovyCode); 55 compiledScript.run(); 68 56 this.size = listOfListOfValues.size(); 69 57 } 70 58 71 public String getInputFileName() { 72 return inputFileName; 73 } 74 75 public void setInputFileName(String inputFileName) { 76 this.inputFileName = inputFileName; 59 public void setInputFileURI(String inputFileURI) { 60 this.inputFileURI = inputFileURI; 77 61 } 78 62





