/** * Creates a {@link Supplier} of {@link ModelException} objects that be passed to * {@link Optional#orElseThrow(Supplier)} to generate exceptions as necessary. * * @param message * The message to be used for the exception * @return A {@link Supplier} that will create {@link ModelException} objects with the given message. */ public static Supplier<ModelException> modelException(String message) { return () -> new ModelException(message); } }
public ModelException(Value v1, Value v2) { this(buildMessage(v1, v2)); }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectLiteral(m.filter(implNode, SpinSailSchema.AXIOM_CLOSURE_NEEDED, null)).ifPresent( lit -> setAxiomClosureNeeded(lit.booleanValue())); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
@Override public void parse(Model model, Resource implNode) throws RepositoryConfigException { super.parse(model, implNode); try { Models.objectLiteral(model.filter(implNode, ProxyRepositorySchema.PROXIED_ID, null)).ifPresent( lit -> setProxiedRepositoryID(lit.getLabel())); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } } }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectResource(m.filter(implNode, DELEGATE, null)).ifPresent( delegate -> setDelegate(SailConfigUtil.parseRepositoryImpl(m, delegate))); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Creates a {@link Supplier} of {@link ModelException} objects that be passed to * {@link Optional#orElseThrow(Supplier)} to generate exceptions as necessary. * * @param message * The message to be used for the exception * @return A {@link Supplier} that will create {@link ModelException} objects with the given message. */ public static Supplier<ModelException> modelException(String message) { return () -> new ModelException(message); } }
public ModelException(Value v1, Value v2) { this(buildMessage(v1, v2)); }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectResource(m.filter(implNode, DELEGATE, null)).ifPresent( delegate -> setDelegate(SailConfigUtil.parseRepositoryImpl(m, delegate))); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Utility method that casts the return value of {@link #subjectResource()} to a IRI, or throws a * ModelException if that value is not an IRI. * * @return The subject of the matched statement(s), or {@code null} if no matching statements were found. * @throws ModelException * If such an exception is thrown by {@link #subjectResource()} or if its return value is not a * IRI. * @deprecated since 4.0. Instead, use {@link Models#subjectURI(Model)} to retrieve a subject URI, and/or * use the size of the set returned by {@link #subjects()} to verify if the subject is unique. */ @Deprecated public default Optional<IRI> subjectIRI() throws ModelException { Optional<Resource> subjectResource = subjectResource(); if (subjectResource.isPresent()) { if (subjectResource.get() instanceof IRI) { return Optional.of((IRI)subjectResource.get()); } else { throw new ModelException("Did not find a unique subject URI"); } } else { return Optional.empty(); } }
@Override public void parse(Model m, Resource implNode) throws SailConfigException { super.parse(m, implNode); try { Models.objectLiteral(m.filter(implNode, SpinSailSchema.AXIOM_CLOSURE_NEEDED, null)).ifPresent( lit -> setAxiomClosureNeeded(lit.booleanValue())); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Add an RDF statement with the predicate and object to the model, using the current subject and graph * (either named or default). * * @param predicate * the statement's predicate. * @param object * the statement's object. If the supplied object is a {@link BNode}, {@link IRI}, or * {@link Literal}, the object is used directly. If it is a prefixed name String with a known * prefix, it is mapped to an IRI. Otherwise a typed {@link Literal} is created out of the supplied * object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping * is available, the method creates a literal with the string representation of the supplied object * as the value, and {@link XMLSchema#STRING} as the datatype. Recognized types are {@link Boolean} * , {@link Byte}, {@link Double}, {@link Float}, {@link Integer}, {@link Long}, {@link Short}, * {@link XMLGregorianCalendar } , and {@link Date}. * @return this {@link ModelBuilder} * @throws ModelException * if the current subject is not set using {@link #subject(Resource)} or {@link #subject(String)}. */ public ModelBuilder add(IRI predicate, Object object) { if (currentSubject == null) { throw new ModelException("subject not set"); } return add(currentSubject, predicate, object); }
public static SailImplConfig parseRepositoryImpl(Model m, Resource implNode) throws SailConfigException { try { Optional<Literal> typeLit = Models.objectLiteral( m.filter(implNode, SailConfigSchema.SAILTYPE, null)); if (typeLit.isPresent()) { Optional<SailFactory> factory = SailRegistry.getInstance().get(typeLit.get().getLabel()); if (factory.isPresent()) { SailImplConfig implConfig = factory.get().getConfig(); implConfig.parse(m, implNode); return implConfig; } else { throw new SailConfigException("Unsupported Sail type: " + typeLit.get().getLabel()); } } return null; } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Utility method that casts the return value of {@link #subjectResource()} to a BNode, or throws a * ModelException if that value is not a BNode. * * @return The subject of the matched statement(s), or {@code null} if no matching statements were found. * @throws ModelException * If such an exception is thrown by {@link #subjectResource()} or if its return value is not a * BNode. * @deprecated since 4.0. Instead, use {@link Models#subjectBNode(Model)} to retrieve a subject BNode, * and/or use the size of the set returned by {@link #subjects()} to verify if the subject is * unique. */ @Deprecated public default Optional<BNode> subjectBNode() throws ModelException { Optional<Resource> subjectResource = subjectResource(); if (subjectResource.isPresent()) { if (subjectResource.get() instanceof BNode) { return Optional.of((BNode)subjectResource.get()); } else { throw new ModelException("Did not find a unique subject URI"); } } else { return Optional.empty(); } }
@Override public void parse(Model graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); try { Models.objectLiteral(graph.filter(implNode, EVALUATION_STRATEGY_FACTORY, null)).ifPresent( factoryClassName -> { setEvaluationStrategyFactoryClassName(factoryClassName.stringValue()); }); } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Add an RDF statement with the predicate and object to the model, using the current subject and graph * (either named or default). * * @param predicate * the statement's predicate. * @param object * the statement's object. If the supplied object is a {@link BNode}, {@link IRI}, or * {@link Literal}, the object is used directly. If it is a prefixed name String with a known * prefix, it is mapped to an IRI. Otherwise a typed {@link Literal} is created out of the supplied * object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping * is available, the method creates a literal with the string representation of the supplied object * as the value, and {@link XMLSchema#STRING} as the datatype. Recognized types are {@link Boolean} * , {@link Byte}, {@link Double}, {@link Float}, {@link Integer}, {@link Long}, {@link Short}, * {@link XMLGregorianCalendar } , and {@link Date}. * @return this {@link ModelBuilder} * @throws ModelException * if the current subject is not set using {@link #subject(Resource)} or {@link #subject(String)}. */ public ModelBuilder add(IRI predicate, Object object) { if (currentSubject == null) { throw new ModelException("subject not set"); } return add(currentSubject, predicate, object); }
public static SailImplConfig parseRepositoryImpl(Model m, Resource implNode) throws SailConfigException { try { Optional<Literal> typeLit = Models.objectLiteral( m.filter(implNode, SailConfigSchema.SAILTYPE, null)); if (typeLit.isPresent()) { Optional<SailFactory> factory = SailRegistry.getInstance().get(typeLit.get().getLabel()); if (factory.isPresent()) { SailImplConfig implConfig = factory.get().getConfig(); implConfig.parse(m, implNode); return implConfig; } else { throw new SailConfigException("Unsupported Sail type: " + typeLit.get().getLabel()); } } return null; } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Utility method that casts the return value of {@link #objectValue()} to an IRI, or throws a * ModelUtilException if that value is not an IRI. * * @return The object of the matched statement(s), or {@link Optional#empty()} if no matching statements * were found. * @throws ModelException * If such an exception is thrown by {@link #objectValue()} or if its return value is not an IRI. * @deprecated since 4.0. Instead, use {@link Models#objectURI(Model)} to retrieve an object URI value, * and/or use the size of the set returned by {@link #objects()} to verify if the object is * unique. */ @Deprecated public default Optional<IRI> objectIRI() throws ModelException { Optional<Value> objectValue = objectValue(); if (objectValue.isPresent()) { if (objectValue.get() instanceof IRI) { return Optional.of((IRI)objectValue.get()); } else { throw new ModelException("Did not find a unique object URI"); } } else { return Optional.empty(); } }
@Override public void parse(Model m, Resource implNode) throws RepositoryConfigException { super.parse(m, implNode); try { Models.objectIRI(m.filter(implNode, QUERY_ENDPOINT, null)).ifPresent( iri -> setQueryEndpointUrl(iri.stringValue())); Models.objectIRI(m.filter(implNode, UPDATE_ENDPOINT, null)).ifPresent( iri -> setUpdateEndpointUrl(iri.stringValue())); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } } }
public boolean hasNext() { try { if (stmts.hasNext()) return true; stmts.close(); return false; } catch (SailException e) { throw new ModelException(e); } }
public void parse(Model model, Resource repositoryNode) throws RepositoryConfigException { try { Models.objectLiteral(model.filter(repositoryNode, REPOSITORYID, null)).ifPresent( lit -> setID(lit.getLabel())); Models.objectLiteral(model.filter(repositoryNode, RDFS.LABEL, null)).ifPresent( lit -> setTitle(lit.getLabel())); Models.objectResource(model.filter(repositoryNode, REPOSITORYIMPL, null)).ifPresent( res -> setRepositoryImplConfig(AbstractRepositoryImplConfig.create(model, res))); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }