Changeset 1990

Show
Ignore:
Timestamp:
02/02/09 09:01:22 (3 years ago)
Author:
florent.chuffart
Message:

add InputDesignMexicoPlanPanel class

Location:
trunk/simexplorer/simexplorer-methods/src/main/java/org/simexplorer/methods/plan
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/simexplorer/simexplorer-methods/src/main/java/org/simexplorer/methods/plan/InputDesignMexicoPlan.java

    r1884 r1990  
    11/* 
    22 * 
    3  *  Copyright (c) 2008, Cemagref 
     3 *  Copyright © 2008, Cemagref 
    44 * 
    55 *  This program is free software; you can redistribute it and/or 
     
    2020package org.simexplorer.methods.plan; 
    2121 
     22import groovy.lang.GroovyShell; 
     23import groovy.lang.Script; 
     24 
    2225import java.util.ArrayList; 
    2326import java.util.List; 
     
    2528import org.simexplorer.core.processors.AbstractArrayPlan; 
    2629import org.simexplorer.core.processors.ApplicativeContext; 
    27 import org.simexplorer.methods.processors.GroovyProcessor; 
    2830import org.simexplorer.core.data.factors.ExperimentalFactor; 
    2931import org.simexplorer.core.data.factors.ExperimentalFactorsValues; 
    30 import org.simexplorer.exception.InternalProcessingError; 
    31 import org.simexplorer.exception.UserBadDataError; 
     32import org.simexplorer.core.processors.annotations.Constant; 
    3233 
    33 import java.util.logging.Level; 
    34 import java.util.logging.Logger; 
    3534 
    3635public class InputDesignMexicoPlan extends AbstractArrayPlan { 
    3736 
    38   private String inputFileName = "inputDesign.xml"; 
     37    @Constant 
     38  private String inputFileURI; //= "http://cfp6040.clermont.cemagref.fr/~florent.chuffart/hdpp_inputs/inputDesign1V5.xml"; // <-- example 
    3939 
    40    
    41    
    42   //TODO ude grovy code editor instead, of processor 
    4340  @Override 
    4441  protected void computeValues(ApplicativeContext context, List<ExperimentalFactor> factors) { 
     42 
    4543    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") 
    5150    .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(); 
    6856    this.size = listOfListOfValues.size(); 
    6957  } 
    7058 
    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; 
    7761  } 
    7862 

logo cemagref

logo iscpif

logo lifegrid

logo region auvergne

logo patres project