Skip to contentMethod: getIRI()
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.annotations.CascadeType;
22: import cz.cvut.kbss.jopa.model.annotations.FetchType;
23: import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraint;
24: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
25:
26: import java.lang.reflect.Field;
27: import java.lang.reflect.Member;
28:
29: public abstract class AbstractAttribute<X, Y> implements Attribute<X, Y> {
30:
31: private final PropertyInfo propertyInfo;
32:
33: private final ManagedType<X> declaringType;
34:
35: private final PersistentAttributeType attributeType;
36:
37: private final IRI iri;
38:
39: private final CascadeType[] cascadeTypes;
40:
41: private final FetchType fetchType;
42:
43: private final boolean inferred;
44:
45: private final boolean includeExplicit;
46:
47: private final boolean nonEmpty;
48:
49: private final boolean lexicalForm;
50:
51: private final boolean simpleLiteral;
52:
53: private final String datatype;
54:
55: private final String language;
56:
57: private final ParticipationConstraint[] constraints;
58:
59: private final ConverterWrapper converter;
60:
61: AbstractAttribute(AbstractAttributeBuilder<X, Y> builder) {
62: this.propertyInfo = builder.propertyInfo;
63: this.declaringType = builder.declaringType;
64: this.attributeType = builder.attributeType;
65: this.iri = builder.iri;
66: this.cascadeTypes = builder.cascadeTypes;
67: this.fetchType = builder.fetchType;
68: this.inferred = builder.inferred;
69: this.includeExplicit = builder.includeExplicit;
70: this.constraints = builder.constraints;
71: this.nonEmpty = builder.nonEmpty;
72: this.converter = builder.converter;
73: this.lexicalForm = builder.lexicalForm;
74: this.simpleLiteral = builder.simpleLiteral;
75: this.language = builder.language;
76: this.datatype = builder.datatype;
77: }
78:
79: @Override
80: public PersistentAttributeType getPersistentAttributeType() {
81: return attributeType;
82: }
83:
84: @Override
85: public Member getJavaMember() {
86: return propertyInfo.getMember();
87: }
88:
89: @Override
90: public IRI getIRI() {
91: return iri;
92: }
93:
94: @Override
95: public CascadeType[] getCascadeTypes() {
96: return cascadeTypes;
97: }
98:
99: @Override
100: public boolean isNonEmpty() {
101: return nonEmpty;
102: }
103:
104: @Override
105: public ParticipationConstraint[] getConstraints() {
106: return constraints;
107: }
108:
109: @Override
110: public ManagedType<X> getDeclaringType() {
111: return declaringType;
112: }
113:
114: @Override
115: public Field getJavaField() {
116: return propertyInfo.field();
117: }
118:
119: @Override
120: public FetchType getFetchType() {
121: return fetchType;
122: }
123:
124: @Override
125: public boolean isInferred() {
126: return inferred;
127: }
128:
129: @Override
130: public boolean includeExplicit() {
131: return includeExplicit;
132: }
133:
134: @Override
135: public boolean isLexicalForm() {
136: return lexicalForm;
137: }
138:
139: @Override
140: public boolean isSimpleLiteral() {
141: return simpleLiteral;
142: }
143:
144: @Override
145: public boolean hasLanguage() {
146: return language != null && !simpleLiteral && !lexicalForm && attributeType != PersistentAttributeType.OBJECT;
147: }
148:
149: @Override
150: public String getLanguage() {
151: return language;
152: }
153:
154: @Override
155: public String getName() {
156: return propertyInfo.getName();
157: }
158:
159: public ConverterWrapper getConverter() {
160: return converter;
161: }
162:
163: @Override
164: public String toString() {
165: return declaringType.getJavaType().getSimpleName() + "." + getName();
166: }
167:
168: @Override
169: public String getDatatype() {
170: return datatype;
171: }
172:
173: abstract static class AbstractAttributeBuilder<X, Y> {
174: private PropertyInfo propertyInfo;
175: private ManagedType<X> declaringType;
176: private PersistentAttributeType attributeType;
177: private IRI iri;
178: private CascadeType[] cascadeTypes;
179: private FetchType fetchType;
180: private boolean inferred;
181: private boolean includeExplicit;
182: private boolean nonEmpty = false;
183: private boolean lexicalForm = false;
184: private boolean simpleLiteral = false;
185: private String datatype;
186: private String language;
187: private ParticipationConstraint[] constraints;
188: private ConverterWrapper converter;
189:
190: FieldMappingValidator mappingValidator;
191:
192: public AbstractAttributeBuilder<X, Y> config(PropertyAttributes config) {
193: this.iri = config.getIri();
194: this.attributeType = config.getPersistentAttributeType();
195: this.cascadeTypes = config.getCascadeTypes();
196: this.constraints = config.getParticipationConstraints();
197: this.nonEmpty = config.isNonEmpty();
198: this.fetchType = config.getFetchType();
199: this.lexicalForm = config.isLexicalForm();
200: this.simpleLiteral = config.isSimpleLiteral();
201: this.datatype = config.hasDatatype() ? config.getDatatype() : null;
202: this.language = config.getLanguage();
203: this.mappingValidator = config.validator;
204: return this;
205: }
206:
207: public AbstractAttributeBuilder<X, Y> propertyInfo(PropertyInfo propertyInfo) {
208: this.propertyInfo = propertyInfo;
209: return this;
210: }
211:
212: public AbstractAttributeBuilder<X, Y> declaringType(ManagedType<X> declaringType) {
213: this.declaringType = declaringType;
214: return this;
215: }
216:
217: public AbstractAttributeBuilder<X, Y> inferred(boolean inferred) {
218: this.inferred = inferred;
219: return this;
220: }
221:
222: public AbstractAttributeBuilder<X, Y> includeExplicit(boolean includeExplicit) {
223: this.includeExplicit = includeExplicit;
224: return this;
225: }
226:
227: public AbstractAttributeBuilder<X, Y> converter(ConverterWrapper converter) {
228: this.converter = converter;
229: return this;
230: }
231:
232: public abstract AbstractAttribute<X, Y> build();
233: }
234: }