Skip to content

Package: PluralObjectPropertyStrategy

PluralObjectPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralObjectPropertyStrategy(EntityType, Attribute, Descriptor, EntityMappingHelper)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 38
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
buildInstanceFieldValue(Object)
M: 0 C: 10
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
createAssertion()
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%

Coverage

1: /**
2: * Copyright (C) 2016 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.jopa.oom;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.model.metamodel.Attribute;
19: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
20: import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute;
21: import cz.cvut.kbss.jopa.utils.CollectionFactory;
22: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
23: import cz.cvut.kbss.ontodriver.model.Assertion;
24: import cz.cvut.kbss.ontodriver.model.Axiom;
25: import cz.cvut.kbss.ontodriver.model.NamedResource;
26:
27: import java.util.Collection;
28:
29: abstract class PluralObjectPropertyStrategy<X> extends FieldStrategy<Attribute<? super X, ?>, X> {
30:
31: final PluralAttribute<? super X, ?, ?> pluralAtt;
32: private Collection<Object> values;
33:
34: PluralObjectPropertyStrategy(EntityType<X> et, Attribute<? super X, ?> att, Descriptor descriptor,
35: EntityMappingHelper mapper) {
36: super(et, att, descriptor, mapper);
37: this.pluralAtt = (PluralAttribute<? super X, ?, ?>) attribute;
38: this.values = CollectionFactory.createDefaultCollection(pluralAtt.getCollectionType());
39: }
40:
41: @Override
42: void addValueFromAxiom(Axiom<?> ax) {
43: final NamedResource valueIdentifier = (NamedResource) ax.getValue().getValue();
44:• if (IdentifierTransformer.isValidIdentifierType(pluralAtt.getBindableJavaType())) {
45: values.add(IdentifierTransformer
46: .transformToIdentifier(valueIdentifier.getIdentifier(), pluralAtt.getBindableJavaType()));
47: } else {
48: final Object value = mapper.getEntityFromCacheOrOntology(pluralAtt.getBindableJavaType(),
49: valueIdentifier.getIdentifier(), attributeDescriptor);
50: values.add(value);
51: }
52:
53: }
54:
55: @Override
56: void buildInstanceFieldValue(Object instance) throws IllegalAccessException {
57:• if (!values.isEmpty()) {
58: setValueOnInstance(instance, values);
59: }
60: }
61:
62: @Override
63: Assertion createAssertion() {
64: return Assertion.createObjectPropertyAssertion(pluralAtt.getIRI().toURI(),
65: attribute.isInferred());
66: }
67: }