Skip to content

Method: config(PropertyAttributes)

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.oom.converter.ConverterWrapper;
21:
22: import java.util.Collection;
23: import java.util.Map;
24:
25: public abstract class AbstractPluralAttribute<X, C, E> extends AbstractAttribute<X, C>
26: implements PluralAttribute<X, C, E> {
27:
28: private final Type<E> elementType;
29:
30: private final Class<C> collectionType;
31:
32: AbstractPluralAttribute(PluralAttributeBuilder<X, C, E> builder) {
33: super(builder);
34: this.elementType = builder.elementType;
35: this.collectionType = builder.collectionType;
36: }
37:
38: @Override
39: public boolean isCollection() {
40: return true;
41: }
42:
43: @Override
44: public Class<E> getBindableJavaType() {
45: return elementType.getJavaType();
46: }
47:
48: @Override
49: public cz.cvut.kbss.jopa.model.metamodel.Bindable.BindableType getBindableType() {
50: return BindableType.PLURAL_ATTRIBUTE;
51: }
52:
53: @Override
54: public cz.cvut.kbss.jopa.model.metamodel.CollectionType getCollectionType() {
55: if (getJavaType().isAssignableFrom(Collection.class)) {
56: return CollectionType.COLLECTION;
57: } else if (getJavaType().isAssignableFrom(Map.class)) {
58: return CollectionType.MAP;
59: } else {
60: throw new IllegalArgumentException();
61: }
62: }
63:
64: @Override
65: public Type<E> getElementType() {
66: return elementType;
67: }
68:
69: @Override
70: public Class<C> getJavaType() {
71: return collectionType;
72: }
73:
74: abstract static class PluralAttributeBuilder<X, C, E> extends AbstractAttributeBuilder<X, C> {
75: private Type<E> elementType;
76: private Class<C> collectionType;
77:
78: @Override
79: public PluralAttributeBuilder<X, C, E> config(PropertyAttributes config) {
80: super.config(config);
81: elementType((Type<E>) config.getType());
82: return this;
83: }
84:
85: public PluralAttributeBuilder<X, C, E> elementType(Type<E> elementType) {
86: this.elementType = elementType;
87: return this;
88: }
89:
90: public PluralAttributeBuilder<X, C, E> collectionType(Class<C> collectionType) {
91: this.collectionType = collectionType;
92: return this;
93: }
94:
95: @Override
96: public PluralAttributeBuilder<X, C, E> propertyInfo(PropertyInfo propertyInfo) {
97: super.propertyInfo(propertyInfo);
98: return this;
99: }
100:
101: @Override
102: public PluralAttributeBuilder<X, C, E> declaringType(ManagedType<X> declaringType) {
103: super.declaringType(declaringType);
104: return this;
105: }
106:
107: @Override
108: public PluralAttributeBuilder<X, C, E> inferred(boolean inferred) {
109: super.inferred(inferred);
110: return this;
111: }
112:
113: @Override
114: public PluralAttributeBuilder<X, C, E> includeExplicit(boolean includeExplicit) {
115: super.includeExplicit(includeExplicit);
116: return this;
117: }
118:
119: @Override
120: public PluralAttributeBuilder<X, C, E> converter(ConverterWrapper converter) {
121: super.converter(converter);
122: return this;
123: }
124:
125: @Override
126: public abstract AbstractPluralAttribute<X, C, E> build();
127: }
128: }