public boolean isGraph() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); return model != null; }
public boolean isJson() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); return jsonItems != null; }
public boolean isResultSet() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); return resultSet != null; }
public boolean isDataset() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); return dataset != null; }
public boolean isBoolean() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); return booleanResult != null; }
public Boolean getBooleanResult() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isBoolean() ) throw new ResultSetException("Not a boolean result"); return booleanResult; }
public Model getModel() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isModel() ) throw new ResultSetException("Not a graph result"); return model; }
public Dataset getDataset() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isDataset() ) throw new ResultSetException("Not a dataset result"); return dataset; }
public ResultSet getResultSet() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isResultSet() ) throw new ResultSetException("Not a ResultSet result"); return resultSet; }
public Iterator<JsonObject> getJsonItems() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isJson() ) throw new ResultSetException("Not a JSON result"); return jsonItems; }
public static SPARQLResult read(Reader in, Model model, Context context) { XMLInputFactory xf = XMLInputFactory.newInstance() ; try { XMLStreamReader xReader = xf.createXMLStreamReader(in) ; return worker(xReader, model, context) ; } catch (XMLStreamException e) { throw new ResultSetException("Can't initialize StAX parsing engine", e) ; } catch (Exception ex) { throw new ResultSetException("Failed when initializing the StAX parsing engine", ex) ; } }
public static SPARQLResult read(InputStream in, Model model, Context context) { XMLInputFactory xf = XMLInputFactory.newInstance() ; try { XMLStreamReader xReader = xf.createXMLStreamReader(in) ; return worker(xReader, model, context); } catch (XMLStreamException e) { throw new ResultSetException("Can't initialize StAX parsing engine", e) ; } catch (Exception ex) { throw new ResultSetException("Failed when initializing the StAX parsing engine", ex) ; } }
private static void checkContains(JsonObject term, boolean allowUndefinedKeys, boolean requireAllExpectedKeys, String... keys) { List<String> expectedKeys = Arrays.asList(keys); Set<String> declared = new HashSet<>(); for ( String k : term.keys() ) { if ( !expectedKeys.contains(k) && !allowUndefinedKeys ) throw new ResultSetException("Expected only object keys " + Arrays.asList(keys) + " but encountered '" + k + "'"); if ( expectedKeys.contains(k) ) declared.add(k); } if ( requireAllExpectedKeys && declared.size() < expectedKeys.size() ) throw new ResultSetException("One or more of the required keys " + expectedKeys + " was not found"); } }
private void staxError(String msg, Throwable th) { Log.warn(this, "StAX error: " + msg, th) ; throw new ResultSetException(msg, th) ; } }
@Override public void read(Reader reader, String baseURI, ContentType ct, StreamRDF output, Context context) { XMLInputFactory xf = XMLInputFactory.newInstance() ; XMLStreamReader xReader ; try { xReader = xf.createXMLStreamReader(reader) ; } catch (XMLStreamException e) { throw new ResultSetException("Can't initialize StAX parsing engine", e) ; } read(xReader, baseURI, output) ; }
private static void checkLang(Lang lang) { Objects.requireNonNull(lang); if ( ! ResultSetReaderRegistry.isRegistered(lang) ) { throw new ResultSetException("Not a result set syntax: "+lang); } }
private void endElementBoolean() { endAccumulate() ; String result = buff.toString() ; if ( result.equals("true") ) { this.askResult = true ; return ; } if ( result.equalsIgnoreCase("false") ) { askResult = false ; return ; } throw new ResultSetException("Unknown boolean value: " + result) ; }
private void staxError(String msg) { Log.warn(this, "StAX error: " + msg) ; throw new ResultSetException(msg) ; }
/** Read ResultSet. * @param uri URI to read from (includes file: and a plain file name). * @param hintLang Hint for the syntax * @param context Content object to control reading process. */ public static ResultSet parse(String uri, Lang hintLang, Context context) { ResultSet rs = ResultsReader.create().lang(hintLang).context(context).read(uri); if ( rs == null ) throw new ResultSetException("Not a result set"); return rs; }
private static String stringOrNull(JsonObject obj, String key) { JsonValue v = obj.get(key); if ( v == null ) return null; if ( !v.isString() ) throw new ResultSetException("Not a string: key: " + key); return v.getAsString().value(); }