All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mvel2.util.SharedVariableSpaceModel Maven / Gradle / Ivy

Go to download

TBEL is a powerful expression language for ThingsBoard platform user-defined functions. Original implementation is based on MVEL.

There is a newer version: 1.2.4
Show newest version
package org.mvel2.util;

import org.mvel2.integration.VariableResolver;
import org.mvel2.integration.VariableResolverFactory;
import org.mvel2.integration.impl.IndexVariableResolver;
import org.mvel2.integration.impl.IndexedVariableResolverFactory;
import org.mvel2.integration.impl.SimpleValueResolver;

/**
 * @author Mike Brock .
 */
public class SharedVariableSpaceModel extends VariableSpaceModel {
  private VariableResolver[] cachedGlobalResolvers;

  public SharedVariableSpaceModel(String[] allVars, Object[] vals) {
    super(allVars);

    cachedGlobalResolvers = new VariableResolver[vals.length];
    for (int i = 0; i < vals.length; i++) {
      cachedGlobalResolvers[i] = new IndexVariableResolver(i, vals);
    }
  }

  public VariableResolverFactory createFactory() {
    VariableResolver[] resolvers = new VariableResolver[allVars.length];
    for (int i = 0; i < resolvers.length; i++) {
      if (i >= cachedGlobalResolvers.length) {
        resolvers[i] = new SimpleValueResolver(null);
      }
      else {
        resolvers[i] = cachedGlobalResolvers[i];
      }
    }

    return new IndexedVariableResolverFactory(allVars, resolvers);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy