Search in sources :

Example 1 with AssemblerException

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());
    }
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Resource(org.apache.jena.rdf.model.Resource)

Example 2 with AssemblerException

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();
}
Also used : Graph(org.apache.jena.graph.Graph) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 3 with AssemblerException

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);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Node(org.apache.jena.graph.Node) VocabTDB.pLocation(org.apache.jena.tdb.assembler.VocabTDB.pLocation) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 4 with AssemblerException

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);
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) Model(org.apache.jena.rdf.model.Model)

Example 5 with AssemblerException

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);
    }
}
Also used : AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)8 Model (org.apache.jena.rdf.model.Model)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Graph (org.apache.jena.graph.Graph)2 Resource (org.apache.jena.rdf.model.Resource)2 VocabTDB.pLocation (org.apache.jena.tdb.assembler.VocabTDB.pLocation)2 Location (org.apache.jena.tdb.base.file.Location)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 BaseTest (org.apache.jena.atlas.junit.BaseTest)1 Node (org.apache.jena.graph.Node)1 Dataset (org.apache.jena.query.Dataset)1 Literal (org.apache.jena.rdf.model.Literal)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 NodeValue (org.apache.jena.sparql.expr.NodeValue)1 ConfigTest (org.apache.jena.tdb.ConfigTest)1 VocabTDB.pDataset (org.apache.jena.tdb.assembler.VocabTDB.pDataset)1 Test (org.junit.Test)1