Skip to content

Method: isSimpleLiteral()

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.model.metamodel;
19:
20: import cz.cvut.kbss.jopa.model.IRI;
21: import cz.cvut.kbss.jopa.model.MultilingualString;
22: import cz.cvut.kbss.jopa.model.annotations.CascadeType;
23: import cz.cvut.kbss.jopa.model.annotations.EnumType;
24: import cz.cvut.kbss.jopa.model.annotations.Enumerated;
25: import cz.cvut.kbss.jopa.model.annotations.FetchType;
26: import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty;
27: import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
28: import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
29: import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraint;
30: import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraints;
31:
32: abstract class PropertyAttributes {
33:
34: final FieldMappingValidator validator;
35:
36: TypeBuilderContext<?> typeBuilderContext;
37:
38: Type<?> type = null;
39: Attribute.PersistentAttributeType persistentAttributeType = null;
40: IRI iri = null;
41: CascadeType[] cascadeTypes = new CascadeType[]{};
42: FetchType fetchType = FetchType.EAGER;
43: boolean lexicalForm = false;
44: boolean simpleLiteral = false;
45: String datatype = "";
46: String language;
47: private boolean nonEmpty = false;
48: private ParticipationConstraint[] participationConstraints = new ParticipationConstraint[]{};
49: private EnumType enumType = null;
50:
51: PropertyAttributes(FieldMappingValidator validator) {
52: this.validator = validator;
53: }
54:
55: Type<?> getType() {
56: return type;
57: }
58:
59: Attribute.PersistentAttributeType getPersistentAttributeType() {
60: return persistentAttributeType;
61: }
62:
63: IRI getIri() {
64: return iri;
65: }
66:
67: CascadeType[] getCascadeTypes() {
68: return cascadeTypes;
69: }
70:
71: FetchType getFetchType() {
72: return fetchType;
73: }
74:
75: boolean isKnownOwlProperty() {
76: return true;
77: }
78:
79: boolean isNonEmpty() {
80: return nonEmpty;
81: }
82:
83: boolean isLexicalForm() {
84: return lexicalForm;
85: }
86:
87: boolean isSimpleLiteral() {
88: return simpleLiteral;
89: }
90:
91: public String getDatatype() {
92: return datatype;
93: }
94:
95: public boolean hasDatatype() {
96: return !datatype.isEmpty();
97: }
98:
99: String getLanguage() {
100: return language;
101: }
102:
103: ParticipationConstraint[] getParticipationConstraints() {
104: return participationConstraints;
105: }
106: public EnumType getEnumType() {
107: return enumType;
108: }
109: void resolve(PropertyInfo propertyInfo, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
110: resolveParticipationConstraints(propertyInfo);
111: resolveEnumType(propertyInfo, fieldValueCls);
112: }
113:
114: private void resolveParticipationConstraints(PropertyInfo propertyInfo) {
115: ParticipationConstraints cons = propertyInfo.getAnnotation(ParticipationConstraints.class);
116:
117: if (cons != null) {
118: if (cons.value().length > 0) {
119: this.participationConstraints = cons.value();
120: } else {
121: this.nonEmpty = cons.nonEmpty();
122: }
123: }
124: }
125: private void resolveEnumType(PropertyInfo propertyInfo, Class<?> fieldValueCls) {
126: final Enumerated enumAnn = propertyInfo.getAnnotation(Enumerated.class);
127: if (enumAnn != null) {
128: this.enumType = enumAnn.value();
129: } else if (fieldValueCls.isEnum()) {
130: // As per default of Enumerated.value()
131: this.enumType = EnumType.STRING;
132: }
133: }
134:
135: String resolveLanguage(Class<?> fieldValueCls) {
136: return MultilingualString.class.equals(fieldValueCls) ? null : typeBuilderContext.getPuLanguage();
137: }
138:
139: static PropertyAttributes create(PropertyInfo field, FieldMappingValidator validator, TypeBuilderContext<?> context) {
140: final PropertyAttributes instance;
141: if (field.getAnnotation(OWLObjectProperty.class) != null) {
142: instance = new ObjectPropertyAttributes(validator);
143: } else if (field.getAnnotation(OWLDataProperty.class) != null) {
144: instance = new DataPropertyAttributes(validator);
145: } else if (field.getAnnotation(OWLAnnotationProperty.class) != null) {
146: instance = new AnnotationPropertyAttributes(validator);
147: } else {
148: instance = new NonPropertyAttributes(validator);
149: }
150: instance.typeBuilderContext = context;
151: return instance;
152: }
153:
154: private static class NonPropertyAttributes extends PropertyAttributes {
155:
156: NonPropertyAttributes(FieldMappingValidator validator) {
157: super(validator);
158: }
159:
160: @Override
161: boolean isKnownOwlProperty() {
162: return false;
163: }
164:
165: @Override
166: void resolve(PropertyInfo propertyInfo, MetamodelBuilder metamodelBuilder, Class<?> fieldValueCls) {
167: // do nothing
168: }
169: }
170: }