Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7cf112ff5e11085f5c45fc33649adbe60f3dc3b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*******************************************************************************
 * Copyright (c) 2010, 2011 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.context.java;

import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentProperty;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod;

public class GenericJavaPersistentProperty
		extends GenericJavaPersistentAttribute
		implements JaxbPersistentProperty {


	protected final JavaResourceMethod resourceGetter;

	protected final JavaResourceMethod resourceSetter;

	public GenericJavaPersistentProperty(JaxbPersistentClass parent, JavaResourceMethod resourceGetter, JavaResourceMethod resourceSetter) {
		super(parent);
		this.resourceGetter = resourceGetter;
		this.resourceSetter = resourceSetter;
		this.initializeMapping();
	}

	public JavaResourceAttribute getJavaResourceAttribute() {
		return this.calculateResourceMethodToAnnotate();
	}

	public String getJavaResourceAttributeTypeName() {
		JavaResourceAttribute getterMethod = getResourceGetterMethod();
		//it's invalid to have a setter without a getter, so just return null in this case
		//rather than attempting to define the type from the setter's parameters
		return getterMethod == null ? null : getJavaResourceAttributeType(getterMethod);
	}

	public boolean isJavaResourceAttributeTypeArray() {
		JavaResourceAttribute getterMethod = getResourceGetterMethod();
		//it's invalid to have a setter without a getter, so just return false in this case
		//rather than attempting to use the setter's parameters
		return getterMethod == null ? false : typeIsArray(getterMethod);
	}

	public boolean isJavaResourceAttributeTypeSubTypeOf(String typeName) {
		JavaResourceAttribute getterMethod = getResourceGetterMethod();
		//it's invalid to have a setter without a getter, so just return false in this case
		//rather than attempting to use the setter's parameters
		return getterMethod == null ? false : typeIsSubTypeOf(getterMethod, typeName);
	}

	public JavaResourceMethod getResourceGetterMethod() {
		return this.resourceGetter;
	}

	public JavaResourceMethod getResourceSetterMethod() {
		return this.resourceSetter;
	}

	public boolean isFor(JavaResourceField resourceField) {
		return false;
	}

	public boolean isFor(JavaResourceMethod getterMethod, JavaResourceMethod setterMethod) {
		return (this.resourceGetter == getterMethod) && (this.resourceSetter == setterMethod);
	}

	//since this is based on a preference as well as annotation location
	//we will just calculate it instead of handling it in sync and storing it.
	protected JavaResourceMethod calculateResourceMethodToAnnotate() {
		if (getterIsAnnotated()) {
			if (setterIsAnnotated()) {
				//use preference for which one to set the primary annotation on.
				return getAnnotateGetterPreference() ? this.resourceGetter : this.resourceSetter;
			}
			return this.resourceGetter;
		}
		else if (setterIsAnnotated()) {
			return this.resourceSetter;
		}
		else if (getAnnotateGetterPreference()&& this.resourceGetter != null) {
			return this.resourceGetter;
		}
		return this.resourceSetter;
	}

	protected boolean getterIsAnnotated() {
		return this.resourceGetter == null ? false : this.resourceGetter.isAnnotated(); 		
	}

	protected boolean setterIsAnnotated() {
		return this.resourceSetter == null ? false : this.resourceSetter.isAnnotated(); 
	}

	//TODO bug 333483 - make this a preference for the user to select whether the getter or setter should be annotated.
	protected boolean getAnnotateGetterPreference() {
		return true;
	}

	//TODO validation - bug 333484
	//if (getterIsAnnotated() && setterIsAnnotated()) error to user
}

Back to the top