Package spark.api.exception

Examples of spark.api.exception.SparqlException


   
    XMLStreamReader rdr;
    try {
      rdr = xmlStreamFactory.createXMLStreamReader(stream, "UTF-8");
    } catch (XMLStreamException e) {
      throw new SparqlException("Unable to open XML data", e);
    }
    List<String> cols = new ArrayList<String>();
    List<String> md = new ArrayList<String>();

    try {
      if (rdr.nextTag() != START_ELEMENT || !nameIs(rdr, SPARQL)) {
        throw new SparqlException("Result is not a SPARQL XML result document");
      }
     
      // Initialize the base URI to the
      String base = null;
      if (cmd != null) {
        base = ((ProtocolDataSource)cmd.getConnection().getDataSource()).getUrl().toString();
      }
     
      // read the header information
      parseHeader(base, rdr, cols, md);
     
      // move the cursor into the results, and read in the first row
      if (rdr.nextTag() != START_ELEMENT) throw new SparqlException("No body to result document");
     
      String typeName = rdr.getLocalName();
      if (typeName.equalsIgnoreCase(RESULTS.toString())) {
        if (type != null && type != ResultType.SELECT) {
          throw new SparqlException("Unexpected result type; expected " + type + " but found SELECT.");
        }
        return new XMLSelectResults(cmd, rdr, cols, md);
      }
      if (typeName.equalsIgnoreCase(BOOLEAN.toString())) {
        if (type != null && type != ResultType.ASK) {
          throw new SparqlException("Unexpected result type; expected " + type + " but found ASK.");
        }
        if (!cols.isEmpty()) {
          logger.warn("Boolean result contained column definitions in head: {}", cols);
        }
        return parseBooleanResult(cmd, rdr, md);
      }

      throw new SparqlException("Unknown element type in result document. Expected <results> or <boolean> but got <" + typeName + ">");
    } catch (XMLStreamException e) {
      throw new SparqlException("Error reading the XML stream", e);
    }
  }
View Full Code Here


   * @return The parsed result.
   */
  static private Result parseBooleanResult(Command cmd, XMLStreamReader rdr,
      List<String> metadata) throws XMLStreamException, SparqlException {
    if (rdr.next() != CHARACTERS) {
      throw new SparqlException("Unexpected data in Boolean result: " + rdr.getEventType());
    }
    boolean result = Boolean.parseBoolean(rdr.getText());
    testClose(rdr, rdr.nextTag(), BOOLEAN, "Bad close of boolean element");
    cleanup(rdr);
    return new ProtocolBooleanResult(cmd, result, metadata);
View Full Code Here

    boolean endedVars = false;
    int eventType;
    while ((eventType = rdr.nextTag()) != END_ELEMENT || !nameIs(rdr, HEAD)) {
      if (eventType == START_ELEMENT) {
        if (nameIs(rdr, VARIABLE)) {
          if (endedVars) throw new SparqlException("Encountered a variable after header metadata");
          String var = rdr.getAttributeValue(null, "name");
          if (var != null) cols.add(var);
          else logger.warn("<variable> element without 'name' attribute");
        } else if (nameIs(rdr, LINK)) {
          String b = getBase(base, rdr); // Copy to a new var since we're looping.
View Full Code Here

   * @param elt The element name.
   * @param message The message to use in case of error.
   * @throws SparqlException Thrown if the type is not a START_ELEMENT or the name is not the required name.
   */
  static final void testOpen(XMLStreamReader rdr, int type, Element elt, String message) throws SparqlException {
    if (type != START_ELEMENT || !nameIs(rdr, elt)) throw new SparqlException(message);
  }
View Full Code Here

   * @param elt The element name.
   * @param message The message to use in case of error.
   * @throws SparqlException Thrown if the type is not an END_ELEMENT or the name is not the required name.
   */
  static final void testClose(XMLStreamReader rdr, int type, Element elt, String message) throws SparqlException {
    if (type != END_ELEMENT || !nameIs(rdr, elt)) throw new SparqlException(message);
  }
View Full Code Here

  public Result parse(Command cmd, InputStream input, ResultType type) throws SparqlException {
    BufferedReader br = null;
    try {
      // Expected type should already be validated by ResultFactory, check anyways.
      if (type != null && type != ResultType.ASK) {
        throw new SparqlException("Unexpected result type; expected " + type + " but found ASK.");
      }
     
      char[] buf = new char[BUFFER_LEN];
     
      // TODO: Find the actual encoding from the server response, if available.
      br = new BufferedReader(new InputStreamReader(input, UTF8));
      int len = fill(buf, br);
     
      String s = new String(buf, 0, len).trim();
      logger.debug("Read '{}' from text/html ASK result", s);
     
      boolean result;
      if (s.equalsIgnoreCase("true")) {
        result = true;
      } else if (s.equalsIgnoreCase("false")) {
        result = false;
      } else {
        logger.warn("Unexpected boolean value read from text/html ASK result: '{}'", s);
        result = false;
      }
     
      if (logger.isWarnEnabled() && br.read() >= 0) {
        logger.warn("Unexpected input found after boolean value");
      }
     
      return new BooleanResultImpl(cmd, result);
    } catch (IOException e) {
      throw new SparqlException("Error reading from server input", e);
    } finally {
      try {
        if (br != null) br.close();
        else input.close();
      } catch (IOException e) {
View Full Code Here

    if(value == null) {
      return null;
    } else if(value instanceof NamedNode) {
      return (NamedNode) value;
    } else {
      throw new SparqlException("Node for variable " + variable + " contains a " + value.getClass().getName() + ", not a NamedNode.");
    }
  }
View Full Code Here

    if(value == null) {
      return null;
    } else if(value instanceof BlankNode) {
      return (BlankNode) value;
    } else {
      throw new SparqlException("Node for variable " + variable + " contains a " + value.getClass().getName() + ", not a BlankNode.");
    }
  }
View Full Code Here

    if(value == null) {
      return null;
    } else if(value instanceof Literal) {
      return (Literal) value;
    } else {
      throw new SparqlException("Node for variable " + variable + " contains a " + value.getClass().getName() + ", not a Literal.");
    }
  }
View Full Code Here

    try {
      server = new SaslSocketServer(this, new InetSocketAddress((InetAddress)null, 0));
      server.start();
    } catch(IOException e) {
      throw new SparqlException("Error starting server.");
    }
  }
View Full Code Here

TOP

Related Classes of spark.api.exception.SparqlException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.