Search in sources :

Example 1 with TypeNotUniqueException

use of org.apache.jena.sparql.util.TypeNotUniqueException in project jena by apache.

the class ExTDB3 method main.

public static void main(String... argv) {
    String assemblerFile = "Store/tdb-assembler.ttl";
    // Find a particular description in the file where there are several: 
    Model spec = RDFDataMgr.loadModel(assemblerFile);
    // Find the right starting point for the description in some way.
    Resource root = null;
    if (false)
        // If you know the Resource URI:
        root = spec.createResource("http://example/myChoiceOfURI");
    else {
        // Alternatively, look for the a single resource of the right type. 
        try {
            // Find the required description - the file can contain descriptions of many different types.
            root = GraphUtils.findRootByType(spec, VocabTDB.tDatasetTDB);
            if (root == null)
                throw new JenaException("Failed to find a suitable root");
        } catch (TypeNotUniqueException ex) {
            throw new JenaException("Multiple types for: " + DatasetAssemblerVocab.tDataset);
        }
    }
    Dataset ds = (Dataset) Assembler.general.open(root);
}
Also used : JenaException(org.apache.jena.shared.JenaException) TypeNotUniqueException(org.apache.jena.sparql.util.TypeNotUniqueException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource)

Example 2 with TypeNotUniqueException

use of org.apache.jena.sparql.util.TypeNotUniqueException in project jena by apache.

the class ExTDB3 method main.

public static void main(String... argv) {
    String assemblerFile = "Store/tdb-assembler.ttl";
    // Find a particular description in the file where there are several:
    Model spec = RDFDataMgr.loadModel(assemblerFile);
    // Find the right starting point for the description in some way.
    Resource root = null;
    if (false)
        // If you know the Resource URI:
        root = spec.createResource("http://example/myChoiceOfURI");
    else {
        // Alternatively, look for the a single resource of the right type.
        try {
            // Find the required description - the file can contain descriptions of many different types.
            root = GraphUtils.findRootByType(spec, VocabTDB.tDatasetTDB);
            if (root == null)
                throw new JenaException("Failed to find a suitable root");
        } catch (TypeNotUniqueException ex) {
            throw new JenaException("Multiple types for: " + DatasetAssemblerVocab.tDataset);
        }
    }
    Dataset ds = (Dataset) Assembler.general.open(root);
}
Also used : JenaException(org.apache.jena.shared.JenaException) TypeNotUniqueException(org.apache.jena.sparql.util.TypeNotUniqueException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource)

Example 3 with TypeNotUniqueException

use of org.apache.jena.sparql.util.TypeNotUniqueException in project jena by apache.

the class GraphUtils method getResourceByType.

public static Resource getResourceByType(Model model, Resource type) {
    ResIterator sIter = model.listSubjectsWithProperty(RDF.type, type);
    if (!sIter.hasNext())
        return null;
    Resource r = sIter.next();
    if (sIter.hasNext())
        throw new TypeNotUniqueException(r);
    return r;
}
Also used : TypeNotUniqueException(org.apache.jena.sparql.util.TypeNotUniqueException)

Aggregations

TypeNotUniqueException (org.apache.jena.sparql.util.TypeNotUniqueException)3 Dataset (org.apache.jena.query.Dataset)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 JenaException (org.apache.jena.shared.JenaException)2