/** * Return the path of the attribute at the the position index in the paths given in input without * reference to subclass. * * @param paths The paths to get from. * @param index The index of the path to get. * @return the path of the attribute at the the position index */ protected String createAttributePath(String[] paths, int index) { String partialPath = startClass.getType().getSimpleName(); String path; for (int partialPathIndex = 0; partialPathIndex <= index; partialPathIndex++) { path = paths[partialPathIndex]; if (path.contains("[")) { path = path.substring(0, path.indexOf("[")); } partialPath = partialPath + "." + path; } return partialPath; }
/** * Add a contains constraint to Query (q) built with the query class and attribute given in input * * @param query The query to add a reference to. * @param qc The class the reference belongs to. * @param attribute the name of the field of the class. * @param attributePath Another similarly named field - I wish it had been documented! * @return The query class of the attributePath. */ protected QueryClass addReference( final Query query, final QueryClass qc, String attribute, String attributePath) { ConstraintSet cs = (ConstraintSet) query.getConstraint(); QueryReference qr = null; String type = ""; boolean useSubClass = false; if (WidgetConfigUtil.isPathContainingSubClass(os.getModel(), attribute)) { useSubClass = true; type = attribute.substring(attribute.indexOf("[") + 1, attribute.indexOf("]")); attribute = attribute.substring(0, attribute.indexOf("[")); } QueryClass qcTmp = null; try { qr = new QueryObjectReference(qc, attribute); if (useSubClass) { try { qcTmp = new QueryClass(Class.forName(os.getModel().getPackageName() + "." + type)); } catch (ClassNotFoundException cnfe) { LOG.error("The type " + type + " doesn't exist in the model."); } } else { qcTmp = new QueryClass(qr.getType()); } } catch (IllegalArgumentException e) { // Not a reference - try collection instead qr = new QueryCollectionReference(qc, attribute); if (useSubClass) { try { qcTmp = new QueryClass(Class.forName(os.getModel().getPackageName() + "." + type)); } catch (ClassNotFoundException cnfe) { LOG.error("The type " + type + " doesn't exist in the model."); } } else { qcTmp = new QueryClass(TypeUtil.getElementType(qc.getType(), attribute)); } } QueryClass ret; if (!queryClassInQuery.containsKey(attributePath)) { ret = qcTmp; query.addFrom(ret); cs.addConstraint(new ContainsConstraint(qr, ConstraintOp.CONTAINS, ret)); queryClassInQuery.put(attributePath, ret); } else { ret = queryClassInQuery.get(attributePath); } return ret; }