use of org.apache.jena.assembler.exceptions.AssemblerException in project jena by apache.
the class TestAssemblerGroupTracing method testFail.
public void testFail() {
Resource root = resourceInModel("x rdf:type A");
AssemblerGroup g = AssemblerGroup.create();
g.implementWith(resource("A"), new ShantAssemble());
try {
g.open(root);
fail("shouldn't get past exception");
} catch (AssemblerException e) {
AssemblerGroup.Frame frame = new AssemblerGroup.Frame(resource("x"), resource("A"), ShantAssemble.class);
assertEquals(listOfOne(frame), e.getDoing());
}
}
use of org.apache.jena.assembler.exceptions.AssemblerException in project jena by apache.
the class TestTDBAssembler method createGraphEmbed.
@Test
public void createGraphEmbed() {
String f = dirAssem + "/tdb-graph-embed.ttl";
Object thing = null;
try {
thing = AssemblerUtils.build(f, JA.Model);
} catch (AssemblerException e) {
e.getCause().printStackTrace(System.err);
throw e;
}
assertTrue(thing instanceof Model);
Graph graph = ((Model) thing).getGraph();
assertTrue(graph instanceof GraphTDB);
DatasetGraphTDB ds = ((GraphTDB) graph).getDatasetGraphTDB();
if (ds != null)
ds.close();
}
use of org.apache.jena.assembler.exceptions.AssemblerException in project jena by apache.
the class DatasetAssemblerTDB method make.
static Dataset make(Resource root) {
if (!exactlyOneProperty(root, pLocation))
throw new AssemblerException(root, "No location given");
String dir = getStringValue(root, pLocation);
Location loc = Location.create(dir);
DatasetGraph dsg = TDBFactory.createDatasetGraph(loc);
if (root.hasProperty(pUnionDefaultGraph)) {
Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode();
NodeValue nv = NodeValue.makeNode(b);
if (nv.isBoolean())
dsg.getContext().set(TDB.symUnionDefaultGraph, nv.getBoolean());
else
Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b);
}
/*
<r> rdf:type tdb:DatasetTDB ;
tdb:location "dir" ;
//ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "10000" ] ;
tdb:unionGraph true ; # or "true"
*/
AssemblerUtils.setContext(root, dsg.getContext());
return DatasetFactory.wrap(dsg);
}
use of org.apache.jena.assembler.exceptions.AssemblerException in project jena by apache.
the class SecuredAssembler method open.
@Override
public Model open(Assembler a, Resource root, Mode mode) {
Resource rootModel = getUniqueResource(root, BASE_MODEL);
if (rootModel == null) {
throw new AssemblerException(root, String.format(NO_X_PROVIDED, BASE_MODEL, root));
}
Model baseModel = a.openModel(rootModel, Mode.ANY);
Literal modelName = getUniqueLiteral(root, JA.modelName);
if (modelName == null) {
throw new AssemblerException(root, String.format(NO_X_PROVIDED, JA.modelName, root));
}
Literal factoryName = getUniqueLiteral(root, EVALUATOR_FACTORY);
Resource evaluatorImpl = getUniqueResource(root, EVALUATOR_IMPL);
if (factoryName == null && evaluatorImpl == null) {
throw new AssemblerException(root, String.format("Either a %s or a %s must be provided for %s", EVALUATOR_FACTORY, EVALUATOR_IMPL, root));
}
if (factoryName != null && evaluatorImpl != null) {
throw new AssemblerException(root, String.format("May not specify both a %s and a %s for %s", EVALUATOR_FACTORY, EVALUATOR_IMPL, root));
}
SecurityEvaluator securityEvaluator = null;
if (factoryName != null) {
securityEvaluator = executeEvaluatorFactory(root, factoryName);
}
if (evaluatorImpl != null) {
securityEvaluator = getEvaluatorImpl(a, evaluatorImpl);
}
return Factory.getInstance(securityEvaluator, modelName.asLiteral().getString(), baseModel);
}
use of org.apache.jena.assembler.exceptions.AssemblerException in project jena by apache.
the class SecuredAssembler method executeEvaluatorFactory.
private SecurityEvaluator executeEvaluatorFactory(Resource root, Literal factoryName) {
try {
Class<?> factoryClass = Class.forName(factoryName.getString());
Method method = factoryClass.getMethod("getInstance");
if (!SecurityEvaluator.class.isAssignableFrom(method.getReturnType())) {
throw new AssemblerException(root, String.format("%s (found at %s for %s) getInstance() must return an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root));
}
if (!Modifier.isStatic(method.getModifiers())) {
throw new AssemblerException(root, String.format("%s (found at %s for %s) getInstance() must be a static method", factoryName, EVALUATOR_FACTORY, root));
}
return (SecurityEvaluator) method.invoke(null);
} catch (SecurityException e) {
throw new AssemblerException(root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e);
} catch (IllegalArgumentException e) {
throw new AssemblerException(root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e);
} catch (ClassNotFoundException e) {
throw new AssemblerException(root, String.format("Class %s (found at %s for %s) could not be loaded", factoryName, EVALUATOR_FACTORY, root));
} catch (NoSuchMethodException e) {
throw new AssemblerException(root, String.format("%s (found at %s for %s) must implement a static getInstance() that returns an instance of SecurityEvaluator", factoryName, EVALUATOR_FACTORY, root));
} catch (IllegalAccessException e) {
throw new AssemblerException(root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e);
} catch (InvocationTargetException e) {
throw new AssemblerException(root, String.format(ERROR_FINDING_FACTORY, factoryName, e.getMessage()), e);
}
}
Aggregations