class IfTokenResolver implements TokenResolver, Initializable {

   public String resolve(Token token, QueryContext ctx) {
      if (token.getType() != TokenType.IF) {
         throw new DalRuntimeException("Internal error: only IF token is supported by " + getClass());
      }

      if (token instanceof StartTagToken) {
         if (ctx.isWithinIfToken()) {
            throw new DalRuntimeException("IF token can't be nested");
         }

         ctx.setWithinIfToken(true);
         ctx.setSqlResolveDisabled(!evaluate((StartTagToken) token, ctx));
         return "";
      } else if (token instanceof EndTagToken) {
         ctx.setWithinIfToken(false);
         ctx.setSqlResolveDisabled(false);
         return "";
      } else {
         throw new DalRuntimeException("Internal error: IF token can only be used as <IF ...> or </IF>");
      }
   }

}