Skip to content

Method: updateReferencedList(ReferencedListValueDescriptor)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.owlapi.list;
19:
20: import cz.cvut.kbss.ontodriver.Lists;
21: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
22: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
23: import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor;
24: import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor;
25: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
26: import cz.cvut.kbss.ontodriver.model.Axiom;
27: import cz.cvut.kbss.ontodriver.model.NamedResource;
28: import cz.cvut.kbss.ontodriver.owlapi.OwlapiAdapter;
29: import cz.cvut.kbss.ontodriver.owlapi.exception.OwlapiDriverException;
30: import cz.cvut.kbss.ontodriver.owlapi.util.Procedure;
31:
32: import java.util.List;
33: import java.util.Objects;
34:
35: /**
36: * Public access point the simple and referenced list handling in the OWLAPI driver.
37: */
38: public class OwlapiLists implements Lists {
39:
40: private final OwlapiAdapter adapter;
41:
42: private final Procedure beforeCallback;
43: private final Procedure afterChangeCallback;
44:
45: public OwlapiLists(OwlapiAdapter adapter, Procedure beforeCallback, Procedure afterChangeCallback) {
46: this.adapter = adapter;
47: this.beforeCallback = beforeCallback;
48: this.afterChangeCallback = afterChangeCallback;
49: }
50:
51: @Override
52: public List<Axiom<NamedResource>> loadSimpleList(SimpleListDescriptor descriptor) throws OntoDriverException {
53: ensureStateAndArgumentValid(descriptor);
54: return adapter.getSimpleListHandler().loadList(descriptor);
55: }
56:
57: private void ensureStateAndArgumentValid(Object argument) throws OwlapiDriverException {
58: beforeCallback.execute();
59: Objects.requireNonNull(argument);
60: }
61:
62: @Override
63: public void persistSimpleList(SimpleListValueDescriptor descriptor) throws OntoDriverException {
64: ensureStateAndArgumentValid(descriptor);
65: adapter.getSimpleListHandler().persistList(descriptor);
66: afterChangeCallback.execute();
67: }
68:
69: @Override
70: public void updateSimpleList(SimpleListValueDescriptor descriptor) throws OntoDriverException {
71: ensureStateAndArgumentValid(descriptor);
72: adapter.getSimpleListHandler().updateList(descriptor);
73: afterChangeCallback.execute();
74: }
75:
76: @Override
77: public List<Axiom<?>> loadReferencedList(ReferencedListDescriptor descriptor)
78: throws OntoDriverException {
79: ensureStateAndArgumentValid(descriptor);
80: return adapter.getReferencedListHandler().loadList(descriptor);
81: }
82:
83: @Override
84: public <V> void persistReferencedList(ReferencedListValueDescriptor<V> descriptor) throws OntoDriverException {
85: ensureStateAndArgumentValid(descriptor);
86: adapter.getReferencedListHandler().persistList(descriptor);
87: afterChangeCallback.execute();
88: }
89:
90: @Override
91: public <V> void updateReferencedList(ReferencedListValueDescriptor<V> descriptor) throws OntoDriverException {
92: ensureStateAndArgumentValid(descriptor);
93: adapter.getReferencedListHandler().updateList(descriptor);
94: afterChangeCallback.execute();
95: }
96: }