/*
 * Copyright (C) 2014 Fabrizio Lungo <fab@lungo.co.uk> - All Rights Reserved
 *
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 *
 * Created by Fabrizio Lungo <fab@lungo.co.uk>, October 2014
 */
package me.flungo.sparql.builder;

import me.flungo.sparql.builder.query.SPARQLQuery;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryFactory;

/**
 *
 * @author Fabrizio Lungo <fab@lungo.co.uk>
 */
public class SPARQLBuilder {

    private SPARQLPrologue prologue = null;
    private SPARQLQuery query = null;

    public void setPrologue(SPARQLPrologue prologue) {
        this.prologue = prologue;
    }

    public void setQuery(SPARQLQuery query) {
        this.query = query;
    }

    public SPARQLPrologue getPrologue() {
        return prologue;
    }

    public SPARQLQuery getQuery() {
        return query;
    }

    public Query buildQuery() {
        // Validate that a query can be produced
        if (query == null) {
            throw new IllegalStateException("No query to build");
        }
        // Create the query
        return QueryFactory.create(toString());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (prologue != null) {
            sb.append(prologue).append('\n').append('\n');
        }
        if (prologue != null) {
            sb.append(prologue).append('\n');
        }
        return sb.toString();
    }

}

@@ -301,60 +301,8 @@
 %0D%0A%0D%0A
-import me.flungo.sparql.builder.query.SPARQLQuery;%0D%0A
 impo
@@ -377,16 +377,68 @@
 actory;%0D
+%0Aimport me.flungo.sparql.builder.query.SPARQLQuery;%0D
 %0A%0D%0A/**%0D%0A
@@ -1124,32 +1124,144 @@
 %22);%0D%0A        %7D%0D%0A
+        if (!query.isValid()) %7B%0D%0A            throw new IllegalStateException(%22Query is not valid%22);%0D%0A        %7D%0D%0A
         // Creat

Check Query validity before building.