class FieldTokenResolver implements TokenResolver {

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

      SimpleTagToken field = (SimpleTagToken) token;
      String fieldName = field.getAttribute("name", null);
      String tableName = field.getAttribute("table", ctx.getEntityInfo().getLogicalName());
      String[] logicalNameAndAlias = ctx.getEntityInfo().getLogicalNameAndAlias(tableName);
      EntityInfo entityInfo = m_manager.getEntityInfo(logicalNameAndAlias[0]);
      Attribute attribute = entityInfo.getAttribute(fieldName);

      if (attribute != null) {
         switch (ctx.getQuery().getType()) {
         case SELECT:
            if (!ctx.isTableResolved()) {
               DataField f = entityInfo.getFieldByName(fieldName);

               ctx.addOutField(f);
               ctx.addOutSubObjectName(null);
            }

            if (attribute.selectExpr().length() > 0) {
               return m_expressionResolver.resolve(ctx, attribute.selectExpr());
            } else {
               String tableAlias = logicalNameAndAlias[1];

               return m_naming.getField(attribute.field(), tableAlias);
            }
         case INSERT:
            return m_naming.getField(attribute.field());
         case UPDATE:
            return m_naming.getField(attribute.field());
         case DELETE:
            return m_naming.getField(attribute.field());
         default:
            throw new DalRuntimeException("TABLE token does not support query type: " + ctx.getQuery().getType());
         }
      } else {
         throw new DalRuntimeException("DataField(" + fieldName + ") is not defined in "
               + ctx.getQuery().getEntityClass() + ". Query: " + ctx.getQuery());
      }
   }

}