use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class IndexedPreFixIncNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
VariableResolver vResolver = factory.getIndexedVariableResolver(register);
vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1));
return ctx;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class InlineCollectionNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
if (accessor != null) {
return accessor.getValue(ctx, thisValue, factory);
} else {
try {
AccessorOptimizer ao = OptimizerFactory.getThreadAccessorOptimizer();
if (collectionGraph == null)
parseGraph(true, null, null);
accessor = ao.optimizeCollection(AbstractParser.getCurrentThreadParserContext(), collectionGraph, egressType, expr, trailingStart, trailingOffset, ctx, thisValue, factory);
egressType = ao.getEgressType();
return accessor.getValue(ctx, thisValue, factory);
} finally {
OptimizerFactory.clearThreadAccessorOptimizer();
}
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class InlineCollectionNode method execGraph.
private Object execGraph(Object o, Class type, Object ctx, VariableResolverFactory factory) {
if (o instanceof List) {
ArrayList list = new ArrayList(((List) o).size());
for (Object item : (List) o) {
list.add(execGraph(item, type, ctx, factory));
}
return list;
} else if (o instanceof Map) {
HashMap map = new HashMap();
for (Object item : ((Map) o).keySet()) {
map.put(execGraph(item, type, ctx, factory), execGraph(((Map) o).get(item), type, ctx, factory));
}
return map;
} else if (o instanceof Object[]) {
int dim = 0;
if (type != null) {
String nm = type.getName();
while (nm.charAt(dim) == '[') dim++;
} else {
type = Object[].class;
dim = 1;
}
Object newArray = Array.newInstance(getSubComponentType(type), ((Object[]) o).length);
try {
Class cls = dim > 1 ? findClass(null, repeatChar('[', dim - 1) + "L" + getBaseComponentType(type).getName() + ";", AbstractParser.getCurrentThreadParserContext()) : type;
int c = 0;
for (Object item : (Object[]) o) {
Array.set(newArray, c++, execGraph(item, cls, ctx, factory));
}
return newArray;
} catch (IllegalArgumentException e) {
throw new CompileException("type mismatch in array", expr, start, e);
} catch (ClassNotFoundException e) {
throw new RuntimeException("this error should never throw:" + getBaseComponentType(type).getName(), e);
}
} else {
if (type.isArray()) {
return MVEL.eval((String) o, ctx, factory, getBaseComponentType(type));
} else {
return MVEL.eval((String) o, ctx, factory);
}
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class NewObjectNode method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
try {
if (typeDescr.isArray()) {
Class cls = findClass(factory, typeDescr.getClassName(), null);
int[] s = new int[typeDescr.getArrayLength()];
ArraySize[] arraySize = typeDescr.getArraySize();
for (int i = 0; i < s.length; i++) {
s[i] = convert(eval(arraySize[i].value, ctx, factory), Integer.class);
}
return newInstance(cls, s);
} else {
String[] cnsRes = captureContructorAndResidual(name, 0, name.length);
List<char[]> constructorParms = parseMethodOrConstructor(cnsRes[0].toCharArray());
if (constructorParms != null) {
Class cls = findClass(factory, new String(subset(name, 0, findFirst('(', 0, name.length, name))).trim(), null);
Object[] parms = new Object[constructorParms.size()];
for (int i = 0; i < constructorParms.size(); i++) {
parms[i] = eval(constructorParms.get(i), ctx, factory);
}
Constructor cns = getBestConstructorCandidate(parms, cls, false);
if (cns == null)
throw new CompileException("unable to find constructor for: " + cls.getName(), expr, start);
for (int i = 0; i < parms.length; i++) {
//noinspection unchecked
parms[i] = convert(parms[i], cns.getParameterTypes()[i]);
}
if (cnsRes.length > 1) {
return PropertyAccessor.get(cnsRes[1], cns.newInstance(parms), factory, thisValue);
} else {
return cns.newInstance(parms);
}
} else {
Constructor<?> cns = Class.forName(typeDescr.getClassName(), true, currentThread().getContextClassLoader()).getConstructor(EMPTYCLS);
if (cnsRes.length > 1) {
return PropertyAccessor.get(cnsRes[1], cns.newInstance(), factory, thisValue);
} else {
return cns.newInstance();
}
}
}
} catch (CompileException e) {
throw e;
} catch (ClassNotFoundException e) {
throw new CompileException("unable to resolve class: " + e.getMessage(), expr, start, e);
} catch (NoSuchMethodException e) {
throw new CompileException("cannot resolve constructor: " + e.getMessage(), expr, start, e);
} catch (Exception e) {
throw new CompileException("could not instantiate class: " + e.getMessage(), expr, start, e);
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class NewObjectNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
if (newObjectOptimizer == null) {
if (egressType == null) {
if (factory != null && factory.isResolveable(typeDescr.getClassName())) {
try {
egressType = (Class) factory.getVariableResolver(typeDescr.getClassName()).getValue();
rewriteClassReferenceToFQCN(COMPILE_IMMEDIATE);
if (typeDescr.isArray()) {
try {
egressType = findClass(factory, repeatChar('[', typeDescr.getArrayLength()) + "L" + egressType.getName() + ";", null);
} catch (Exception e) {
// for now, don't handle this.
}
}
} catch (ClassCastException e) {
throw new CompileException("cannot construct object: " + typeDescr.getClassName() + " is not a class reference", expr, start, e);
}
}
}
if (typeDescr.isArray()) {
return (newObjectOptimizer = new NewObjectArray(getBaseComponentType(egressType.getComponentType()), typeDescr.getCompiledArraySize())).getValue(ctx, thisValue, factory);
}
try {
AccessorOptimizer optimizer = getThreadAccessorOptimizer();
ParserContext pCtx = new ParserContext();
pCtx.getParserConfiguration().setAllImports(getInjectedImports(factory));
newObjectOptimizer = optimizer.optimizeObjectCreation(pCtx, name, 0, name.length, ctx, thisValue, factory);
/**
* Check to see if the optimizer actually produced the object during optimization. If so,
* we return that value now.
*/
if (optimizer.getResultOptPass() != null) {
egressType = optimizer.getEgressType();
return optimizer.getResultOptPass();
}
} catch (CompileException e) {
throw ErrorUtil.rewriteIfNeeded(e, expr, start);
} finally {
OptimizerFactory.clearThreadAccessorOptimizer();
}
}
return newObjectOptimizer.getValue(ctx, thisValue, factory);
}
Aggregations