Skip to content

Method: isClassAssertion(Axiom)

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.metamodel.EntityType;
18: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
19: import cz.cvut.kbss.ontodriver.model.Axiom;
20: import cz.cvut.kbss.ontodriver.model.Assertion.AssertionType;
21:
22: import java.lang.reflect.Field;
23:
24: final class MappingUtils {
25:
26: private MappingUtils() {
27: throw new AssertionError();
28: }
29:
30: /**
31: * Checks whether the specified axioms is a class assertion for an instance
32: * of the specified entity type. </p>
33: *
34: * @param ax Axiom
35: * @param et Entity type
36: * @return True if the axioms asserts that an individual is of type
37: * represented by the entity type
38: */
39: static boolean isEntityClassAssertion(Axiom<?> ax, EntityType<?> et) {
40: return isClassAssertion(ax) && isEntityClass(ax, et);
41: }
42:
43: /**
44: * Returns true if the specified axiom is a class assertion axiom.
45: *
46: * @param ax Axiom to check
47: * @return true if class assertion
48: */
49: static boolean isClassAssertion(Axiom<?> ax) {
50:• return ax.getAssertion().getType() == AssertionType.CLASS;
51: }
52:
53: private static boolean isEntityClass(Axiom<?> ax, EntityType<?> et) {
54: final String type = et.getIRI().toString();
55: final String val = ax.getValue().stringValue();
56: return val.equals(type);
57: }
58:
59: /**
60: * Gets field specification for the specified field.
61: * @param field Entity field
62: * @param et Entity type containing field specifications
63: * @param <T> Entity class
64: * @return Field specification (if exists)
65: */
66: static <T> FieldSpecification<? super T, ?> getFieldSpecification(Field field, EntityType<T> et) {
67: assert field != null;
68: assert et != null;
69: if (et.getTypes() != null && et.getTypes().getJavaField().equals(field)) {
70: return et.getTypes();
71: } else if (et.getProperties() != null && et.getProperties().getJavaField().equals(field)) {
72: return et.getProperties();
73: } else {
74: return et.getAttribute(field.getName());
75: }
76: }
77: }