Skip to content

Package: PropertyAttributes$NonPropertyAttributes

PropertyAttributes$NonPropertyAttributes

nameinstructionbranchcomplexitylinemethod
PropertyAttributes.NonPropertyAttributes(FieldMappingValidator)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isKnownOwlProperty()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
resolve(Field, MetamodelBuilder, Class)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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.jopa.model.metamodel;
16:
17: import cz.cvut.kbss.jopa.model.IRI;
18: import cz.cvut.kbss.jopa.model.MultilingualString;
19: import cz.cvut.kbss.jopa.model.annotations.*;
20:
21: import java.lang.reflect.Field;
22:
23: abstract class PropertyAttributes {
24:
25: final FieldMappingValidator validator;
26:
27: TypeBuilderContext<?> typeBuilderContext;
28:
29: Type<?> type = null;
30: Attribute.PersistentAttributeType persistentAttributeType = null;
31: IRI iri = null;
32: CascadeType[] cascadeTypes = new CascadeType[]{};
33: FetchType fetchType = FetchType.EAGER;
34: boolean lexicalForm = false;
35: boolean simpleLiteral = false;
36: String datatype = "";
37: String language;
38: private boolean nonEmpty = false;
39: private ParticipationConstraint[] participationConstraints = new ParticipationConstraint[]{};
40:
41: PropertyAttributes(FieldMappingValidator validator) {
42: this.validator = validator;
43: }
44:
45: Type<?> getType() {
46: return type;
47: }
48:
49: Attribute.PersistentAttributeType getPersistentAttributeType() {
50: return persistentAttributeType;
51: }
52:
53: IRI getIri() {
54: return iri;
55: }
56:
57: CascadeType[] getCascadeTypes() {
58: return cascadeTypes;
59: }
60:
61: FetchType getFetchType() {
62: return fetchType;
63: }
64:
65: boolean isKnownOwlProperty() {
66: return true;
67: }
68:
69: boolean isNonEmpty() {
70: return nonEmpty;
71: }
72:
73: boolean isLexicalForm() {
74: return lexicalForm;
75: }
76:
77: boolean isSimpleLiteral() {
78: return simpleLiteral;
79: }
80:
81: public String getDatatype() {
82: return datatype;
83: }
84:
85: public boolean hasDatatype() {
86: return !datatype.isEmpty();
87: }
88:
89: String getLanguage() {
90: return language;
91: }
92:
93: ParticipationConstraint[] getParticipationConstraints() {
94: return participationConstraints;
95: }
96:
97: void resolve(Field field, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
98: resolveParticipationConstraints(field);
99: }
100:
101: String resolveLanguage(Class<?> fieldValueCls) {
102: return MultilingualString.class.equals(fieldValueCls) ? null : typeBuilderContext.getPuLanguage();
103: }
104:
105: private void resolveParticipationConstraints(Field field) {
106: ParticipationConstraints cons = field.getAnnotation(ParticipationConstraints.class);
107: if (cons != null) {
108: if (cons.value().length > 0) {
109: this.participationConstraints = cons.value();
110: } else {
111: this.nonEmpty = cons.nonEmpty();
112: }
113: }
114: }
115:
116: static PropertyAttributes create(Field field, FieldMappingValidator validator, TypeBuilderContext<?> context) {
117: final PropertyAttributes instance;
118: if (field.getAnnotation(OWLObjectProperty.class) != null) {
119: instance = new ObjectPropertyAttributes(validator);
120: } else if (field.getAnnotation(OWLDataProperty.class) != null) {
121: instance = new DataPropertyAttributes(validator);
122: } else if (field.getAnnotation(OWLAnnotationProperty.class) != null) {
123: instance = new AnnotationPropertyAttributes(validator);
124: } else {
125: instance = new NonPropertyAttributes(validator);
126: }
127: instance.typeBuilderContext = context;
128: return instance;
129: }
130:
131: private static class NonPropertyAttributes extends PropertyAttributes {
132:
133: NonPropertyAttributes(FieldMappingValidator validator) {
134: super(validator);
135: }
136:
137: @Override
138: boolean isKnownOwlProperty() {
139: return false;
140: }
141:
142: @Override
143: void resolve(Field field, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
144: // do nothing
145: }
146: }
147: }