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