Skip to content

Method: loadSimpleList(SimpleListDescriptor)

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