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.MetamodelImpl;
19: import cz.cvut.kbss.jopa.model.annotations.*;
20:
21: import java.lang.reflect.Field;
22:
23: /**
24: * @author ledvima1
25: */
26: abstract class PropertyAttributes {
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 nonEmpty = false;
34: ParticipationConstraint[] participationConstraints = new ParticipationConstraint[]{};
35:
36: Type<?> getType() {
37: return type;
38: }
39:
40: Attribute.PersistentAttributeType getPersistentAttributeType() {
41: return persistentAttributeType;
42: }
43:
44: IRI getIri() {
45: return iri;
46: }
47:
48: CascadeType[] getCascadeTypes() {
49: return cascadeTypes;
50: }
51:
52: FetchType getFetchType() {
53: return fetchType;
54: }
55:
56: boolean isKnownOwlProperty() {
57: return true;
58: }
59:
60: boolean isNonEmpty() {
61: return nonEmpty;
62: }
63:
64: ParticipationConstraint[] getParticipationConstraints() {
65: return participationConstraints;
66: }
67:
68: void resolve(Field field, MetamodelImpl metamodel, Class<?> fieldValueCls) {
69: resolveParticipationConstraints(field);
70: }
71:
72: void resolveParticipationConstraints(Field field) {
73: ParticipationConstraints cons = field.getAnnotation(ParticipationConstraints.class);
74: if (cons != null) {
75: if (cons.value() != null && cons.value().length > 0) {
76: this.participationConstraints = cons.value();
77: } else {
78: this.nonEmpty = cons.nonEmpty();
79: }
80: }
81: }
82:
83: static PropertyAttributes create(Field field) {
84: if (field.getAnnotation(OWLObjectProperty.class) != null) {
85: return new ObjectPropertyAttributes();
86: } else if (field.getAnnotation(OWLDataProperty.class) != null) {
87: return new DataPropertyAttributes();
88: } else if (field.getAnnotation(OWLAnnotationProperty.class) != null) {
89: return new AnnotationPropertyAttributes();
90: } else {
91: return new NonPropertyAttributes();
92: }
93: }
94:
95: private static class NonPropertyAttributes extends PropertyAttributes {
96:
97: @Override
98: boolean isKnownOwlProperty() {
99: return false;
100: }
101:
102: @Override
103: void resolve(Field field, MetamodelImpl metamodel, Class<?> fieldValueCls) {
104: // do nothing
105: }
106: }
107: }