Skip to content

Method: JsonLdPropertyAccessResolver()

1: /**
2: * Copyright (C) 2022 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.common;
16:
17: import cz.cvut.kbss.jsonld.annotation.JsonLdProperty;
18:
19: import java.lang.reflect.Field;
20: import java.util.Objects;
21:
22: import static cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor.isInstanceIdentifier;
23: import static cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor.isTypesField;
24:
25: /**
26: * Resolves property access based on the {@link cz.cvut.kbss.jsonld.annotation.JsonLdProperty} annotation value.
27: */
28: public class JsonLdPropertyAccessResolver implements PropertyAccessResolver {
29:
30: @Override
31: public boolean isReadable(Field field, Class<?> objectClass) {
32: Objects.requireNonNull(field);
33: final JsonLdProperty annotation = field.getAnnotation(JsonLdProperty.class);
34: return annotation == null || annotation.access() != JsonLdProperty.Access.WRITE_ONLY ||
35: isInstanceIdentifier(field) || isTypesField(field);
36: }
37:
38: @Override
39: public boolean isWriteable(Field field) {
40: Objects.requireNonNull(field);
41: final JsonLdProperty annotation = field.getAnnotation(JsonLdProperty.class);
42: return annotation == null || annotation.access() != JsonLdProperty.Access.READ_ONLY;
43: }
44: }