Skip to contentMethod: JenaLists(JenaAdapter, Procedure, Procedure)
1: /**
2: * Copyright (C) 2019 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.jena.list;
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.jena.JenaAdapter;
21: import cz.cvut.kbss.ontodriver.jena.util.Procedure;
22: import cz.cvut.kbss.ontodriver.model.Axiom;
23: import cz.cvut.kbss.ontodriver.model.NamedResource;
24:
25: import java.util.List;
26: import java.util.Objects;
27:
28: public class JenaLists implements Lists {
29:
30: private final JenaAdapter adapter;
31:
32: private final Procedure beforeCallback;
33: private final Procedure afterChangeCallback;
34:
35: public JenaLists(JenaAdapter adapter, Procedure beforeCallback, Procedure afterChangeCallback) {
36: this.adapter = adapter;
37: this.beforeCallback = beforeCallback;
38: this.afterChangeCallback = afterChangeCallback;
39: }
40:
41: @Override
42: public List<Axiom<NamedResource>> loadSimpleList(SimpleListDescriptor descriptor) throws OntoDriverException {
43: executeBeforeCallbackAndVerifyArgument(descriptor);
44: Objects.requireNonNull(descriptor);
45: return adapter.simpleListHandler().loadList(descriptor);
46: }
47:
48: private void executeBeforeCallbackAndVerifyArgument(ListDescriptor descriptor) throws OntoDriverException {
49: beforeCallback.execute();
50: Objects.requireNonNull(descriptor);
51: }
52:
53: @Override
54: public void persistSimpleList(SimpleListValueDescriptor descriptor) throws OntoDriverException {
55: executeBeforeCallbackAndVerifyArgument(descriptor);
56: adapter.simpleListHandler().persistList(descriptor);
57: afterChangeCallback.execute();
58: }
59:
60: @Override
61: public void updateSimpleList(SimpleListValueDescriptor descriptor) throws OntoDriverException {
62: executeBeforeCallbackAndVerifyArgument(descriptor);
63: adapter.simpleListHandler().updateList(descriptor);
64: afterChangeCallback.execute();
65: }
66:
67: @Override
68: public List<Axiom<NamedResource>> loadReferencedList(ReferencedListDescriptor descriptor)
69: throws OntoDriverException {
70: executeBeforeCallbackAndVerifyArgument(descriptor);
71: return adapter.referencedListHandler().loadList(descriptor);
72: }
73:
74: @Override
75: public void persistReferencedList(ReferencedListValueDescriptor descriptor) throws OntoDriverException {
76: executeBeforeCallbackAndVerifyArgument(descriptor);
77: adapter.referencedListHandler().persistList(descriptor);
78: afterChangeCallback.execute();
79: }
80:
81: @Override
82: public void updateReferencedList(ReferencedListValueDescriptor descriptor) throws OntoDriverException {
83: executeBeforeCallbackAndVerifyArgument(descriptor);
84: adapter.referencedListHandler().updateList(descriptor);
85: afterChangeCallback.execute();
86: }
87: }