| 30 | import org.apache.jena.sparql.sse.SSE; |
| 31 | |
| 32 | public class ModAlgebra extends ModBase { |
| 33 | protected final ArgDecl queryFileDecl = new ArgDecl(ArgDecl.HasValue, "query", "file"); |
| 34 | |
| 35 | private String queryFilename = null; |
| 36 | private String queryString = null; |
| 37 | private Op op = null; |
| 38 | |
| 39 | @Override |
| 40 | public void registerWith(CmdGeneral cmdLine) { |
| 41 | cmdLine.getUsage().startCategory("Query"); |
| 42 | cmdLine.add(queryFileDecl, "--query, --file", "File containing an algebra query"); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void processArgs(CmdArgModule cmdLine) { |
| 47 | if ( cmdLine.contains(queryFileDecl) ) { |
| 48 | queryFilename = cmdLine.getValue(queryFileDecl); |
| 49 | queryString = IO.readWholeFileAsUTF8(queryFilename); |
| 50 | } |
| 51 | |
| 52 | if ( cmdLine.getNumPositional() == 0 && queryFilename == null ) |
| 53 | cmdLine.cmdError("No query string or query file"); |
| 54 | |
| 55 | if ( cmdLine.getNumPositional() > 1 ) |
| 56 | cmdLine.cmdError("Only one query string allowed"); |
| 57 | |
| 58 | if ( cmdLine.getNumPositional() == 1 && queryFilename != null ) |
| 59 | cmdLine.cmdError("Either query string or query file - not both"); |
| 60 | |
| 61 | if ( queryFilename == null ) { |
| 62 | String qs = cmdLine.getPositionalArg(0); |
| 63 | queryString = cmdLine.indirect(qs); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public Op getOp() { |
| 68 | if ( op != null ) |
| 69 | return op; |
| 70 | op = SSE.parseOp(queryString); |
| 71 | if ( op == null ) |
| 72 | System.err.println("Failed to parse : " + queryString); |
| 73 | return op; |
| 74 | } |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected