Skip to content

Method: ObjectPropertyAttributes(FieldMappingValidator)

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.BasicTypeImpl;
18: import cz.cvut.kbss.jopa.model.IRI;
19: import cz.cvut.kbss.jopa.model.MetamodelImpl;
20: import cz.cvut.kbss.jopa.model.annotations.CascadeType;
21: import cz.cvut.kbss.jopa.model.annotations.FetchType;
22: import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty;
23:
24: import java.lang.reflect.Field;
25:
26: class ObjectPropertyAttributes extends PropertyAttributes {
27:
28: ObjectPropertyAttributes(FieldMappingValidator validator) {
29: super(validator);
30: }
31:
32: @Override
33: void resolve(Field field, MetamodelImpl metamodel, Class<?> fieldValueCls) {
34: super.resolve(field, metamodel, fieldValueCls);
35: final OWLObjectProperty oop = field.getAnnotation(OWLObjectProperty.class);
36: assert oop != null;
37:
38: this.persistentAttributeType = Attribute.PersistentAttributeType.OBJECT;
39: this.iri = IRI.create(oop.iri());
40:
41: if (validator.isValidIdentifierType(fieldValueCls)) {
42: initPlainIdentifierAttribute(fieldValueCls);
43: } else {
44: this.type = metamodel.entity(fieldValueCls);
45: this.cascadeTypes = oop.cascade();
46: this.fetchType = oop.fetch();
47: }
48: }
49:
50: private void initPlainIdentifierAttribute(Class<?> targetType) {
51: this.type = BasicTypeImpl.get(targetType);
52: this.cascadeTypes = new CascadeType[0];
53: this.fetchType = FetchType.EAGER;
54: }
55: }