Skip to content

Method: isKnownOwlProperty()

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