package server; import java.util.Iterator; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import jade.core.behaviours.OneShotBehaviour; public class TraderAgentBehaviourFSM_ExecuteBehaviour extends OneShotBehaviour { int transition = 2; public void action() { TraderAgent myAgentTA = (TraderAgent)myAgent; String queryMessage = myAgentTA.getLastQuery(); System.out.println("\n The complete query is: \n" + queryMessage); Model m = myAgentTA.getMem().getModel(); Query query = QueryFactory.create(queryMessage); QueryExecution qexec = QueryExecutionFactory.create(query,m); try { ResultSet results = qexec.execSelect(); while(results.hasNext()) { QuerySolution soln = results.nextSolution(); System.out.println("\n The 'QuerySolution' is: " + soln.toString()); Iterator it = soln.varNames(); System.out.println("\n The variables contained: "); while(it.hasNext()) { String varName = (String)it.next(); System.out.println(" --> " + varName); } Literal l = soln.getLiteral("id"); System.out.println("\n Query Result: " + l.getString()); myAgentTA.setLastResult(l.getString()); } } finally{qexec.close();} } public int onEnd() { return transition; } }