Skip to main content
summaryrefslogtreecommitdiffstats
blob: e50c25eb6cd1a902e328f049e9173844f7dd8560 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2008, 2010 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.eclipselink.core.internal.resource.java.source;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.Attribute;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkTransformerAnnotation;

/**
 * org.eclipse.persistence.annotations.ReadTransformer
 * org.eclipse.persistence.annotations.WriteTransformer
 */
abstract class SourceEclipseLinkTransformerAnnotation
	extends SourceAnnotation<Attribute>
	implements EclipseLinkTransformerAnnotation
{
	final DeclarationAnnotationElementAdapter<String> transformerClassDeclarationAdapter;
	final AnnotationElementAdapter<String> transformerClassAdapter;
	String transformerClass;

	final DeclarationAnnotationElementAdapter<String> methodDeclarationAdapter;
	final AnnotationElementAdapter<String> methodAdapter;
	String method;


	SourceEclipseLinkTransformerAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, DeclarationAnnotationAdapter daa) {
		super(parent, attribute, daa);
		this.transformerClassDeclarationAdapter = new ConversionDeclarationAnnotationElementAdapter<String>(daa, this.getTransformerClassElementName(), false, SimpleTypeStringExpressionConverter.instance());
		this.transformerClassAdapter = new MemberAnnotationElementAdapter<String>(attribute, this.transformerClassDeclarationAdapter);

		this.methodDeclarationAdapter = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, this.getMethodElementName(), false);
		this.methodAdapter = new MemberAnnotationElementAdapter<String>(attribute, this.methodDeclarationAdapter);
	}

	public void initialize(CompilationUnit astRoot) {
		this.transformerClass = this.buildTransformerClass(astRoot);
		this.method = this.buildMethod(astRoot);
	}

	public void synchronizeWith(CompilationUnit astRoot) {
		this.syncTransformerClass(this.buildTransformerClass(astRoot));
		this.syncMethod(this.buildMethod(astRoot));
	}

	@Override
	public void toString(StringBuilder sb) {
		sb.append(this.transformerClass);
	}


	// ********** TransformerAnnotation implementation **********

	// ***** transformer class
	public String getTransformerClass() {
		return this.transformerClass;
	}

	public void setTransformerClass(String transformerClass) {
		if (this.attributeValueHasChanged(this.transformerClass, transformerClass)) {
			this.transformerClass = transformerClass;
			this.transformerClassAdapter.setValue(transformerClass);
		}
	}

	private void syncTransformerClass(String astTransformerClass) {
		String old = this.transformerClass;
		this.transformerClass = astTransformerClass;
		this.firePropertyChanged(TRANSFORMER_CLASS_PROPERTY, old, astTransformerClass);
	}

	private String buildTransformerClass(CompilationUnit astRoot) {
		return this.transformerClassAdapter.getValue(astRoot);
	}

	public TextRange getTransformerClassTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.transformerClassDeclarationAdapter, astRoot);
	}

	abstract String getTransformerClassElementName();

	// ***** method
	public String getMethod() {
		return this.method;
	}

	public void setMethod(String method) {
		if (this.attributeValueHasChanged(this.method, method)) {
			this.method = method;
			this.methodAdapter.setValue(method);
		}
	}

	private void syncMethod(String astMethod) {
		String old = this.method;
		this.method = astMethod;
		this.firePropertyChanged(METHOD_PROPERTY, old, astMethod);
	}

	private String buildMethod(CompilationUnit astRoot) {
		return this.methodAdapter.getValue(astRoot);
	}

	public TextRange getMethodTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.methodDeclarationAdapter, astRoot);
	}

	abstract String getMethodElementName();

}

Back to the top