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