use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class Fold method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
List list;
if (constraintEx != null) {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
itemR.value = o;
if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
list.add(subEx.getValue(o, thisValue, itemFactory));
}
}
} else {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
}
}
return list;
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class ForEachNode method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item);
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
Object iterCond = MVEL.eval(expr, start, offset, thisValue, factory);
if (itemType != null && itemType.isArray())
enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
this.compiledBlock = (ExecutableStatement) subCompileExpression(expr, blockStart, blockOffset);
Object v;
if (iterCond instanceof Iterable) {
for (Object o : (Iterable) iterCond) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond != null && iterCond.getClass().isArray()) {
int len = Array.getLength(iterCond);
for (int i = 0; i < len; i++) {
itemR.setValue(Array.get(iterCond, i));
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond instanceof CharSequence) {
for (Object o : iterCond.toString().toCharArray()) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond instanceof Integer) {
int max = (Integer) iterCond + 1;
for (int i = 1; i != max; i++) {
itemR.setValue(i);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else {
throw new CompileException("non-iterable type: " + (iterCond != null ? iterCond.getClass().getName() : "null"), expr, start);
}
return null;
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class ForEachNode method handleCond.
private void handleCond(char[] condition, int start, int offset, int fields, ParserContext pCtx) {
int cursor = start;
int end = start + offset;
while (cursor < end && condition[cursor] != ':') cursor++;
if (cursor == end || condition[cursor] != ':')
throw new CompileException("expected : in foreach", condition, cursor);
int x;
if ((x = (item = createStringTrimmed(condition, start, cursor - start)).indexOf(' ')) != -1) {
String tk = new String(condition, start, x).trim();
try {
itemType = ParseTools.findClass(null, tk, pCtx);
item = new String(condition, start + x, (cursor - start) - x).trim();
} catch (ClassNotFoundException e) {
throw new CompileException("cannot resolve identifier: " + tk, condition, start);
}
}
// this.start = ++cursor;
this.start = cursor + 1;
this.offset = offset - (cursor - start) - 1;
if ((fields & COMPILE_IMMEDIATE) != 0) {
Class egress = (this.condition = (ExecutableStatement) subCompileExpression(expr, this.start, this.offset, pCtx)).getKnownEgressType();
if (itemType != null && egress.isArray()) {
enforceTypeSafety(itemType, getBaseComponentType(this.condition.getKnownEgressType()));
} else if (pCtx.isStrongTyping()) {
determineIterType(egress);
}
}
}
use of org.mule.mvel2.CompileException in project mvel by mikebrock.
the class Strsim method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
try {
String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory));
if (i == null)
throw new ClassCastException();
String x = (String) stmt.getReducedValue(ctx, thisValue, factory);
if (x == null)
throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), getStart());
return similarity(i, x);
} catch (ClassCastException e) {
throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart());
}
}
use of org.mule.mvel2.CompileException 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);
}
}
}
Aggregations