org.apache.jena.sparql.ARQInternalErrorException Java Examples

The following examples show how to use org.apache.jena.sparql.ARQInternalErrorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TokenizerText.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
private void processPLX(int ch)
{
    if ( ch == CH_PERCENT )
    {
        stringBuilder.append((char)ch);

        ch = reader.peekChar();
        if ( ! isHexChar(ch) )
            error("Not a hex character: '%c'",ch);
        stringBuilder.append((char)ch);
        reader.readChar();

        ch = reader.peekChar();
        if ( ! isHexChar(ch) )
            error("Not a hex character: '%c'",ch);
        stringBuilder.append((char)ch);
        reader.readChar();
    }
    else if ( ch == CH_RSLASH )
    {
        ch = readCharEscape();
        stringBuilder.append((char)ch);
    }
    else
        throw new ARQInternalErrorException("Not a '\\' or a '%' character");
}
 
Example #2
Source File: FUN_Property.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    if (args == null) {
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    }
    if (args.size() != 2) {
        throw new ExprEvalException("Expecting two argument");
    }
    NodeValue file = args.get(0).eval(binding, env);
    NodeValue propertyNode = args.get(1).eval(binding, env);
    if (!propertyNode.isString()) {
        throw new ExprEvalException("Second argument must be a string. Got " + propertyNode);
    }
    Properties properties;
    try {
        properties = getProperties(file, env);
    } catch (IOException ex) {
        throw new ExprEvalException("IOException while extracting properties document " + file, ex);
    }
    String prop = properties.getProperty(propertyNode.getString());
    if (prop == null) {
        throw new ExprEvalException("Property " + prop + " not found in properties document " + file);
    }
    return new NodeValueString(prop);
}
 
Example #3
Source File: ST_Incr.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    if (args == null) {
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    }
    if (args.size() != 0) {
        throw new ExprEvalException("Expecting zero argument");
    }
    IndentedWriter writer = ContextUtils.getTemplateOutput(env.getContext());
    if(writer != null) {
    	writer.incIndent();
    } else {
    	LOG.warn("calling st:incr() outside TEMPLATE context.");
    }
    return EMPTY_NODE;
}
 
Example #4
Source File: ST_Decr.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    if (args == null) {
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    }
    if (args.size() != 0) {
        throw new ExprEvalException("Expecting zero argument");
    }
    IndentedWriter writer = ContextUtils.getTemplateOutput(env.getContext());
    if(writer != null) {
    	writer.decIndent();
    } else {
    	LOG.warn("calling st:decr() outside TEMPLATE context.");
    }
    return EMPTY_NODE;
}
 
Example #5
Source File: IteratorStreamFunctionBase3.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 3) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 3, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    exec(v1, v2, v3, nodeValuesStream);
}
 
Example #6
Source File: IteratorFunctionBase2.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 2) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 2, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    return exec(v1, v2);
}
 
Example #7
Source File: IteratorFunctionBase4.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 4) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 4, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    return exec(v1, v2, v3, v4);
}
 
Example #8
Source File: IteratorFunctionBase5.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 5) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 5, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    NodeValue v5 = args.get(4);
    return exec(v1, v2, v3, v4, v5);
}
 
Example #9
Source File: IteratorFunctionBase3.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 3) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 3, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    return exec(v1, v2, v3);
}
 
Example #10
Source File: IteratorStreamFunctionBase2.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 2) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 2, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    exec(v1, v2, nodeValuesStream);
}
 
Example #11
Source File: IteratorStreamFunctionBase.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public final void exec(
        final Binding binding,
        final ExprList args,
        final FunctionEnv env,
        final Consumer<List<List<NodeValue>>> collectionListNodeValue) {

    this.env = env;
    if (args == null) {
        throw new ARQInternalErrorException("IteratorFunctionBase:"
                + " Null args list");
    }

    List<NodeValue> evalArgs = new ArrayList<>();
    for (Expr e : args) {
        try {
            NodeValue x = e.eval(binding, env);
            evalArgs.add(x);
        } catch (ExprEvalException ex) {
            LOG.trace("Cannot evaluate node " + e + ": " + ex.getMessage());
            evalArgs.add(null);
        }
    }
    exec(evalArgs, collectionListNodeValue);
}
 
Example #12
Source File: IteratorStreamFunctionBase5.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    if (args.size() != 5) {
        throw new ExprEvalException(this.getClass().getName()
                + ": Wrong number of arguments: Wanted 5, got "
                + args.size());
    }
    NodeValue v1 = args.get(0);
    NodeValue v2 = args.get(1);
    NodeValue v3 = args.get(2);
    NodeValue v4 = args.get(3);
    NodeValue v5 = args.get(4);
    exec(v1, v2, v3, v4, v5, nodeValuesStream);
}
 
Example #13
Source File: ExpandPrefixedNameFunction.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
	if (args == null) {
		throw new ARQInternalErrorException("ExpandPrefixFunction: Null args list");
	}
	if (args.size() != 1) {
		throw new ExprEvalException("ExpandPrefixFunction: Wrong number of arguments: Wanted 1, got " + args.size());
	}
       return exec(args.get(0).eval(binding, env), env.getContext());
}
 
Example #14
Source File: ExpandPrefixFunction.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
	if (args == null) {
		throw new ARQInternalErrorException("ExpandPrefixFunction: Null args list");
	}
	if (args.size() != 1) {
		throw new ExprEvalException("ExpandPrefixFunction: Wrong number of arguments: Wanted 1, got " + args.size());
	}
       return exec(args.get(0).eval(binding, env), env.getContext());
}
 
Example #15
Source File: IteratorStreamFunctionBase4.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException(this.getClass().getName()
                + ": Null args list");
    }
    NodeValue v1 = args.size() >= 1 ? args.get(0) : null;
    NodeValue v2 = args.size() >= 2 ? args.get(1) : null;
    NodeValue v3 = args.size() >= 3 ? args.get(2) : null;
    NodeValue v4 = args.size() >= 4 ? args.get(3) : null;
    exec(v1, v2, v3, v4, nodeValuesStream);
}
 
Example #16
Source File: IteratorStreamFunctionBase0.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException("Null args list");
    }
    if (!args.isEmpty()) {
        throw new ExprEvalException("Wrong number of"
                + " arguments: Wanted 0, got " + args.size());
    }
    exec(nodeValuesStream);
}
 
Example #17
Source File: IteratorFunctionBase1.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException("SelectorBase1:"
                + " Null args list");
    }
    if (args.size() != 1) {
        throw new ExprEvalException("SelectorBase1: Wrong number of"
                + " arguments: Wanted 1, got " + args.size());
    }
    NodeValue v1 = args.get(0);
    return exec(v1);
}
 
Example #18
Source File: IteratorFunctionBase0.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final List<List<NodeValue>> exec(List<NodeValue> args) {
    if (args == null) {
        throw new ARQInternalErrorException("Iterator function '"
                + this.getClass().getName() + " Null args list");
    }
    if (!args.isEmpty()) {
        throw new ExprEvalException("Iterator function '"
                + this.getClass().getName() + " Wanted 0, got "
                + args.size());
    }
    return exec();
}
 
Example #19
Source File: IteratorStreamFunctionBase1.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public final void exec(List<NodeValue> args, Consumer<List<List<NodeValue>>> nodeValuesStream) {
    if (args == null) {
        throw new ARQInternalErrorException("SelectorBase1:"
                + " Null args list");
    }
    if (args.size() != 1) {
        throw new ExprEvalException("SelectorBase1: Wrong number of"
                + " arguments: Wanted 1, got " + args.size());
    }
    NodeValue v1 = args.get(0);
    exec(v1, nodeValuesStream);
}
 
Example #20
Source File: SPARQLExtFmtExprSPARQL.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ExprFunctionOp funcOp) {
	String fn = funcOp.getFunctionPrintName(context);
	if (funcOp instanceof E_NotExists) {
		fn = "NOT EXISTS";
	} else if (funcOp instanceof E_Exists) {
		fn = "EXISTS";
	} else {
		throw new ARQInternalErrorException("Unrecognized ExprFunctionOp: " + fn);
	}

	SPARQLExtFormatterElement fmtElt = new SPARQLExtFormatterElement(out, context);
	out.print(fn);
	out.print(" ");
	int indent = out.getAbsoluteIndent();
	int currentCol = out.getCol();
	try {
		out.setAbsoluteIndent(currentCol);
		Element el = funcOp.getElement();
		if (el == null) {
			el = OpAsQuery.asQuery(funcOp.getGraphPattern()).getQueryPattern();
		}
		el.visit(fmtElt);
	} finally {
		out.setAbsoluteIndent(indent);
	}
}
 
Example #21
Source File: ST_Format.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public NodeValue exec(Binding binding, ExprList args, String uri, FunctionEnv env) {
    final boolean isDebugStConcat = ContextUtils.isDebugStConcat(env.getContext());
    if (args == null) // The contract on the function interface is that this should not happen.
    {
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    }

    List<NodeValue> evalArgs = new ArrayList<>();
    for (Expr e : args) {
        try {
            NodeValue x = e.eval(binding, env);
            evalArgs.add(x);
        } catch (Exception ex) {
            StringWriter sw = new StringWriter();
            ex.printStackTrace(new PrintWriter(sw));
            String message = String.format("Error executing st:format with expression %s and binding %s: %s", ExprUtils.fmtSPARQL(args), LogUtils.compress(binding).toString(), sw.toString());
            if (LOG.isDebugEnabled()) {
                LOG.debug(message, ex);
            }
            if (isDebugStConcat) {
                evalArgs.add(new NodeValueString(String.format("\n<<<<<<<<<< %s >>>>>>>>>>\n", message)));
            }
        }
    }

    NodeValue nv = exec(evalArgs, env);
    return nv;
}
 
Example #22
Source File: QueryIterTripleStarPattern.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
@Override
protected Binding moveToNextBinding()
{
    if ( ! hasNextBinding() ) 
        throw new ARQInternalErrorException();

    final Binding r = slot;
    slot = null;
    return r;
}
 
Example #23
Source File: FUN_Select_Call_Template.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
/**
   *
   * @param binding
   * @param args
   * @param uri
   * @param env
   * @return
   */
  @Override
  public NodeValue exec(
          final Binding binding,
          final ExprList args,
          final String uri,
          final FunctionEnv env) {
      if (args == null) {
          throw new ARQInternalErrorException("FunctionBase: Null args list");
      }
      if (args.size() < 2) {
          throw new ExprEvalException("Expecting at least two arguments");
      }
      NodeValue selectQueryNode = null;
      if(args.get(0) != null) {
      	selectQueryNode = args.get(0).eval(binding, env);
          if (!(selectQueryNode.isLiteral() && SPARQLExt.MEDIA_TYPE_URI.equals(selectQueryNode.getDatatypeURI()))) {
              throw new ExprEvalException("First argument must be a literal with datatype " + SPARQLExt.MEDIA_TYPE_URI + ". Got: " + selectQueryNode);
          }
      }
      NodeValue templateQueryNode = args.get(1).eval(binding, env);
      if (!(templateQueryNode.isIRI())) {
          throw new ExprEvalException("Second argument must be a URI. Got: " + templateQueryNode);
      }
      ExprList callArgs = args.subList(2, args.size());

      final Context context = env.getContext();
      final QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context);

      final List<List<Node>> callParameters = new ArrayList<>();
      if(selectQueryNode != null) {
       RootPlan selectPlan = queryExecutor.getPlanFromString(selectQueryNode.asString(), null);
       List<Binding> bindings = new ArrayList<>();
       bindings.add(binding);
       ResultSet resultSet = selectPlan.execSelect(bindings, context);
       
       for(;resultSet.hasNext();) {
           Binding newBinding = resultSet.nextBinding();
           callParameters.add(EvalUtils.eval(callArgs, newBinding, env));
       }
      } else {
          callParameters.add(EvalUtils.eval(callArgs, binding, env));
      }
      String templateQueryName = templateQueryNode.asNode().getURI();
      try(ByteArrayOutputStream baos = new ByteArrayOutputStream();
      		IndentedWriter writer = new IndentedWriter(baos);) {
       Context newContext = ContextUtils.fork(context).setTemplateOutput(writer).fork();
       queryExecutor.execTemplateFromName(templateQueryName, callParameters, newContext);
       String result = new String(baos.toByteArray());
       writer.close(); // need to flush. One before the other isn't important. boas.close is the only variant that doesn't work.
       return new NodeValueString(result);
      } catch (IOException ex) {
      	throw new ExprEvalException(ex);
}

  }
 
Example #24
Source File: ST_Call_Template.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
/**
   *
   * @param binding
   * @param args
   * @param uri
   * @param env
   * @return
   */
  @Override
  public NodeValue exec(
          final Binding binding,
          final ExprList args,
          final String uri,
          final FunctionEnv env) {
      if (args == null) {
          throw new ARQInternalErrorException("FunctionBase: Null args list");
      }
      if (args.size() < 1) {
          throw new ExprEvalException("Expecting at least one argument");
      }
      NodeValue queryNode = args.get(0).eval(binding, env);
      if (!(queryNode.isIRI() || queryNode.isLiteral() && SPARQLExt.MEDIA_TYPE_URI.equals(queryNode.getDatatypeURI()))) {
          throw new ExprEvalException("Name of sub query "
                  + "should be a URI or a literal with datatype " + SPARQLExt.MEDIA_TYPE_URI + ". Got: " + queryNode);
      }
      if (queryNode.isLiteral() && args.size() > 1) {
          throw new ExprEvalException("Expecting at most one argument when first argument is a literal.");
      }

      final Context context = env.getContext();
      final QueryExecutor queryExecutor = ContextUtils.getQueryExecutor(context);
      try(ByteArrayOutputStream baos = new ByteArrayOutputStream();
      		IndentedWriter writer = new IndentedWriter(baos);) {
      	Context newContext = ContextUtils.fork(context).setTemplateOutput(writer).fork();
          if (queryNode.isIRI()) {
              String queryName = queryNode.asNode().getURI();
              List<List<Node>> callParameters = new ArrayList<>();
              callParameters.add(EvalUtils.eval(args.subList(1, args.size()), binding, env));
              queryExecutor.execTemplateFromName(queryName, callParameters, newContext);
              return new NodeValueString(new String(baos.toByteArray()));
          }
          String queryString = queryNode.asNode().getLiteralLexicalForm();
      	queryExecutor.execTemplateFromString(queryString, binding, newContext);
          String result = new String(baos.toByteArray());
       writer.close(); // need to flush. One before the other isn't important. boas.close is the only variant that doesn't work.
          return new NodeValueString(result);
      } catch (IOException ex) {
      	throw new ExprEvalException(ex);
}
  }
 
Example #25
Source File: FUN_PrefixedIRI.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param binding
 * @param args
 * @param uri
 * @param env
 * @return
 */
@Override
public NodeValue exec(
        final Binding binding,
        final ExprList args,
        final String uri,
        final FunctionEnv env) {
    if (args == null) {
        throw new ARQInternalErrorException("FunctionBase: Null args list");
    }
    if (args.size() != 1) {
        throw new ExprEvalException("Expecting one argument");
    }
    NodeValue node = args.get(0).eval(binding, env);
    if (node == null) {
        throw new ExprEvalException("The input did not resolve to a IRI: " + args.get(0));
    }
    if (!node.isIRI()) {
        LOG.debug("The input should be a IRI. Got " + node);
        throw new ExprEvalException("The input should be a IRI. Got " + node);
    }

    String longIRI = node.asNode().getURI();
    Dataset dataset = ContextUtils.getDataset(env.getContext());
    
    final Map<String, String> prefixMap = dataset.getDefaultModel().getNsPrefixMap();
    final Set<String> prefixes = prefixMap.keySet();
    String prefix = null;
    String localName = uri;
    for (String p : prefixes) {
        String ns = prefixMap.get(p);
        if (longIRI.startsWith(ns)) {
            String ln = longIRI.substring(ns.length());
            if (ln.length() <= localName.length()) {
                prefix = p;
                localName = ln;
            }
        }
    }
    if(prefix != null) {
        return new NodeValueString(prefix + ":" + localName);
    } else {
        return new NodeValueString(longIRI);
    }
}
 
Example #26
Source File: MyQueryEngine.java    From xcurator with Apache License 2.0 4 votes vote down vote up
@Override
public Plan create(Op op, DatasetGraph dataset, Binding inputBinding, Context context)
{   // Shodul notbe called because acceept/Op is false
    throw new ARQInternalErrorException("MyQueryEngine: factory calleddirectly with an algebra expression") ;
}