code: public static Query toQuery(Object o, boolean duplicate) throws PageException {
  
  	if (o instanceof Query) {
  	    if (duplicate) {
  		Query src = (Query) o;
  		Query trg = new QueryImpl(src.getColumnNames(), src.getRowCount(), "query");
  
  		Collection.Key[] keys = src.getColumnNames();
  		QueryColumn[] columnsSrc = new QueryColumn[keys.length];
  		for (int i = 0; i < columnsSrc.length; i++) {
  		    columnsSrc[i] = src.getColumn(keys[i]);
  		}
  
  		keys = trg.getColumnNames();
  		QueryColumn[] columnsTrg = new QueryColumn[keys.length];
  		for (int i = 0; i < columnsTrg.length; i++) {
  		    columnsTrg[i] = trg.getColumn(keys[i]);
  		}
  
  		int i;
  		for (int row = trg.getRecordcount(); row > 0; row--) {
  		    for (i = 0; i < columnsTrg.length; i++) {
  			columnsTrg[i].set(row, columnsSrc[i].get(row, null));
  		    }
  		}
  		return trg;
  	    }
  	    return (Query) o;
  	}
  	else if (o instanceof ObjectWrap) {
  	    return toQuery(((ObjectWrap) o).getEmbededObject(), duplicate);
  	}
  	throw new CasterException(o, "query");
      }
docs: cast a Object to a Query Object
  
  @param o Object to cast
  @param duplicate duplicate the object or not
  @return casted Query Object
  @throws PageException