コード例 #1
1
  @Override
  public OlapConnection connectMDB(String dbName, String catalog) throws GamaRuntimeException {
    OlapWrapper wrapper;
    Connection conn;
    System.out.println("dbtype:" + dbtype);
    System.out.println("driver:" + driverMap.toString());
    System.out.println("jdbc:" + jdbcMap.toString());
    try {
      if (vender.equalsIgnoreCase(MONDRIAN)) {
        Class.forName(DRIVER);
        conn =
            DriverManager.getConnection(
                "jdbc:mondrian:"
                    + "JdbcDrivers="
                    + driverMap.get(dbtype.toLowerCase())
                    + ";"
                    + "Jdbc="
                    + jdbcMap.get(dbtype.toLowerCase())
                    + url
                    + ":"
                    + port
                    + "/"
                    + dbName
                    + "?user="******"&"
                    + "password="******";"
                    + "Catalog=file:"
                    + catalog
                    + ";");

        wrapper = (OlapWrapper) conn;
        olapConnection = wrapper.unwrap(OlapConnection.class);
      } else {
        throw GamaRuntimeException.error(
            "MondrianConnection.connectMDB: The " + vender + " is not supported!");
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw GamaRuntimeException.error(e.toString());
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw GamaRuntimeException.error(e.toString());
    }
    return olapConnection;
  }
コード例 #2
1
ファイル: RFile.java プロジェクト: usuallycwdillon/gama
  public void doRFileEvaluate(final IScope scope, final IContainer param) {
    int size = param.length(scope);
    // if ( size == 0 ) { throw GamaRuntimeException.error("Missing Parameter Exception", scope); }

    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);

      double[] vectorParam = new double[param.length(scope)];

      int k = 0;
      for (Object o : param.iterable(scope)) {
        vectorParam[k++] = Cast.asFloat(scope, o);
      }

      RCode c = new RCode();
      // Adding the parameters
      c.addDoubleArray("vectorParam", vectorParam);

      // Adding the codes in file
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute_param.Param:" + vectorParam.toString());
        GuiUtils.debug("Stats.R_compute_param.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute_param.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;

      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
      }
      br.close();
      fr.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);

      // DEBUG:
      // java.lang.System.out.println("Name: '" + R_statements.length(scope) + "'");
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.R_statements.length: '" + R_statements.size() + "'");
      }

      for (String name : caller.getParser().getNames()) {
        String[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // java.lang.System.out.println("Name: '" + name + "'");
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }

        result.put(name, GamaListFactory.create(scope, Types.NO_TYPE, results));
      }

      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute_param.return:" + result.serialize(false));
      }

      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }
コード例 #3
0
ファイル: SymbolDescription.java プロジェクト: trungpv88/gama
  private void flagError(
      final String s,
      final String code,
      final boolean warning,
      final boolean info,
      final EObject source,
      final String... data)
      throws GamaRuntimeException {

    if (warning && !info && !GamaPreferences.WARNINGS_ENABLED.getValue()) {
      return;
    }
    if (info && !GamaPreferences.INFO_ENABLED.getValue()) {
      return;
    }

    IDescription desc = this;
    EObject e = source;
    if (e == null) {
      e = getUnderlyingElement(null);
    }
    while (e == null && desc != null) {
      desc = desc.getEnclosingDescription();
      if (desc != null) {
        e = desc.getUnderlyingElement(null);
      }
    }
    if (!warning && !info) {
      final String resource = e == null ? "(no file)" : e.eResource().getURI().lastSegment();
      // System.err.println("COMPILATION ERROR in " + this.toString() + ":
      // " + s + "; source: " + resource);
    }
    // throws a runtime exception if there is no way to signal the error in
    // the source
    // (i.e. we are probably in a runtime scenario)
    if (e == null
        || e.eResource().getURI().path().contains(IExpressionCompiler.SYNTHETIC_RESOURCES_PREFIX)) {
      throw warning ? GamaRuntimeException.warning(s) : GamaRuntimeException.error(s);
    }
    final ErrorCollector c = getErrorCollector();
    if (c == null) {
      System.out.println((warning ? "Warning" : "Error") + ": " + s);
      return;
    }
    c.add(new GamlCompilationError(s, code, e, warning, info, data));
  }
コード例 #4
0
 @operator(value = "to_java")
 @doc(
     value = "represents the java way to write an expression in java, depending on its type",
     deprecated = "NOT YET IMPLEMENTED",
     see = {"to_gaml"})
 @Deprecated
 public static String toJava(final Object val) throws GamaRuntimeException {
   throw GamaRuntimeException.error("to_java is not yet implemented");
 }
コード例 #5
0
 @Override
 public void setChildren(final List<? extends ISymbol> children) {
   // First we verify the control architecture
   final IArchitecture control = getArchitecture();
   if (control == null) {
     throw GamaRuntimeException.error(
         "The control of species " + description.getName() + " cannot be computed");
   }
   // Then we classify the children in their categories
   for (final ISymbol s : children) {
     if (s instanceof ISpecies) {
       final ISpecies oneMicroSpecies = (ISpecies) s;
       oneMicroSpecies.setMacroSpecies(this);
       microSpecies.put(oneMicroSpecies.getName(), oneMicroSpecies);
     } else if (s instanceof IVariable) {
       variables.put(s.getName(), (IVariable) s);
     } else if (s instanceof AspectStatement) {
       aspects.put(s.getName(), (AspectStatement) s);
     } else if (s instanceof ActionStatement) {
       if (!s.getDescription().isBuiltIn()) {
         String name = s.getName();
         if (name.equals(initActionName)) {
           isInitOverriden = true;
         } else if (name.equals(stepActionName)) {
           isStepOverriden = true;
         }
       }
       actions.put(s.getName(), (ActionStatement) s);
     } else if (s instanceof UserCommandStatement) {
       userCommands.put(s.getName(), (UserCommandStatement) s);
     } else if (s instanceof IStatement) {
       behaviors.add((IStatement) s); // reflexes, states or tasks
     }
   }
   control.setChildren(behaviors);
   control.verifyBehaviors(this);
 }
コード例 #6
0
ファイル: ChartDataSet.java プロジェクト: trungpv88/gama
  public void updateXValues(IScope scope, int chartCycle, int targetNb) {
    Object xval, xlab;
    if (this.useXSource || this.useXLabels) {

      if (this.useXSource) {
        xval = xsource.resolveAgainst(scope).value(scope);
      } else {
        xval = xlabels.resolveAgainst(scope).value(scope);
      }
      if (this.useXLabels) {
        xlab = xlabels.resolveAgainst(scope).value(scope);
      } else {
        xlab = xsource.resolveAgainst(scope).value(scope);
      }

      if (xval instanceof GamaList) {
        IList xv2 = Cast.asList(scope, xval);
        IList xl2 = Cast.asList(scope, xlab);

        if (this.useXSource && xv2.size() > 0 && xv2.get(0) instanceof Number) {
          XSeriesValues = new ArrayList<Double>();
          Xcategories = new ArrayList<String>();
          for (int i = 0; i < xv2.size(); i++) {
            XSeriesValues.add(new Double(Cast.asFloat(scope, xv2.get(i))));
            Xcategories.add(Cast.asString(scope, xl2.get(i)));
          }

        } else {
          if (xv2.size() > Xcategories.size()) {
            Xcategories = new ArrayList<String>();
            for (int i = 0; i < xv2.size(); i++) {
              if (i >= XSeriesValues.size()) {
                XSeriesValues.add(new Double(getXCycleOrPlusOneForBatch(scope, chartCycle)));
              }
              Xcategories.add(Cast.asString(scope, xl2.get(i)));
            }
          }
        }
        if (xv2.size() < targetNb) {
          throw GamaRuntimeException.error(
              "The x-serie length ("
                  + xv2.size()
                  + ") should NOT be shorter than any series length ("
                  + targetNb
                  + ") !",
              scope);
        }

      } else {
        if (this.useXSource && xval instanceof Number) {
          double dvalue = Cast.asFloat(scope, xval);
          String lvalue = Cast.asString(scope, xlab);
          XSeriesValues.add(new Double(dvalue));
          Xcategories.add(lvalue);
        }
        if (targetNb == -1 && !this.forceNoXAccumulate) targetNb = XSeriesValues.size() + 1;
        while (XSeriesValues.size() < targetNb) {
          XSeriesValues.add(new Double(getXCycleOrPlusOneForBatch(scope, chartCycle)));
          Xcategories.add(Cast.asString(scope, xlab));
        }
      }
    }

    if (!this.useXSource && !this.useXLabels) {
      if (targetNb == -1 && !this.forceNoXAccumulate && commonXindex >= XSeriesValues.size())
        targetNb = XSeriesValues.size() + 1;
      while (XSeriesValues.size() < targetNb) {
        addCommonXValue(scope, getXCycleOrPlusOneForBatch(scope, chartCycle));
      }
    }
  }
コード例 #7
0
ファイル: RFile.java プロジェクト: usuallycwdillon/gama
  public void doRFileEvaluate(final IScope scope) {
    final String RFile = getPath();
    try {
      // Call R
      RCaller caller = new RCaller();

      String RPath = GamaPreferences.LIB_R.value(scope).getPath();
      caller.setRscriptExecutable(RPath);
      // caller.setRscriptExecutable("\"" + RPath + "\"");
      // if(java.lang.System.getProperty("os.name").startsWith("Mac"))
      // {
      // caller.setRscriptExecutable(RPath);
      // }

      RCode c = new RCode();
      List<String> R_statements = new ArrayList<String>();

      // tmthai.begin----------------------------------------------------------------------------
      String fullPath = FileUtils.constructAbsoluteFilePath(scope, RFile, true);
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.RScript:" + RPath);
        GuiUtils.debug("Stats.R_compute.RFile:" + RFile);
        GuiUtils.debug("Stats.R_compute.fullPath:" + fullPath);
      }

      // FileReader fr = new FileReader(RFile);
      FileReader fr = new FileReader(fullPath);
      // tmthai.end----------------------------------------------------------------------------

      BufferedReader br = new BufferedReader(fr);
      String statement;
      while ((statement = br.readLine()) != null) {
        c.addRCode(statement);
        R_statements.add(statement);
        // java.lang.System.out.println(statement);
        if (DEBUG) {
          GuiUtils.debug("Stats.R_compute.statement:" + statement);
        }
      }

      fr.close();
      br.close();
      caller.setRCode(c);

      GamaMap<String, IList> result = GamaMapFactory.create(Types.STRING, Types.LIST);

      String var = computeVariable(R_statements.get(R_statements.size() - 1).toString());
      caller.runAndReturnResult(var);
      for (String name : caller.getParser().getNames()) {
        Object[] results = null;
        results = caller.getParser().getAsStringArray(name);
        // for (int i = 0; i < results.length; i++) {
        // java.lang.System.out.println(results[i]);
        // }
        if (DEBUG) {
          GuiUtils.debug(
              "Stats.R_compute_param.caller.Name: '"
                  + name
                  + "' length: "
                  + results.length
                  + " - Value: "
                  + results.toString());
        }
        result.put(name, GamaListFactory.createWithoutCasting(Types.NO_TYPE, results));
      }
      if (DEBUG) {
        GuiUtils.debug("Stats.R_compute.return:" + result.serialize(false));
      }
      // return result;
      setBuffer(result);

    } catch (Exception ex) {

      throw GamaRuntimeException.error("RCallerExecutionException " + ex.getMessage(), scope);
    }
  }
コード例 #8
0
 public static GamaColor staticCast(
     final IScope scope, final Object obj, final Object param, final boolean copy)
     throws GamaRuntimeException {
   // param can contain the alpha value
   if (obj instanceof GamaColor) {
     GamaColor col = (GamaColor) obj;
     if (param instanceof Integer) {
       return new GamaColor(col.getRed(), col.getGreen(), col.getBlue(), (Integer) param);
     } else if (param instanceof Double) {
       return new GamaColor(col.getRed(), col.getGreen(), col.getBlue(), (Double) param);
     } else {
       return (GamaColor) obj;
     }
   }
   if (obj instanceof List) {
     List l = (List) obj;
     int size = l.size();
     if (size == 0) {
       return new GamaColor(Color.black);
     }
     if (size == 1 || size == 2) {
       return staticCast(scope, ((List) obj).get(0), param, copy);
     } else if (size == 3) {
       return new GamaColor(
           Cast.asInt(scope, l.get(0)),
           Cast.asInt(scope, l.get(1)),
           Cast.asInt(scope, l.get(2)),
           255);
     } else if (size >= 4) {
       return new GamaColor(
           Cast.asInt(scope, l.get(0)),
           Cast.asInt(scope, l.get(1)),
           Cast.asInt(scope, l.get(2)),
           Cast.asInt(scope, l.get(3)));
     }
     /* To allow constructions like rgb [255,255,255] */
   }
   if (obj instanceof IContainer) {
     return staticCast(
         scope, ((IContainer) obj).listValue(scope, Types.NO_TYPE, false), param, copy);
   }
   if (obj instanceof String) {
     String s = ((String) obj).toLowerCase();
     GamaColor c = GamaColor.colors.get(s);
     if (c == null) {
       try {
         c = new GamaColor(Color.decode(s));
       } catch (NumberFormatException e) {
         GamaRuntimeException ex =
             GamaRuntimeException.error("'" + s + "' is not a valid color name", scope);
         throw ex;
       }
       GamaColor.colors.put(s, c);
     }
     if (param == null) {
       return c;
     } else if (param instanceof Integer) {
       return new GamaColor(c, (Integer) param);
     } else if (param instanceof Double) {
       return new GamaColor(c, (Double) param);
     }
   }
   if (obj instanceof Boolean) {
     return (Boolean) obj ? new GamaColor(Color.black) : new GamaColor(Color.white);
   }
   int i = Cast.asInt(scope, obj);
   GamaColor gc = GamaColor.getInt((255 & 0xFF) << 24 | i & 0xFFFFFF << 0);
   if (param instanceof Integer) {
     return new GamaColor(gc, (Integer) param);
   } else if (param instanceof Double) {
     return new GamaColor(gc, (Double) param);
   }
   return gc;
 }
コード例 #9
0
  @Override
  public OlapConnection connectMDB() throws GamaRuntimeException {
    OlapWrapper wrapper;
    Connection conn;
    if (DEBUG) {
      GuiUtils.debug("dbtype:" + dbtype);
      GuiUtils.debug("driver:" + driverMap.toString());
      GuiUtils.debug("jdbc:" + jdbcMap.toString());
      GuiUtils.debug(
          "MondrianConnection.connectMDB:"
              + vender
              + " - "
              + dbtype
              + " - "
              + " - "
              + url
              + " - "
              + port
              + " - "
              + dbName
              + " - "
              + catalog
              + " - "
              + userName
              + " - "
              + password);
    }
    try {
      if (vender.equalsIgnoreCase(MONDRIAN)) {
        Class.forName(DRIVER);
        conn =
            DriverManager.getConnection(
                "jdbc:mondrian:"
                    + "JdbcDrivers="
                    + driverMap.get(dbtype.toLowerCase())
                    + ";"
                    + "Jdbc="
                    + jdbcMap.get(dbtype.toLowerCase())
                    + url
                    + ":"
                    + port
                    + "/"
                    + dbName
                    + "?user="******"&"
                    + "password="******";"
                    //						+"Catalog=file:C:\\Program Files\\Apache Software Foundation\\Tomcat
                    // 7.0\\webapps\\mondrian\\WEB-INF\\queries\\FoodMart.xml;"
                    + "Catalog=file:"
                    + catalog
                    + ";");

        wrapper = (OlapWrapper) conn;
        olapConnection = wrapper.unwrap(OlapConnection.class);
      } else {
        throw GamaRuntimeException.error(
            "MondrianConnection.connectMDB: The " + vender + " is not supported!");
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw GamaRuntimeException.error(e.toString());
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw GamaRuntimeException.error(e.toString());
    }
    return olapConnection;
  }