Search in sources :

Example 21 with BeetlException

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);
            }
        }
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Example 22 with BeetlException

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);
        }
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException) Collection(java.util.Collection) MethodInvoker(org.beetl.core.om.MethodInvoker)

Example 23 with BeetlException

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;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Example 24 with BeetlException

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;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Example 25 with BeetlException

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;
    }
}
Also used : BeetlException(org.beetl.core.exception.BeetlException)

Aggregations

BeetlException (org.beetl.core.exception.BeetlException)60 GrammarToken (org.beetl.core.statement.GrammarToken)10 IOException (java.io.IOException)7 BeetlParserException (org.beetl.core.exception.BeetlParserException)6 Expression (org.beetl.core.statement.Expression)6 AndExpression (org.beetl.core.statement.AndExpression)5 ArthExpression (org.beetl.core.statement.ArthExpression)5 CompareExpression (org.beetl.core.statement.CompareExpression)5 ContentBodyExpression (org.beetl.core.statement.ContentBodyExpression)5 FormatExpression (org.beetl.core.statement.FormatExpression)5 FunctionExpression (org.beetl.core.statement.FunctionExpression)5 IncDecExpression (org.beetl.core.statement.IncDecExpression)5 JsonArrayExpression (org.beetl.core.statement.JsonArrayExpression)5 JsonMapExpression (org.beetl.core.statement.JsonMapExpression)5 NativeCallExpression (org.beetl.core.statement.NativeCallExpression)5 NegExpression (org.beetl.core.statement.NegExpression)5 NotBooleanExpression (org.beetl.core.statement.NotBooleanExpression)5 OrExpression (org.beetl.core.statement.OrExpression)5 StatementExpression (org.beetl.core.statement.StatementExpression)5 TernaryExpression (org.beetl.core.statement.TernaryExpression)5