private static ReasonerFactory createInstance( Resource root, Class<?> c ) { try { return (ReasonerFactory) c.newInstance(); } catch (Exception e) { throw new AssemblerException( root, "could not create instance of " + c.getName(), e ); } }
private static ReasonerFactory createInstance( Resource root, Class<?> c ) { try { return (ReasonerFactory) c.newInstance(); } catch (Exception e) { throw new AssemblerException( root, "could not create instance of " + c.getName(), e ); } }
private SecurityEvaluator getEvaluatorImpl(Assembler a, Resource evaluatorImpl ) { Object obj = a.open(a, evaluatorImpl, Mode.ANY); if (obj instanceof SecurityEvaluator) { return (SecurityEvaluator) obj; } throw new AssemblerException( evaluatorImpl, String.format( "%s does not specify a SecurityEvaluator instance", evaluatorImpl)); }
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 )); throw new AssemblerException( root, String.format( "%s (found at %s for %s) getInstance() must be a static method", factoryName, EVALUATOR_FACTORY, root )); throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e); throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e); throw new AssemblerException( root, String.format( "Class %s (found at %s for %s) could not be loaded", factoryName, EVALUATOR_FACTORY, root )); 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 )); throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e); throw new AssemblerException( root, String.format( ERROR_FINDING_FACTORY, factoryName, e.getMessage() ), e);
/** Format:: access:entry ("user1" <http://host/graphname1> <http://host/graphname2> ) ; */ private void parseList(Multimap<String, Node> map, Resource root, GNode entry) { List<Node> members = GraphList.members(entry); // string, then URIs. if ( members.isEmpty() ) throw new AssemblerException(root, "Found access:entry with an empty list"); Node userNode = members.get(0); if ( ! Util.isSimpleString(userNode) ) throw new AssemblerException(root, "User name is not a string: "+NodeFmtLib.str(userNode)); String user = userNode.getLiteralLexicalForm(); List<Node> graphs = members.subList(1, members.size()); accessEntries(root, map, user, graphs); }
private Node graphLabel(Node x, Resource root) { if ( SecurityContext.allGraphsStr.equals(x) ) x = SecurityContext.allGraphs; if ( SecurityContext.allNamedGraphsStr.equals(x) ) x = SecurityContext.allNamedGraphs; if ( ! x.isURI() ) throw new AssemblerException(root, "Not a graph name: "+x); return x; }
if (rootModel == null) throw new AssemblerException( root, String.format( NO_X_PROVIDED, BASE_MODEL, root )); if (modelName == null) throw new AssemblerException( root, String.format( NO_X_PROVIDED, JA.modelName, root )); 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 )); throw new AssemblerException( root, String.format( "May not specify both a %s and a %s for %s" , EVALUATOR_FACTORY, EVALUATOR_IMPL, root ));
@Override public Model open(Assembler a, Resource root, Mode mode) { String file = GraphUtils.getStringValue(root, HDTJenaConstants.pFileName) ; boolean loadInMemory = Boolean.parseBoolean(GraphUtils.getStringValue(root, HDTJenaConstants.pKeepInMemory)); try { // FIXME: Read more properties. Cache config? HDT hdt; if(loadInMemory) { hdt = HDTManager.loadIndexedHDT(file, null); } else { hdt = HDTManager.mapIndexedHDT(file, null); } HDTGraph graph = new HDTGraph(hdt); return ModelFactory.createModelForGraph(graph); } catch (IOException e) { log.error("Error reading HDT file: {}", file, e); throw new AssemblerException(root, "Error reading HDT file: "+file+" / "+e.toString()); } }
@Override public Object open( Assembler a, Resource root, Mode mode ) { Set <Resource>types = AssemblerHelp.findSpecificTypes( root, JA.Object ); if (types.size() == 0) { // Does it exist as a subject in the model? Mistyped? boolean noSuchSubject = ! root.listProperties().hasNext() ; if ( noSuchSubject ) { String s ; if ( root.isURIResource() ) s = "<"+root.getURI()+">" ; else if ( root.isAnon() ) s = "_:"+root.getId() ; else s = String.valueOf(root) ; throw new AssemblerException(root, "Can't find "+s+" as a subject") ; } throw new NoSpecificTypeException( root ); } else if (types.size() > 1) throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); else return openBySpecificType( a, root, mode, types.iterator().next() ); }
@Override public Object open( Assembler a, Resource root, Mode mode ) { Set <Resource>types = AssemblerHelp.findSpecificTypes( root, JA.Object ); if (types.size() == 0) { // Does it exist as a subject in the model? Mistyped? boolean noSuchSubject = ! root.listProperties().hasNext() ; if ( noSuchSubject ) { String s ; if ( root.isURIResource() ) s = "<"+root.getURI()+">" ; else if ( root.isAnon() ) s = "_:"+root.getId() ; else s = String.valueOf(root) ; throw new AssemblerException(root, "Can't find "+s+" as a subject") ; } throw new NoSpecificTypeException( root ); } else if (types.size() > 1) throw new AmbiguousSpecificTypeException( root, new ArrayList<>( types ) ); else return openBySpecificType( a, root, mode, types.iterator().next() ); }
private Object openBySpecificType( Assembler a, Resource root, Mode mode, Resource type ) { Assembler toUse = assemblerFor( type ); Class<? extends Assembler> aClass = toUse == null ? null : toUse.getClass(); Frame frame = new Frame( root, type, aClass ); try { if (toUse == null) throw new NoImplementationException( this, root, type ); else return toUse.open( a, root, mode ); } catch (AssemblerException e) { throw e.pushDoing( frame ); } catch (Exception e) { AssemblerException x = new AssemblerException( root, "caught: " + e.getMessage(), e ); throw x.pushDoing( frame ); } }
private Object openBySpecificType( Assembler a, Resource root, Mode mode, Resource type ) { Assembler toUse = assemblerFor( type ); Class<? extends Assembler> aClass = toUse == null ? null : toUse.getClass(); Frame frame = new Frame( root, type, aClass ); try { if (toUse == null) throw new NoImplementationException( this, root, type ); else return toUse.open( a, root, mode ); } catch (AssemblerException e) { throw e.pushDoing( frame ); } catch (Exception e) { AssemblerException x = new AssemblerException( root, "caught: " + e.getMessage(), e ); throw x.pushDoing( frame ); } }
public Dataset createDataset(Assembler a, Resource root, Mode mode) { // Can use ja:graph or ja:defaultGraph but not both. Resource dftGraphDesc1 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph); Resource dftGraphDesc2 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph); if ( dftGraphDesc1 != null && dftGraphDesc2 != null ) throw new AssemblerException(root, "Found both ja:graph and ja:defaultGraph"); Resource graphDesc = ( dftGraphDesc1 != null) ? dftGraphDesc1 : dftGraphDesc2 ; Model model; if ( graphDesc != null ) model = a.openModel(graphDesc); else // Assembler description did not define one. model = GraphFactory.makeDefaultModel(); Dataset ds = DatasetFactory.wrap(model); List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph); if ( ! nodes.isEmpty() ) { String x = DatasetAssemblerVocab.tDatasetOne.getLocalName(); throw new AssemblerException(root, "A "+x+" dataset can only hold a default graph, and no named graphs"); } AssemblerUtils.setContext(root, ds.getContext()); return ds; } }
/** Format:: access:entry [ :user "user2" ; :graphs (<http://host/graphname3> ) ] */ private void parseStruct(Multimap<String, Node> map, Resource root, Resource r) { if ( ! GraphUtils.exactlyOneProperty(r, VocabSecurity.pUser) ) throw new AssemblerException(root, "Expected exactly one access:user property for "+r); if ( ! GraphUtils.exactlyOneProperty(r, VocabSecurity.pGraphs) ) throw new AssemblerException(root, "Expected exactly one access:graphs property for "+r); String user = GraphUtils.getStringValue(r, VocabSecurity.pUser); r.listProperties(VocabSecurity.pGraphs).mapWith(s->s.getObject()).forEachRemaining(x->{ List<Node> graphs = new ArrayList<>(); if ( x.isURIResource() ) { //System.out.printf("S: user %s : access : %s\n", user, x.asNode()); graphs.add(x.asNode()); } else { // List? RDFList list = x.as(RDFList.class); list.iterator().forEachRemaining(rn->{ graphs.add(rn.asNode()); }); } accessEntries(root, map, user, graphs); }); }
@Override public Dataset open(Assembler a, Resource root, Mode mode) { if ( ! GraphUtils.exactlyOneProperty(root, VocabSecurity.pSecurityRegistry) ) throw new AssemblerException(root, "Expected exactly one access:registry property"); if ( ! GraphUtils.exactlyOneProperty(root, VocabSecurity.pDataset) ) throw new AssemblerException(root, "Expected exactly one access:dataset property"); RDFNode rnRegistry = root.getProperty(VocabSecurity.pSecurityRegistry).getObject(); RDFNode rnDataset = root.getProperty(VocabSecurity.pDataset).getObject(); AuthorizationService sr = (AuthorizationService)a.open(rnRegistry.asResource()) ; DatasetGraph dsgBase = ((Dataset)a.open(rnDataset.asResource())).asDatasetGraph(); DatasetGraph dsg = new DatasetGraphAccessControl(dsgBase, sr); // Add marker // ds.getContext().set(DataAccessCtl.symControlledAccess, true); // Add security registry : if this dataset is wrapped then this means the AuthorizationService is still accessible. // But adding to DatasetGraphAccessControl (currently) pushes it down to the wrapped base DSG. //dsg.getContext().set(DataAccessCtl.symAuthorizationService, sr); return DatasetFactory.wrap(dsg); }
throw new AssemblerException(root, "Both location and dataset given: exactly one required") ; throw new AssemblerException(root, "Must give location or refer to a dataset description") ;
private List<String> getAsMultiStringValue(Resource r, Property p) { Statement stmt = r.getProperty(p) ; if ( stmt == null ) return null ; RDFNode obj = stmt.getObject(); if ( obj.isLiteral() ) return Arrays.asList(obj.asLiteral().getLexicalForm()); if ( obj.isURIResource() ) return Arrays.asList(obj.asResource().getURI()); RDFList rdfList = obj.asResource().as( RDFList.class ); List<RDFNode> x = rdfList.asJavaList(); List<String> xs = ListUtils.toList(x.stream().map(n->{ if ( n.isLiteral() ) return n.asLiteral().getLexicalForm(); if ( n.isURIResource() ) return n.asResource().getURI(); throw new AssemblerException(r, "Not a string or URI: "+n); })); return xs; }
throw new AssemblerException(root, "Both location and dataset given: exactly one required") ; throw new AssemblerException(root, "Must give location or refer to a dataset description") ;
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 = DatabaseMgr.connectDatasetGraph(loc) ; if ( root.hasProperty(pUnionDefaultGraph) ) { Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode() ; NodeValue nv = NodeValue.makeNode(b) ; if ( nv.isBoolean() ) dsg.getContext().set(TDB2.symUnionDefaultGraph, nv.getBoolean()) ; else Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b) ; } /* <r> rdf:type tdb:DatasetTDB2 ; 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) ; }
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) ; }