Skip to main content
summaryrefslogtreecommitdiffstats
blob: 080e85d7b8e0274c3e87d7e5e0fa4b04e25b9a0b (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * Copyright (c) 2008 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;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.utility.jdt.NumberIntegerExpressionConverter;
import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
import org.eclipse.jpt.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.utility.jdt.Type;
import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
import org.eclipse.jpt.eclipselink.core.resource.java.TimeOfDayAnnotation;


public class TimeOfDayImpl extends AbstractResourceAnnotation<Type> implements TimeOfDayAnnotation
{	
	private final AnnotationElementAdapter<Integer> hourAdapter;
	private final AnnotationElementAdapter<Integer> minuteAdapter;
	private final AnnotationElementAdapter<Integer> secondAdapter;
	private final AnnotationElementAdapter<Integer> millisecondAdapter;
	
	private final DeclarationAnnotationElementAdapter<Integer> hourDeclarationAdapter;
	private final DeclarationAnnotationElementAdapter<Integer> minuteDeclarationAdapter;
	private final DeclarationAnnotationElementAdapter<Integer> secondDeclarationAdapter;
	private final DeclarationAnnotationElementAdapter<Integer> millisecondDeclarationAdapter;
	
	
	private Integer hour;
	private Integer minute;
	private Integer second;
	private Integer millisecond;
	
	protected TimeOfDayImpl(JavaResourceNode parent, Type type, DeclarationAnnotationAdapter daa) {
		super(parent, type, daa);
		this.hourDeclarationAdapter = buildHourAdapter(daa);
		this.hourAdapter = new ShortCircuitAnnotationElementAdapter<Integer>(type, this.hourDeclarationAdapter);
		this.minuteDeclarationAdapter = buildMinuteAdapter(daa);
		this.minuteAdapter = new ShortCircuitAnnotationElementAdapter<Integer>(type, this.minuteDeclarationAdapter);
		this.secondDeclarationAdapter = buildSecondAdapter(daa);
		this.secondAdapter = new ShortCircuitAnnotationElementAdapter<Integer>(type, this.secondDeclarationAdapter);
		this.millisecondDeclarationAdapter = buildMillisecondAdapter(daa);
		this.millisecondAdapter = new ShortCircuitAnnotationElementAdapter<Integer>(type, this.millisecondDeclarationAdapter);
	}
	
	public String getAnnotationName() {
		return ANNOTATION_NAME;
	}
	
	//*************** TimeOfDayAnnotation implementation ****************
	
	public Integer getHour() {
		return this.hour;
	}
	
	public void setHour(Integer newHour) {
		if (attributeValueHasNotChanged(this.hour, newHour)) {
			return;
		}
		Integer oldHour = this.hour;
		this.hour = newHour;
		this.hourAdapter.setValue(newHour);
		firePropertyChanged(HOUR_PROPERTY, oldHour, newHour);
	}

	public Integer getMinute() {
		return this.minute;
	}
	
	public void setMinute(Integer newMinute) {
		if (attributeValueHasNotChanged(this.minute, newMinute)) {
			return;
		}
		Integer oldMinute = this.minute;
		this.minute = newMinute;
		this.minuteAdapter.setValue(newMinute);
		firePropertyChanged(MINUTE_PROPERTY, oldMinute, newMinute);
	}
	
	public Integer getSecond() {
		return this.second;
	}
	
	public void setSecond(Integer newSecond) {
		if (attributeValueHasNotChanged(this.second, newSecond)) {
			return;
		}
		Integer oldSecond = this.second;
		this.second = newSecond;
		this.secondAdapter.setValue(newSecond);
		firePropertyChanged(SECOND_PROPERTY, oldSecond, newSecond);
	}
	
	public Integer getMillisecond() {
		return this.millisecond;
	}
	
	public void setMillisecond(Integer newMillisecond) {
		if (attributeValueHasNotChanged(this.millisecond, newMillisecond)) {
			return;
		}
		Integer oldMillisecond = this.millisecond;
		this.millisecond = newMillisecond;
		this.millisecondAdapter.setValue(newMillisecond);
		firePropertyChanged(MILLISECOND_PROPERTY, oldMillisecond, newMillisecond);
	}
	
	public TextRange getHourTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.hourDeclarationAdapter, astRoot);
	}

	public TextRange getMinuteTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.minuteDeclarationAdapter, astRoot);
	}
	
	public TextRange getSecondTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.secondDeclarationAdapter, astRoot);
	}
	
	public TextRange getMillisecondTextRange(CompilationUnit astRoot) {
		return this.getElementTextRange(this.millisecondDeclarationAdapter, astRoot);
	}
	
	public void initialize(CompilationUnit astRoot) {
		this.hour = this.hour(astRoot);
		this.minute = this.minute(astRoot);
		this.second = this.second(astRoot);
		this.millisecond = this.millisecond(astRoot);
	}

	public void update(CompilationUnit astRoot) {
		this.setHour(this.hour(astRoot));
		this.setMinute(this.minute(astRoot));
		this.setSecond(this.second(astRoot));
		this.setMillisecond(this.millisecond(astRoot));
	}
	
	protected Integer hour(CompilationUnit astRoot) {
		return this.hourAdapter.getValue(astRoot);
	}
	
	protected Integer minute(CompilationUnit astRoot) {
		return this.minuteAdapter.getValue(astRoot);
	}
	
	protected Integer second(CompilationUnit astRoot) {
		return this.secondAdapter.getValue(astRoot);
	}
	
	protected Integer millisecond(CompilationUnit astRoot) {
		return this.millisecondAdapter.getValue(astRoot);
	}
	
	// ********** static methods **********
	
	private static DeclarationAnnotationElementAdapter<Integer> buildHourAdapter(DeclarationAnnotationAdapter daa) {
		return new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, EclipseLinkJPA.TIME_OF_DAY__HOUR, false, NumberIntegerExpressionConverter.instance());
	}
	
	private static DeclarationAnnotationElementAdapter<Integer> buildMinuteAdapter(DeclarationAnnotationAdapter daa) {
		return new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, EclipseLinkJPA.TIME_OF_DAY__MINUTE, false, NumberIntegerExpressionConverter.instance());
	}
	
	private static DeclarationAnnotationElementAdapter<Integer> buildSecondAdapter(DeclarationAnnotationAdapter daa) {
		return new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, EclipseLinkJPA.TIME_OF_DAY__SECOND, false, NumberIntegerExpressionConverter.instance());
	}
	
	private static DeclarationAnnotationElementAdapter<Integer> buildMillisecondAdapter(DeclarationAnnotationAdapter daa) {
		return new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, EclipseLinkJPA.TIME_OF_DAY__MILLISECOND, false, NumberIntegerExpressionConverter.instance());
	}

}

Back to the top