Package: DataPropertyFieldStrategy
DataPropertyFieldStrategy
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DataPropertyFieldStrategy(EntityType, AbstractAttribute, Descriptor, EntityMappingHelper) |
|
|
|
|
|
||||||||||||||||||||
canBeConverted(Object) |
|
|
|
|
|
||||||||||||||||||||
convertToAxiomValue(Object) |
|
|
|
|
|
||||||||||||||||||||
createAssertion() |
|
|
|
|
|
||||||||||||||||||||
getLanguage() |
|
|
|
|
|
||||||||||||||||||||
isValidRange(Object) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
toAttributeValue(Object) |
|
|
|
|
|
||||||||||||||||||||
toAxiomValue(Object) |
|
|
|
|
|
Coverage
1: /*
2: * JOPA
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.jopa.oom;
19:
20: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
21: import cz.cvut.kbss.jopa.model.metamodel.AbstractAttribute;
22: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
23: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
24: import cz.cvut.kbss.jopa.oom.converter.DefaultConverterWrapper;
25: import cz.cvut.kbss.ontodriver.model.Assertion;
26: import cz.cvut.kbss.ontodriver.model.Value;
27:
28: import java.util.Collection;
29: import java.util.Collections;
30:
31: abstract class DataPropertyFieldStrategy<A extends AbstractAttribute<? super X, ?>, X> extends FieldStrategy<A, X> {
32:
33: protected final ConverterWrapper<Object, Object> converter;
34:
35: DataPropertyFieldStrategy(EntityType<X> et, A att, Descriptor entityDescriptor,
36: EntityMappingHelper mapper) {
37: super(et, att, entityDescriptor, mapper);
38:• this.converter = att.getConverter() != null ? att.getConverter() : DefaultConverterWrapper.INSTANCE;
39: }
40:
41: boolean isValidRange(Object value) {
42:• return attribute.getJavaType().isAssignableFrom(value.getClass()) || canBeConverted(value);
43: }
44:
45: boolean canBeConverted(Object value) {
46: return converter.supportsAxiomValueType(value.getClass());
47: }
48:
49: Object toAttributeValue(Object value) {
50:• assert value != null;
51: return converter.convertToAttribute(value);
52: }
53:
54: Value<?> convertToAxiomValue(Object value) {
55:• assert value != null;
56: return new Value<>(converter.convertToAxiomValue(value));
57: }
58:
59: @Override
60: Collection<Value<?>> toAxiomValue(Object value) {
61:• return Collections.singleton(value != null ? convertToAxiomValue(value) : Value.nullValue());
62: }
63:
64: String getLanguage() {
65:• if (attribute.isSimpleLiteral()) {
66: return null;
67: }
68: final Descriptor attDescriptor = entityDescriptor.getAttributeDescriptor(attribute);
69:• return attDescriptor.hasLanguage() ? attDescriptor.getLanguage() : attribute.getLanguage();
70: }
71:
72: @Override
73: Assertion createAssertion() {
74: return Assertion.createDataPropertyAssertion(attribute.getIRI().toURI(), getLanguage(), attribute.isInferred());
75: }
76: }