Skip to content

Package: InstanceVisitor

InstanceVisitor

Coverage

1: /*
2: * JB4JSON-LD
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.jsonld.serialization.traversal;
19:
20: import java.util.Collection;
21: import java.util.Set;
22:
23: public interface InstanceVisitor {
24:
25: /**
26: * Visits an object that represents an individual, without any additional attributes.
27: *
28: * This can be an identifier-based attribute value (e.g., URI), or an enum constant mapped to an individual.
29: * @param ctx Current serialization context
30: */
31: void visitIndividual(SerializationContext<?> ctx);
32:
33: /**
34: * Visits the instance represented by the specified context.
35: * <p>
36: * Called before a new instance is open by the object graph traverser.
37: *
38: * @param ctx Current serialization context
39: * @return Whether the object should be processed or not
40: * @see #openObject(SerializationContext)
41: */
42: boolean visitObject(SerializationContext<?> ctx);
43:
44: /**
45: * Called when a new instance is discovered by the object graph traverser.
46: * <p>
47: * The instance attributes will be processed immediately after this method returns.
48: *
49: * @param ctx Current serialization context
50: */
51: void openObject(SerializationContext<?> ctx);
52:
53: /**
54: * Called when the graph traverser is done with traversing the current instance.
55: *
56: * @param ctx Current serialization context
57: * @see #openObject(SerializationContext)
58: */
59: void closeObject(SerializationContext<?> ctx);
60:
61: /**
62: * Called when an attribute is processed by the object graph traverser.
63: * <p>
64: * Note that identifiers ({@link cz.cvut.kbss.jopa.model.annotations.Id}) and types ({@link cz.cvut.kbss.jopa.model.annotations.Types})
65: * are processed separately and are not visited as attributes. Also, when processing {@link cz.cvut.kbss.jopa.model.annotations.Properties},
66: * this method is invoked for each property in the map.
67: *
68: * @param ctx Current serialization context
69: */
70: void visitAttribute(SerializationContext<?> ctx);
71:
72: /**
73: * Called when the identifier of an instance (JSON-LD {@code @id} attribute) is encountered.
74: * <p>
75: * This may be invoked out of order, at the beginning of processing an object.
76: *
77: * @param ctx Current serialization context
78: */
79: void visitIdentifier(SerializationContext<String> ctx);
80:
81: /**
82: * Called when the types of an instance (JSON-LD {@code @type} attribute) are serialized.
83: *
84: * @param ctx Current serialization context
85: */
86: void visitTypes(SerializationContext<Set<String>> ctx);
87:
88: /**
89: * Called when a collection is encountered by the object traverser.
90: * <p>
91: * This can be either when a top-level collection is discovered, or when an object's attribute is a collection.
92: *
93: * @param ctx Current serialization context
94: */
95: void openCollection(SerializationContext<? extends Collection<?>> ctx);
96:
97: /**
98: * Called after the last collection item is processed.
99: *
100: * @param ctx Current serialization context
101: * @see #openCollection(SerializationContext)
102: */
103: void closeCollection(SerializationContext<?> ctx);
104: }