Andy,

A follow-up question: how would you create an immutable OntModel?

    OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, modelRO);

Would the ontModel still be mutable?

On Sat, Aug 28, 2021 at 3:43 PM Andy Seaborne <a...@apache.org> wrote:
>
>
>
> On 27/08/2021 12:23, Zak Mc Kracken wrote:
> > Hi all,
> >
> > I have a little RDF file (describing a dataset metadata), which I want
> > to read in an helper class and return as a read-only view on the file.
> > The reason to return it as read-only is that I also keep a simple cache
> > of uri/Object, which is a simplified view of RDF resources in the file,
> > so a modifiable Model would make it impossible to keep the two aligned.
> >
> > That said, I wonder if there is some read-only wrapper for the Jena's
> > Model interface, something similar to Collections.unmodifiableXXX(),
> > which of course, would be based on the decorator pattern, with
> > delegation to a base Model for most of the interface methods, except
> > interceptors for addXXX(), which would throw
> > UnsupportedOperationException. Would be easy to implement it, but I
> > don't like to reinvent wheels, if something like that already exists.
>
> Apparently there isn't one. Not sure why not.
>
> There is a read-only graph (and a read-only DatasetGraph) so one way to
> create a read-only model is:
>
>          Model model = ModelFactory.createDefaultModel();
>          Graph graphRO = new GraphReadOnly(model.getGraph());
>          Model modelRO = ModelFactory.createModelForGraph(graphRO);
>
> Graph is a narrower interface do catching things here is less code.  In
> fact, GraphBase is read-only unless add/delete(Triple) are overwritten.
>
>      Andy
> >
> > Thanks,
> > Marco.
> >
> >

Reply via email to