*/
@SuppressWarnings("unchecked")
protected <T extends StateObject> List<T> buildStateObjects(CharSequence jpqlFragment,
String queryBNFId) {
VirtualJPQLQueryBNF queryBNF = new VirtualJPQLQueryBNF(getGrammar());
queryBNF.setHandleCollection(true);
queryBNF.setFallbackBNFId(queryBNFId);
queryBNF.registerQueryBNF(queryBNFId);
final List<StateObject> items = new ArrayList<StateObject>();
try {
StateObject stateObject = buildStateObject(jpqlFragment, queryBNF.getId());
StateObjectVisitor visitor = new AnonymousStateObjectVisitor() {
@SuppressWarnings("unused")
public void visit(CollectionExpressionStateObject stateObject) {
CollectionTools.addAll(items, stateObject.children());
}
@Override
protected void visit(StateObject stateObject) {
items.add(stateObject);
}
};
stateObject.accept(visitor);
}
finally {
queryBNF.dispose();
}
return (List<T>) items;
}