class PointOfFocusProcessor {

  public static RecommendationType process(ASTQueryContainer ast)
  throws VisitorException {
    final List<String> v = new ArrayList<String>();

    if (!(ast.getQuery() instanceof ASTSelectQuery)) { // Change to a SelectQuery
      final ASTSelectQuery selectQuery = new ASTSelectQuery(SyntaxTreeBuilderTreeConstants.JJTSELECTQUERY);
      final ASTSelect select = new ASTSelect(SyntaxTreeBuilderTreeConstants.JJTSELECT);

      selectQuery.jjtAppendChild(select);
      for (ASTDatasetClause d : ast.getQuery().getDatasetClauseList()) {
        selectQuery.jjtAppendChild(d);
      }
      selectQuery.jjtAppendChild(ast.getQuery().getWhereClause());
      if (!(ast.getQuery() instanceof ASTAskQuery)) {
        if (ast.getQuery().getGroupClause() != null) {
          selectQuery.jjtAppendChild(ast.getQuery().getGroupClause());
        }
        if (ast.getQuery().getHavingClause() != null) {
          selectQuery.jjtAppendChild(ast.getQuery().getHavingClause());
        }
        if (ast.getQuery().getOrderClause() != null) {
          selectQuery.jjtAppendChild(ast.getQuery().getOrderClause());
        }
        if (ast.getQuery().getLimit() != null) {
          selectQuery.jjtAppendChild(ast.getQuery().getLimit());
        }
        if (ast.getQuery().getOffset() != null) {
          selectQuery.jjtAppendChild(ast.getQuery().getOffset());
        }
      }
      if (ast.getQuery().getBindingsClause() != null) {
        selectQuery.jjtAppendChild(ast.getQuery().getBindingsClause());
      }
      ast.getQuery().jjtReplaceWith(selectQuery);
    }
    final ASTMaterializePointOfFocus matPOF = new ASTMaterializePointOfFocus();
    matPOF.visit(ast, v);
    final POFRecType type = new POFRecType();
    return (RecommendationType) type.visit(ast, RecommendationType.NONE);
  }

}

class TestPointOfFocusProcessor {

  private ASTQueryContainer ast;

  @Test(expected=DGSException.class)
  public void testWrongRecommendationType()
  throws Exception {

    final String q = "SELECT ?s WHERE { GRAPH ?g { < ?p ?o } }";
    ast = SyntaxTreeBuilder.parseQuery(q);
    PointOfFocusProcessor.process(ast);
  }

}