Skip to content

Method: static {...}

1: /*
2: * JOPA
3: * Copyright (C) 2024 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.EntityType;
22: import cz.cvut.kbss.jopa.model.metamodel.Identifier;
23: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
24: import cz.cvut.kbss.ontodriver.model.*;
25:
26: import java.util.Collection;
27: import java.util.Collections;
28: import java.util.Set;
29:
30: class IdentifierFieldStrategy<X> extends FieldStrategy<Identifier<? super X, ?>, X> {
31:
32: IdentifierFieldStrategy(EntityType<X> et, Identifier<? super X, ?> att, Descriptor attributeDescriptor,
33: EntityMappingHelper mapper) {
34: super(et, att, attributeDescriptor, mapper);
35: }
36:
37: @Override
38: void addAxiomValue(Axiom<?> ax) {
39: // Do nothing
40: }
41:
42: @Override
43: boolean hasValue() {
44: return false;
45: }
46:
47: @Override
48: void buildInstanceFieldValue(Object instance) {
49: // Do nothing
50: }
51:
52: @Override
53: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
54: valueBuilder.addValue(createAssertion(), new Value<>(et.getIRI().toURI()), getAttributeWriteContext());
55: }
56:
57: @Override
58: Set<Axiom<?>> buildAxiomsFromInstance(X instance) {
59: return Collections.singleton(
60: new AxiomImpl<>(NamedResource.create(EntityPropertiesUtils.getIdentifier(instance, et)),
61: createAssertion(),
62: new Value<>(et.getIRI().toURI())));
63: }
64:
65: @Override
66: Collection<Value<?>> toAxiomValue(Object value) {
67: return Collections.singleton(new Value<>(et.getIRI().toURI()));
68: }
69:
70: @Override
71: Assertion createAssertion() {
72: assert !attribute.isInferred();
73: return Assertion.createClassAssertion(attribute.isInferred());
74: }
75: }