Skip to contentMethod: getItemType()
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.deserialization;
19:
20: import cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor;
21: import cz.cvut.kbss.jsonld.deserialization.util.DataTypeTransformer;
22:
23: import java.util.Collection;
24: import java.util.Map;
25: import java.util.Set;
26:
27: class TypesContext<T extends Collection<E>, E> extends InstanceContext<T> {
28:
29: private final Set<String> mappedTypes;
30: private final Class<E> elementType;
31:
32: TypesContext(T instance, Map<String, Object> knownInstances, Class<E> elementType, Class<?> ownerType) {
33: super(instance, knownInstances);
34: this.elementType = elementType;
35: this.mappedTypes = BeanAnnotationProcessor.getOwlClasses(ownerType);
36: }
37:
38: @Override
39: void addItem(Object item) {
40: assert item instanceof String;
41: if (mappedTypes.contains(item)) {
42: return;
43: }
44: if (!elementType.isAssignableFrom(item.getClass())) {
45: instance.add(DataTypeTransformer.transformValue(item, elementType));
46: } else {
47: instance.add(elementType.cast(item));
48: }
49: }
50:
51: @Override
52: Class<?> getItemType() {
53: return elementType;
54: }
55: }