Skip to content

Package: SerializationContextFactory

SerializationContextFactory

nameinstructionbranchcomplexitylinemethod
SerializationContextFactory(JsonLdContext)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
create(Object)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
create(Object, SerializationContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createForAttribute(Field, Object, SerializationContext)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createForIdentifier(Field, String, SerializationContext)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createForProperties(Field, Object, SerializationContext)
M: 4 C: 12
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
createForTypes(Field, Set, SerializationContext)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2023 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 cz.cvut.kbss.jsonld.JsonLd;
21: import cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor;
22: import cz.cvut.kbss.jsonld.serialization.context.JsonLdContext;
23:
24: import java.lang.reflect.Field;
25: import java.util.Set;
26:
27: /**
28: * Creates {@link SerializationContext}s based on attribute/field being processed.
29: */
30: public class SerializationContextFactory {
31:
32: private final JsonLdContext rootContext;
33:
34: public SerializationContextFactory(JsonLdContext rootContext) {
35: this.rootContext = rootContext;
36: }
37:
38: public <T> SerializationContext<T> create(T value) {
39: // Create root serialization context
40: return new SerializationContext<>(value, rootContext);
41: }
42:
43: public <T> SerializationContext<T> create(T value, SerializationContext<?> current) {
44: return new SerializationContext<>(value, current.getJsonLdContext());
45: }
46:
47: public <T> SerializationContext<T> createForProperties(Field field, T value, SerializationContext<?> current) {
48:• assert BeanAnnotationProcessor.isPropertiesField(field);
49:
50: return new SerializationContext<>(field, value, current.getJsonLdContext());
51: }
52:
53: public <T> SerializationContext<T> createForAttribute(Field field, T value, SerializationContext<?> current) {
54: return new SerializationContext<>(BeanAnnotationProcessor.getAttributeIdentifier(field), field, value,
55: current.getJsonLdContext());
56: }
57:
58: public SerializationContext<String> createForIdentifier(Field field, String value,
59: SerializationContext<?> current) {
60: return new SerializationContext<>(JsonLd.ID, field, value, current.getJsonLdContext());
61: }
62:
63: public SerializationContext<Set<String>> createForTypes(Field field, Set<String> value,
64: SerializationContext<?> current) {
65: return new SerializationContext<>(JsonLd.TYPE, field, value, current.getJsonLdContext());
66: }
67: }