Skip to content

Method: getAttributeDescriptor(FieldSpecification)

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.model.descriptors;
14:
15: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
16:
17: import java.net.URI;
18: import java.util.Objects;
19: import java.util.Set;
20:
21: /**
22: * Allows to provide descriptor for elements of an object property collection.
23: */
24: public class ObjectPropertyCollectionDescriptor extends FieldDescriptor {
25:
26: private final EntityDescriptor elementDescriptor;
27:
28: public ObjectPropertyCollectionDescriptor(FieldSpecification<?, ?> attribute) {
29: super(attribute);
30: this.elementDescriptor = new EntityDescriptor();
31: }
32:
33: public ObjectPropertyCollectionDescriptor(URI context, FieldSpecification<?, ?> attribute) {
34: super(context, attribute);
35: this.elementDescriptor = new EntityDescriptor(context);
36: }
37:
38: public ObjectPropertyCollectionDescriptor(Set<URI> contexts, FieldSpecification<?, ?> attribute) {
39: super(contexts, attribute);
40: this.elementDescriptor = new EntityDescriptor(contexts);
41: }
42:
43: public ObjectPropertyCollectionDescriptor(URI context, FieldSpecification<?, ?> attribute,
44: boolean assertionsInSubjectContext) {
45: super(context, attribute);
46: this.elementDescriptor = new EntityDescriptor(context, assertionsInSubjectContext);
47: }
48:
49: @Override
50: public Descriptor getAttributeDescriptor(FieldSpecification<?, ?> attribute) {
51: Objects.requireNonNull(attribute);
52:• if (getField().equals(attribute.getJavaField())) {
53: return this;
54: }
55: return elementDescriptor.getAttributeDescriptor(attribute);
56: }
57:
58: @Override
59: public Set<URI> getAttributeContexts(FieldSpecification<?, ?> attribute) {
60: Objects.requireNonNull(attribute);
61: if (getField().equals(attribute.getJavaField())) {
62: return getContexts();
63: }
64: return elementDescriptor.getAttributeContexts(attribute);
65: }
66:
67: @Override
68: public ObjectPropertyCollectionDescriptor addAttributeDescriptor(FieldSpecification<?, ?> attribute,
69: Descriptor descriptor) {
70: elementDescriptor.addAttributeDescriptor(attribute, descriptor);
71: return this;
72: }
73:
74: @Override
75: public ObjectPropertyCollectionDescriptor addAttributeContext(FieldSpecification<?, ?> attribute, URI context) {
76: elementDescriptor.addAttributeContext(attribute, context);
77: return this;
78: }
79:
80: @Override
81: public boolean overridesAssertionContext() {
82: return false;
83: }
84:
85: public EntityDescriptor getElementDescriptor() {
86: return elementDescriptor;
87: }
88:
89: @Override
90: public int hashCode() {
91: final int prime = 31;
92: int result = super.hashCode();
93: result = prime * result + ((elementDescriptor == null) ? 0 : elementDescriptor.hashCode());
94: return result;
95: }
96:
97: @Override
98: public boolean equals(Object obj) {
99: if (this == obj)
100: return true;
101: if (!super.equals(obj))
102: return false;
103: if (getClass() != obj.getClass())
104: return false;
105: ObjectPropertyCollectionDescriptor other = (ObjectPropertyCollectionDescriptor) obj;
106: if (elementDescriptor == null) {
107: return other.elementDescriptor == null;
108: } else return elementDescriptor.equals(other.elementDescriptor);
109: }
110: }