Esempio n. 1
0
 private ConfigurationMetadataHint parseHint(JSONObject json) {
   ConfigurationMetadataHint hint = new ConfigurationMetadataHint();
   hint.setId(json.getString("name"));
   if (json.has("values")) {
     JSONArray values = json.getJSONArray("values");
     for (int i = 0; i < values.length(); i++) {
       JSONObject value = values.getJSONObject(i);
       ValueHint valueHint = new ValueHint();
       valueHint.setValue(readItemValue(value.get("value")));
       String description = value.optString("description", null);
       valueHint.setDescription(description);
       valueHint.setShortDescription(extractShortDescription(description));
       hint.getValueHints().add(valueHint);
     }
   }
   if (json.has("providers")) {
     JSONArray providers = json.getJSONArray("providers");
     for (int i = 0; i < providers.length(); i++) {
       JSONObject provider = providers.getJSONObject(i);
       ValueProvider valueProvider = new ValueProvider();
       valueProvider.setName(provider.getString("name"));
       if (provider.has("parameters")) {
         JSONObject parameters = provider.getJSONObject("parameters");
         Iterator<?> keys = parameters.keys();
         while (keys.hasNext()) {
           String key = (String) keys.next();
           valueProvider.getParameters().put(key, readItemValue(parameters.get(key)));
         }
       }
       hint.getValueProviders().add(valueProvider);
     }
   }
   return hint;
 }
  private void compile() {
    Class[] staticLib = new Class[1];

    Class[] dynamicLib = new Class[1];
    context = new Object[1];
    Class[] dotLib = {Object.class, String.class, Class.class, java.util.Date.class};
    try {
      staticLib[0] = java.lang.Class.forName("java.lang.Math");

      pro = new ValueProvider();
      dynamicLib[0] = pro.getClass();
      context[0] = pro;

      res = new Resolver();

    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Can not find class for JEL!", e);
    }

    try {
      lib = new Library(staticLib, dynamicLib, dotLib, res, null);
      lib.markStateDependent("random", null);
    } catch (gnu.jel.CompilationException ec1) {
      throw new RuntimeException("Can not compile JEL Library!", ec1);
    }

    try {
      compExpression = Evaluator.compile(parsedExpression, lib, Boolean.TYPE);
    } catch (gnu.jel.CompilationException ec2) {
      throw new RuntimeException("Can not compile JEL Expression: " + expression, ec2);
    }
  }
  public boolean evaluate(IPlotterState state) {
    boolean ruleApplies = false;
    pro.setState(state);
    try {
      ruleApplies = compExpression.evaluate_boolean(context);
    } catch (Throwable t) {
      throw new RuntimeException("Runtime JEL Evaluation Problems!", t);
    }

    return ruleApplies;
  }
 public Appendable execute(Appendable appendable, ExecutionContext context) {
   ValueWrapper value = provider.get(context);
   try {
     if (value.isNull() || process(value.get())) {
       return super.execute(appendable, context);
     } else {
       return appendable;
     }
   } finally {
     value.release();
   }
 }
Esempio n. 5
0
 @Override
 public void fill(ValueProvider provider) {
   for (int z = 0; z < nbZ; z++) {
     int offsetZ = z * nbXY;
     for (int y = 0; y < nbY; y++) {
       int offsetY = offsetZ + y * nbX;
       for (int x = 0; x < nbX; x++) {
         int index = offsetY + x;
         byte oldValue = tileTypes[index];
         byte value = provider.getValue(x, y, z);
         if (oldValue != value) {
           tileTypes[index] = value;
           fireChange(x, y, z, oldValue, value);
         }
       }
     }
   }
 }
 private int getAttributeIndex(String key) {
   return pro.getAttributeIndex(key);
 }