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