code: public static Query toQuery(Object o) throws PageException {
  	if (o instanceof Query) return (Query) o;
  	if (o instanceof ObjectWrap) {
  	    return toQuery(((ObjectWrap) o).getEmbededObject());
  	}
  	if (o instanceof ResultSet) return new QueryImpl((ResultSet) o, "query", ThreadLocalPageContext.getTimeZone());
  	if (o instanceof Component) {
  	    Member member = ((Component) o).getMember(Component.ACCESS_PRIVATE, KeyConstants.__toQuery, false, false);
  	    if (member instanceof UDFPlus) {
  		UDFPlus udf = (UDFPlus) member;
  		if (udf.getReturnType() == CFTypes.TYPE_QUERY && udf.getFunctionArguments().length == 0) {
  		    return Caster.toQuery(((Component) o).call(ThreadLocalPageContext.get(), KeyConstants.__toQuery, new Object[] {}));
  		}
  	    }
  	}
  
  	throw new CasterException(o, "query");
      }
docs: cast a Object to a Query Object
  
  @param o Object to cast
  @return casted Query Object
  @throws PageException