use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class SPARQL_QueryGeneral method datasetFromDescriptionWeb.
/**
* Construct a Dataset based on a dataset description. Loads graph from the
* web.
*/
protected Dataset datasetFromDescriptionWeb(HttpAction action, DatasetDescription datasetDesc) {
try {
if (datasetDesc == null)
return null;
if (datasetDesc.isEmpty())
return null;
List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
if (graphURLs.size() == 0 && namedGraphs.size() == 0)
return null;
Dataset dataset = DatasetFactory.create();
// Look in cache for loaded graphs!!
// ---- Default graph
{
Model model = ModelFactory.createDefaultModel();
for (String uri : graphURLs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Default graph URI is null or the empty string");
try {
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
dataset.setDefaultModel(model);
}
// ---- Named graphs
if (namedGraphs != null) {
for (String uri : namedGraphs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Named graph URI is null or the empty string");
try {
Model model = ModelFactory.createDefaultModel();
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
dataset.addNamedModel(uri, model);
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
}
return dataset;
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
ServletOps.errorBadRequest("Parameter error: " + ex.getMessage());
return null;
}
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class SpatialOperationPFBase method exec.
@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
if (server == null) {
if (!warningIssued) {
Log.warn(getClass(), "No spatial index - no spatial search performed");
warningIssued = true;
}
// Not a text dataset - no-op
return IterLib.result(binding, execCxt);
}
argSubject = Substitute.substitute(argSubject, binding);
argObject = Substitute.substitute(argObject, binding);
if (!argSubject.isNode())
throw new InternalErrorException("Subject is not a node (it was earlier!)");
Node s = argSubject.getArg();
if (s.isLiteral())
// Does not match
return IterLib.noResults(execCxt);
SpatialMatch match = objectToStruct(argObject);
if (match == null) {
// can't match
return IterLib.noResults(execCxt);
}
// ----
QueryIterator qIter = (Var.isVar(s)) ? variableSubject(binding, s, match, execCxt) : concreteSubject(binding, s, match, execCxt);
if (match.getLimit() >= 0)
qIter = new QueryIterSlice(qIter, 0, match.getLimit(), execCxt);
return qIter;
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class ExprTransformNodeElement method transform.
@Override
public Expr transform(ExprFunctionOp funcOp, ExprList args, Op opArg) {
// Syntax phased only - ignore args and opArg
Element elt = funcOp.getElement();
Element elt1 = ElementTransformer.transform(elt, elementTransform, this, beforeVisitor, afterVisitor);
if (elt == elt1)
return funcOp;
else {
if (funcOp instanceof E_Exists)
return new E_Exists(elt1);
if (funcOp instanceof E_NotExists)
return new E_NotExists(elt1);
throw new InternalErrorException("Unknown ExprFunctionOp: " + funcOp.getFunctionSymbol());
}
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class TransformElementLib method applyVar.
public static Var applyVar(Var v, ExprTransform exprTransform) {
if (exprTransform == null)
return v;
ExprVar expr = new ExprVar(v);
Expr e = exprTransform.transform(expr);
if (e instanceof ExprVar)
return ((ExprVar) e).asVar();
throw new InternalErrorException("Managed to turn a variable " + v + " into " + e);
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class CmdLangParse method createAccumulateSink.
/** Create an accumulating output stream for later pretty printing */
protected Pair<StreamRDF, PostParseHandler> createAccumulateSink() {
final DatasetGraph dsg = DatasetGraphFactory.create();
StreamRDF sink = StreamRDFLib.dataset(dsg);
final RDFFormat fmt = modLangOutput.getOutputFormatted();
PostParseHandler handler = new PostParseHandler() {
@Override
public void postParse() {
// Try as dataset, then as graph.
WriterDatasetRIOTFactory w = RDFWriterRegistry.getWriterDatasetFactory(fmt);
if (w != null) {
RDFDataMgr.write(outputWrite, dsg, fmt);
return;
}
WriterGraphRIOTFactory wg = RDFWriterRegistry.getWriterGraphFactory(fmt);
if (wg != null) {
RDFDataMgr.write(System.out, dsg.getDefaultGraph(), fmt);
return;
}
throw new InternalErrorException("failed to find the writer: " + fmt);
}
};
return Pair.create(sink, handler);
}
Aggregations