org.mule.mvel2.util.SharedVariableSpaceModel Maven / Gradle / Ivy
Go to download
MVEL is a powerful expression language for Java-based applications.
It provides a plethora of features and is suited for everything
from the smallest property binding and extraction, to full blown scripts.
This is a fork of MVEL customized for use in Mule.
package org.mule.mvel2.util;
import org.mule.mvel2.integration.VariableResolver;
import org.mule.mvel2.integration.VariableResolverFactory;
import org.mule.mvel2.integration.impl.IndexVariableResolver;
import org.mule.mvel2.integration.impl.IndexedVariableResolverFactory;
import org.mule.mvel2.integration.impl.SimpleValueResolver;
/**
* @author Mike Brock .
*/
public class SharedVariableSpaceModel extends VariableSpaceModel {
private VariableResolver[] cachedGlobalResolvers;
public SharedVariableSpaceModel(String[] allVars, Object[] vals) {
this.allVars = 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);
}
}