Skip to content

Package: InstanceVisitor

InstanceVisitor

Coverage

1: /**
2: * Copyright (C) 2017 Czech Technical University in Prague
3: * <p>
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: * <p>
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 id Identifier of the instance
46: * @param instance The instance
47: */
48: void visitKnownInstance(String id, Object instance);
49:
50: /**
51: * Called when the identifier of an instance (JSON-LD {@code @id} attribute) is encountered.
52: * <p>
53: * This may be invoked out of order, at the beginning of processing an object.
54: *
55: * @param identifier Instance identifier
56: * @param instance The serialized instance
57: */
58: void visitIdentifier(String identifier, Object instance);
59:
60: /**
61: * Called when the object graph traverser discovers a JSON-LD-serializable field in an instance.
62: *
63: * @param field The visited field
64: * @param value Value of the visited field
65: */
66: void visitField(Field field, Object value);
67:
68: /**
69: * Called when the types of an instance (JSON-LD {@code @type} attribute) are serialized.
70: *
71: * @param types JSON-LD types of the instance
72: * @param instance The serialized instance
73: */
74: void visitTypes(Collection<String> types, Object instance);
75:
76: /**
77: * Called when a collection is encountered by the object traverser.
78: * <p>
79: * This can be either when a top-level collection is discovered, or when an object's attribute is a collection.
80: *
81: * @param collection The visited collection
82: */
83: void openCollection(Collection<?> collection);
84:
85: /**
86: * Called after the last collection item is processed.
87: *
88: * @param collection The visited collection
89: * @see #openCollection(Collection)
90: */
91: void closeCollection(Collection<?> collection);
92: }