Skip to content

Package: InstanceVisitor

InstanceVisitor

Coverage

1: /**
2: * Copyright (C) 2017 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.jsonld.serialization.traversal;
16:
17: import java.lang.reflect.Field;
18: import java.util.Collection;
19:
20: /**
21: * Visitor for the object graph traversal.
22: */
23: public interface InstanceVisitor {
24:
25: /**
26: * Called when a new instance is discovered by the object graph traverser.
27: * <p>
28: * The instances attributes will be processed immediately after this method returns.
29: *
30: * @param instance The visited instance
31: */
32: void openInstance(Object instance);
33:
34: /**
35: * Called when the graph traverser is done with traversing the specified instance.
36: *
37: * @param instance The visited instance
38: * @see #openInstance(Object)
39: */
40: void closeInstance(Object instance);
41:
42: /**
43: * Called when an already known instance is encountered again by the object graph traverser.
44: *
45: * @param instance The instance
46: */
47: void visitKnownInstance(Object instance);
48:
49: /**
50: * Called when the object graph traverser discovers a JSON-LD-serializable field in an instance.
51: *
52: * @param field The visited field
53: * @param value Value of the visited field
54: */
55: void visitField(Field field, Object value);
56:
57: /**
58: * Called when a collection is encountered by the object traverser.
59: * <p>
60: * This can be either when a top-level collection is discovered, or when an object's attribute is a collection.
61: *
62: * @param collection The visited collection
63: */
64: void openCollection(Collection<?> collection);
65:
66: /**
67: * Called after the last collection item is processed.
68: *
69: * @param collection The visited collection
70: * @see #openCollection(Collection)
71: */
72: void closeCollection(Collection<?> collection);
73: }