Skip to content

Method: PropertiesSpecificationImpl.PropertiesSpecificationBuilder()

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;
16:
17: import cz.cvut.kbss.jopa.model.annotations.FetchType;
18: import cz.cvut.kbss.jopa.model.metamodel.ManagedType;
19: import cz.cvut.kbss.jopa.model.metamodel.PropertiesSpecification;
20:
21: import java.lang.reflect.Field;
22:
23: public class PropertiesSpecificationImpl<X, Y, K, V> implements PropertiesSpecification<X, Y, K, V> {
24: private final ManagedType<X> declaringType;
25: private final FetchType fetchType;
26: private final Field javaField;
27: private final Class<Y> javaType;
28: private final boolean inferred;
29: private final Class<K> propertyIdType;
30: private final Class<V> propertyValueType;
31:
32: private PropertiesSpecificationImpl(PropertiesSpecificationBuilder<X, Y, K, V> builder) {
33: this.declaringType = builder.declaringType;
34: this.fetchType = builder.fetchType;
35: this.javaField = builder.javaField;
36: this.javaType = builder.javaType;
37: this.inferred = builder.inferred;
38: this.propertyIdType = builder.propertyIdType;
39: this.propertyValueType = builder.propertyValueType;
40: }
41:
42: @Override
43: public ManagedType<X> getDeclaringType() {
44: return declaringType;
45: }
46:
47: @Override
48: public FetchType getFetchType() {
49: return fetchType;
50: }
51:
52: @Override
53: public Field getJavaField() {
54: return javaField;
55: }
56:
57: @Override
58: public Class<Y> getJavaType() {
59: return javaType;
60: }
61:
62: @Override
63: public boolean isInferred() {
64: return inferred;
65: }
66:
67: @Override
68: public boolean includeExplicit() {
69: // TODO
70: return true;
71: }
72:
73: @Override
74: public boolean isReadOnly() {
75: // TODO
76: return false;
77: }
78:
79: @Override
80: public String getName() {
81: return javaField.getName();
82: }
83:
84: @Override
85: public Class<K> getPropertyIdentifierType() {
86: return propertyIdType;
87: }
88:
89: @Override
90: public Class<V> getPropertyValueType() {
91: return propertyValueType;
92: }
93:
94: public static <X, Y, K, V> PropertiesSpecificationBuilder declaringType(ManagedType<X> declaringType) {
95: return new PropertiesSpecificationBuilder<X, Y, K, V>().declaringType(declaringType);
96: }
97:
98: public static class PropertiesSpecificationBuilder<X, Y, K, V> {
99: private ManagedType<X> declaringType;
100: private FetchType fetchType;
101: private Field javaField;
102: private Class<Y> javaType;
103: private boolean inferred;
104: private Class<K> propertyIdType;
105: private Class<V> propertyValueType;
106:
107: public PropertiesSpecificationBuilder<X, Y, K, V> declaringType(ManagedType<X> declaringType) {
108: this.declaringType = declaringType;
109: return this;
110: }
111:
112: public PropertiesSpecificationBuilder<X, Y, K, V> fetchType(FetchType fetchType) {
113: this.fetchType = fetchType;
114: return this;
115: }
116:
117: public PropertiesSpecificationBuilder<X, Y, K, V> javaField(Field javaField) {
118: this.javaField = javaField;
119: return this;
120: }
121:
122: public PropertiesSpecificationBuilder<X, Y, K, V> javaType(Class<Y> javaType) {
123: this.javaType = javaType;
124: return this;
125: }
126:
127: public PropertiesSpecificationBuilder<X, Y, K, V> inferred(boolean inferred) {
128: this.inferred = inferred;
129: return this;
130: }
131:
132: public PropertiesSpecificationBuilder<X, Y, K, V> propertyIdType(Class<K> propertyIdType) {
133: this.propertyIdType = propertyIdType;
134: return this;
135: }
136:
137: public PropertiesSpecificationBuilder<X, Y, K, V> propertyValueType(Class<V> propertyValueType) {
138: this.propertyValueType = propertyValueType;
139: return this;
140: }
141:
142: public PropertiesSpecificationImpl<X, Y, K, V> build() {
143: return new PropertiesSpecificationImpl<>(this);
144: }
145: }
146: }