use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class ALU method UnsupportedTypeException.
private static RuntimeException UnsupportedTypeException(final Object o1, final Object o2, final ASTNode node1, final ASTNode node2, String type) {
BeetlException ex = new BeetlException(BeetlException.EXPRESSION_NOT_COMPATIBLE, o1.getClass() + type + o2.getClass());
GrammarToken token = GrammarToken.createToken(node1.token.text + type + node2.token.text, node1.token.line);
ex.pushToken(token);
throw ex;
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class MapResourceLoader method getResource.
public Resource getResource(final String key) {
return new Resource(key, this) {
public Reader openReader() {
String val = get(key);
if (val == null) {
BeetlException ex = new BeetlException(BeetlException.TEMPLATE_LOAD_ERROR);
ex.pushResource(this);
throw ex;
}
return new StringReader(val);
}
public boolean isModified() {
return !autoCheck;
}
};
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class CacheTag method render.
@Override
public void render() {
try {
String key = null;
long refreshPeriod = 0;
BodyContent cahcedObject = null;
key = (String) this.args[0];
if (this.args.length == 3) {
boolean refreshNow = ((Boolean) this.args[2]).booleanValue();
if (refreshNow) {
cahcedObject = super.getBodyContent();
cacheManager.setObject(key, cahcedObject, refreshPeriod);
cahcedObject.fill(bw);
return;
}
}
if (this.args.length >= 2) {
refreshPeriod = ((Number) this.args[1]).longValue();
} else {
// 默认1小时刷新一次
refreshPeriod = 60 * 60;
}
if (refreshPeriod < 0) {
cahcedObject = super.getBodyContent();
cacheManager.setObject(key, cahcedObject, refreshPeriod);
cahcedObject.fill(bw);
} else {
cahcedObject = (BodyContent) cacheManager.getObject(key);
if (cahcedObject == null) {
cahcedObject = super.getBodyContent();
cacheManager.setObject(key, cahcedObject, refreshPeriod);
}
cahcedObject.fill(this.bw);
}
return;
} catch (IOException ex) {
if (!ctx.gt.getConf().isIgnoreClientIOError()) {
throw new BeetlException(BeetlException.CLIENT_IO_ERROR_ERROR, "IO Error", ex);
}
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class ForStatement method execute.
public final void execute(Context ctx) {
// idNode 是其后设置的
int varIndex = ((IVarIndex) idNode).getVarIndex();
Object collection = exp.evaluate(ctx);
IteratorStatus it = null;
if (collection == null) {
if (!this.hasSafe) {
BeetlException ex = new BeetlException(BeetlException.NULL);
ex.pushToken(exp.token);
throw ex;
} else {
it = new IteratorStatus(Collections.EMPTY_LIST);
}
} else {
it = IteratorStatus.getIteratorStatusByType(collection, itType);
if (it == null) {
BeetlParserException ex = new BeetlParserException(BeetlParserException.COLLECTION_EXPECTED_ERROR, "实际类型是:" + collection.getClass());
ex.pushToken(exp.token);
throw ex;
}
}
ctx.vars[varIndex + 1] = it;
//
if (this.hasGoto) {
while (it.hasNext()) {
ctx.vars[varIndex] = it.next();
forPart.execute(ctx);
switch(ctx.gotoFlag) {
case IGoto.NORMAL:
break;
case IGoto.CONTINUE:
ctx.gotoFlag = IGoto.NORMAL;
continue;
case IGoto.RETURN:
return;
case IGoto.BREAK:
ctx.gotoFlag = IGoto.NORMAL;
return;
}
}
if (!it.hasData()) {
if (elseforPart != null)
elseforPart.execute(ctx);
}
return;
} else {
while (it.hasNext()) {
ctx.vars[varIndex] = it.next();
forPart.execute(ctx);
}
if (!it.hasData()) {
if (elseforPart != null)
elseforPart.execute(ctx);
}
}
}
use of org.beetl.core.exception.BeetlException in project beetl2.0 by javamonkey.
the class FunctionExpression method infer.
public void infer(InferContext inferCtx) {
Function fn = inferCtx.gt.getFunction(name);
if (fn == null) {
Resource resource = getResource(inferCtx.gt, name);
if (resource == null) {
BeetlException ex = new BeetlException(BeetlException.FUNCTION_NOT_FOUND);
ex.pushToken(token);
throw ex;
} else {
fn = new FileFunctionWrapper(resource.getId());
}
}
for (Expression exp : exps) {
exp.infer(inferCtx);
}
// return type;
Class c = null;
if (fn instanceof SingleFunctionWrapper) {
SingleFunctionWrapper singleWrapper = (SingleFunctionWrapper) fn;
c = singleWrapper.getReturnType();
} else if (fn instanceof MutipleFunctionWrapper) {
try {
Class[] parasType = new Class[exps.length];
int i = 0;
for (Expression exp : exps) {
exp.infer(inferCtx);
parasType[i++] = exp.getType().cls;
}
c = ((MutipleFunctionWrapper) fn).getReturnType(parasType);
} catch (BeetlException ex) {
ex.pushToken(token);
throw ex;
}
} else {
Method call = null;
try {
call = fn.getClass().getMethod("call", Object[].class, Context.class);
c = call.getReturnType();
} catch (NoSuchMethodException e) {
BeetlException ex = new BeetlException(BeetlException.FUNCTION_INVALID);
ex.pushToken(token);
throw ex;
} catch (SecurityException e) {
BeetlException ex = new BeetlException(BeetlException.FUNCTION_INVALID);
ex.pushToken(token);
throw ex;
}
}
Type lastType = new Type(c);
if (vas == null) {
this.type = lastType;
return;
} else {
Type t = null;
for (VarAttribute attr : vas) {
inferCtx.temp = lastType;
attr.infer(inferCtx);
t = lastType;
lastType = attr.type;
attr.type = t;
}
this.type = lastType;
}
if (safeExp != null) {
safeExp.infer(inferCtx);
if (!safeExp.type.equals(this.type)) {
this.type = Type.ObjectType;
}
}
}
Aggregations