} else if (fd.isReference()) { QueryReference qr = new QueryObjectReference(qc, fieldName); QueryClass qc2 = (QueryClass) q.getReverseAliases().get(fieldValue); QueryHelper.addConstraint(q, qc, new ContainsConstraint(qr, fieldOp, qc2)); } else if (fd.isCollection()) { QueryReference qr = new QueryCollectionReference(qc, fieldName); QueryClass qc2 = (QueryClass) q.getReverseAliases().get(fieldValue); QueryHelper.addConstraint(q, qc, new ContainsConstraint(qr, fieldOp, qc2));
    protected static Query createQuery(Map queryClasses, Model model, Map savedBags)        throws Exception {        Query q = new Query();        Map mapping = new HashMap();        for (Iterator i = queryClasses.keySet().iterator(); i.hasNext();) {            String alias = (String) i.next();            DisplayQueryClass d = (DisplayQueryClass) queryClasses.get(alias);            QueryClass qc = new QueryClass(Class.forName(d.getType()));            q.alias(qc, alias);            q.addFrom(qc);            q.addToSelect(qc);            mapping.put(d, qc);        }                for (Iterator i = queryClasses.keySet().iterator(); i.hasNext();) {            String alias = (String) i.next();            DisplayQueryClass d = (DisplayQueryClass) queryClasses.get(alias);            QueryClass qc = (QueryClass) mapping.get(d);            ClassDescriptor cld = model.getClassDescriptorByName(d.getType());            for (Iterator j = d.getConstraintNames().iterator(); j.hasNext();) {                String constraintName = (String) j.next();                String fieldName = (String) d.getFieldName(constraintName);                FieldDescriptor fd = (FieldDescriptor) cld.getFieldDescriptorByName(fieldName);                ConstraintOp fieldOp = (ConstraintOp) d.getFieldOp(constraintName);                Object fieldValue = d.getFieldValue(constraintName);                if (fd instanceof AttributeDescriptor) {                    if (savedBags.containsKey(fieldValue)                        && BagConstraint.VALID_OPS.contains(fieldOp)) {                        Collection bag = (Collection) savedBags.get(fieldValue);                        QueryHelper.addConstraint(q, fieldName, qc, fieldOp, bag);                    } else {                        QueryHelper.addConstraint(q, fieldName, qc,                                                  fieldOp, new QueryValue(fieldValue));                    }                }            }        }        return q;    }