package edu.stanford.prpl.junction.api.sample.datalog;

import java.net.URL;

import edu.stanford.prpl.junction.api.JunctionAPI;
import edu.stanford.prpl.junction.api.object.OutboundObjectStream;
import edu.stanford.prpl.junction.api.query.JunctionQuery;
import edu.stanford.prpl.junction.api.query.JunctionQueryHandler;
import edu.stanford.prpl.junction.impl.JunctionManager;
import edu.stanford.prpl.junction.impl.JunctionManagerFactory;

public class DatalogActor {
	// JunctionManager extends/implements JunctionAPI
	
	
	public static void main(String[] argv) {
		try {
			JunctionAPI jm = new JunctionManagerFactory().create(new URL("http://your.com/mine"));
		
			jm.registerQueryHandler(
				  	
			  new JunctionQueryHandler() {
  
				  public boolean supportsQuery(JunctionQuery query) {
				  	return true; //return DatalogStoredQuery.supports(query);
				  }
				  
				  public void handleQuery(JunctionQuery query, OutboundObjectStream results) {
						// query text:
						  /*
						if (!(query instanceof StoredQuery)) {
							results.close(); // todo: set error message
							return;
						}
						*/
						String queryText = query.getQueryText();
						
						// get results
						// when result comes in:
						//results.write(jsonObject.getBytes());
						
						// no more results
						results.close();
				  }
			  }
			  );
		
		} catch (Exception e) {
			System.err.println("fail.");
			e.printStackTrace();
		}
	}
	
	
}

@@ -802,23 +802,60 @@
 %09  %09
+//
 return 
-true; //
+DatalogStoredQuery.supports(query);%0A%09%09%09%09%09  
 retu
@@ -856,38 +856,32 @@
   return Datalog
-Stored
 Query.supports(q

call through to Datalogquery to see if query is supported