public Dataset createDataset(Assembler a, Resource root, Mode mode) {
// Expanding version.
DatasetGraph dsg = DatasetGraphFactory.createMem() ;
AssemblerUtils.setContext(root, dsg.getContext()) ;
Dataset ds = DatasetFactory.create(dsg) ;
// -------- Default graph
// Can use ja:graph or ja:defaultGraph
Resource dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph) ;
if ( dftGraph == null )
dftGraph = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph) ;
Model dftModel = null ;
if ( dftGraph != null )
dftModel = a.openModel(dftGraph) ;
else
// Assembler description did not define one - make a dummy.
dftModel = GraphFactory.makePlainModel() ;
ds.setDefaultModel(dftModel) ;
// -------- Named graphs
List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph) ;
for (Iterator<RDFNode> iter = nodes.iterator(); iter.hasNext();) {
RDFNode n = iter.next() ;
if ( !(n instanceof Resource) )
throw new DatasetAssemblerException(root, "Not a resource: " + FmtUtils.stringForRDFNode(n)) ;
Resource r = (Resource)n ;
String gName = GraphUtils.getAsStringValue(r, DatasetAssemblerVocab.pGraphName) ;
Resource g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraph) ;
if ( g == null ) {
g = GraphUtils.getResourceValue(r, DatasetAssemblerVocab.pGraphAlt) ;
if ( g != null )
Log.warn(this, "Use of old vocabulary: use :graph not :graphData") ;
else
throw new DatasetAssemblerException(root, "no graph for: " + gName) ;
}
Model m = a.openModel(g) ;
ds.addNamedModel(gName, m) ;
}
AssemblerUtils.setContext(root, ds.getContext()) ;
return ds ;
}