Skip to content

Method: getParticipationConstraints()

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.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: Type<?> type = null;
27: Attribute.PersistentAttributeType persistentAttributeType = null;
28: IRI iri = null;
29: CascadeType[] cascadeTypes = new CascadeType[]{};
30: FetchType fetchType = FetchType.EAGER;
31: private boolean nonEmpty = false;
32: private ParticipationConstraint[] participationConstraints = new ParticipationConstraint[]{};
33:
34: PropertyAttributes(FieldMappingValidator validator) {
35: this.validator = validator;
36: }
37:
38: Type<?> getType() {
39: return type;
40: }
41:
42: Attribute.PersistentAttributeType getPersistentAttributeType() {
43: return persistentAttributeType;
44: }
45:
46: IRI getIri() {
47: return iri;
48: }
49:
50: CascadeType[] getCascadeTypes() {
51: return cascadeTypes;
52: }
53:
54: FetchType getFetchType() {
55: return fetchType;
56: }
57:
58: boolean isKnownOwlProperty() {
59: return true;
60: }
61:
62: boolean isNonEmpty() {
63: return nonEmpty;
64: }
65:
66: ParticipationConstraint[] getParticipationConstraints() {
67: return participationConstraints;
68: }
69:
70: void resolve(Field field, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
71: resolveParticipationConstraints(field);
72: }
73:
74: private void resolveParticipationConstraints(Field field) {
75: ParticipationConstraints cons = field.getAnnotation(ParticipationConstraints.class);
76: if (cons != null) {
77: if (cons.value().length > 0) {
78: this.participationConstraints = cons.value();
79: } else {
80: this.nonEmpty = cons.nonEmpty();
81: }
82: }
83: }
84:
85: static PropertyAttributes create(Field field, FieldMappingValidator validator) {
86: if (field.getAnnotation(OWLObjectProperty.class) != null) {
87: return new ObjectPropertyAttributes(validator);
88: } else if (field.getAnnotation(OWLDataProperty.class) != null) {
89: return new DataPropertyAttributes(validator);
90: } else if (field.getAnnotation(OWLAnnotationProperty.class) != null) {
91: return new AnnotationPropertyAttributes(validator);
92: } else {
93: return new NonPropertyAttributes(validator);
94: }
95: }
96:
97: private static class NonPropertyAttributes extends PropertyAttributes {
98:
99: NonPropertyAttributes(FieldMappingValidator validator) {
100: super(validator);
101: }
102:
103: @Override
104: boolean isKnownOwlProperty() {
105: return false;
106: }
107:
108: @Override
109: void resolve(Field field, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
110: // do nothing
111: }
112: }
113: }