use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class GeneralForStatement method execute.
public void execute(Context ctx) {
if (expInit != null) {
for (Expression exp : expInit) {
exp.evaluate(ctx);
}
}
if (varAssignSeq != null) {
varAssignSeq.execute(ctx);
}
// boolean hasLooped = false;
for (; ; ) {
Object val = condtion.evaluate(ctx);
boolean bool = false;
if (val instanceof Boolean) {
bool = ((Boolean) val).booleanValue();
} else {
BeetlException be = new BeetlException(BeetlException.BOOLEAN_EXPECTED_ERROR);
be.pushToken(condtion.token);
throw be;
}
if (bool) {
// hasLooped = true;
forPart.execute(ctx);
switch(ctx.gotoFlag) {
case IGoto.NORMAL:
break;
case IGoto.CONTINUE:
ctx.gotoFlag = IGoto.NORMAL;
break;
case IGoto.RETURN:
return;
case IGoto.BREAK:
ctx.gotoFlag = IGoto.NORMAL;
return;
}
} else {
break;
}
if (this.expUpdate != null) {
for (Expression exp : expUpdate) {
exp.evaluate(ctx);
}
}
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class Type method getType.
public Type getType(String attrName) throws BeetlException {
if (Map.class.isAssignableFrom(cls)) {
if (types != null) {
return types[1];
} else {
}
return ObjectType;
} else if (Collection.class.isAssignableFrom(cls)) {
if (types != null) {
return types[0];
} else {
return ObjectType;
}
} else // }
if (cls == Object.class) {
return new Type(Object.class);
} else {
MethodInvoker invoker = ObjectUtil.getInvokder(cls, attrName);
if (invoker == null) {
BeetlException be = new BeetlException(BeetlException.GET_CALL_ERROR);
throw be;
}
Class returnCls = invoker.getReturnType();
if (returnCls == Object.class) {
return Type.ObjectType;
} else {
return new Type(returnCls);
}
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class VarRef method evaluate.
@Override
public Object evaluate(Context ctx) {
Object value = ctx.vars[varIndex];
if (value == Context.NOT_EXIST_OBJECT) {
if (hasSafe) {
return safe == null ? null : safe.evaluate(ctx);
} else {
BeetlException ex = new BeetlException(BeetlException.VAR_NOT_DEFINED);
ex.pushToken(this.firstToken);
throw ex;
}
}
if (value == null) {
if (hasSafe) {
return safe == null ? null : safe.evaluate(ctx);
}
}
if (attributes.length == 0) {
return value;
}
for (int i = 0; i < attributes.length; i++) {
VarAttribute attr = attributes[i];
if (value == null) {
if (hasSafe) {
return safe == null ? null : safe.evaluate(ctx);
} else {
BeetlException be = new BeetlException(BeetlException.NULL, "空指针");
if (i == 0) {
be.pushToken(this.firstToken);
} else {
be.pushToken(attributes[i - 1].token);
}
throw be;
}
}
try {
value = attr.evaluate(ctx, value);
} catch (BeetlException ex) {
ex.pushToken(attr.token);
throw ex;
} catch (RuntimeException ex) {
BeetlException be = new BeetlException(BeetlException.ATTRIBUTE_INVALID, "属性访问出错", ex);
be.pushToken(attr.token);
throw be;
}
}
if (value == null && hasSafe) {
return safe == null ? null : safe.evaluate(ctx);
} else {
return value;
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class NativeCallExpression method checkNull.
private void checkNull(Object o, NativeNode node) {
if (o == null) {
BeetlException be = new BeetlException(BeetlException.NULL);
be.pushToken(GrammarToken.createToken(node.getName(), token.line));
throw be;
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class NativeCallExpression method checkPermit.
private void checkPermit(Context ctx, Class targetCls, Object targetObj, String method) {
if (targetCls == null)
return;
if (!ctx.gt.getNativeSecurity().permit(ctx.template.program.res.getId(), targetCls, targetObj, method)) {
BeetlException be = new BeetlException(BeetlException.NATIVE_SECUARITY_EXCEPTION);
be.pushToken(GrammarToken.createToken(method, token.line));
throw be;
}
}
Aggregations