Skip to main content
summaryrefslogtreecommitdiffstats
blob: ee4d13e34a202409c5152ad96935b46d08a5899a (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
/*******************************************************************************
 * Copyright (c) 2008, 2013 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.jpa.eclipselink.core.internal.context.orm;

import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextModel;
import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkChangeTracking;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkChangeTrackingType;
import org.eclipse.jpt.jpa.eclipselink.core.context.java.EclipseLinkJavaTypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmTypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.EclipseLinkOrmFactory;
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlChangeTracking;
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlChangeTrackingHolder;

public class EclipseLinkOrmChangeTracking
	extends AbstractOrmXmlContextModel<EclipseLinkOrmTypeMapping>
	implements EclipseLinkChangeTracking
{
	protected EclipseLinkChangeTrackingType specifiedType;
	protected EclipseLinkChangeTrackingType defaultType = DEFAULT_TYPE;


	public EclipseLinkOrmChangeTracking(EclipseLinkOrmTypeMapping parent) {
		super(parent);
		this.specifiedType = this.buildSpecifiedType();
	}


	// ********** synchronize/update **********

	@Override
	public void synchronizeWithResourceModel() {
		super.synchronizeWithResourceModel();
		this.setSpecifiedType_(this.buildSpecifiedType());
	}

	@Override
	public void update() {
		super.update();
		this.setDefaultType(this.buildDefaultType());
	}


	// ********** type **********

	public EclipseLinkChangeTrackingType getType() {
		return (this.specifiedType != null) ? this.specifiedType : this.defaultType;
	}

	public EclipseLinkChangeTrackingType getSpecifiedType() {
		return this.specifiedType;
	}

	public void setSpecifiedType(EclipseLinkChangeTrackingType type) {
		if (this.specifiedType != type) {
			XmlChangeTracking xmlChangeTracking = this.getXmlChangeTrackingForUpdate();
			this.setSpecifiedType_(type);
			xmlChangeTracking.setType(EclipseLinkChangeTrackingType.toOrmResourceModel(type));
			this.removeXmlChangeTrackingIfUnset();
		}
	}

	protected void setSpecifiedType_(EclipseLinkChangeTrackingType type) {
		EclipseLinkChangeTrackingType old = this.specifiedType;
		this.specifiedType = type;
		this.firePropertyChanged(SPECIFIED_TYPE_PROPERTY, old, type);
	}

	protected EclipseLinkChangeTrackingType buildSpecifiedType() {
		XmlChangeTracking xmlChangeTracking = this.getXmlChangeTracking();
		return (xmlChangeTracking == null) ? null : EclipseLinkChangeTrackingType.fromOrmResourceModel(xmlChangeTracking.getType());
	}

	public EclipseLinkChangeTrackingType getDefaultType() {
		return this.defaultType;
	}

	protected void setDefaultType(EclipseLinkChangeTrackingType type) {
		EclipseLinkChangeTrackingType old = this.defaultType;
		this.defaultType = type;
		this.firePropertyChanged(DEFAULT_TYPE_PROPERTY, old, type);
	}

	protected EclipseLinkChangeTrackingType buildDefaultType() {
		EclipseLinkChangeTracking javaChangeTracking = this.getJavaChangeTrackingForDefaults();
		return (javaChangeTracking != null) ? javaChangeTracking.getType() : DEFAULT_TYPE;
	}


	// ********** xml customizer class ref **********

	/**
	 * Return <code>null</code> if the XML change tracking does not exists.
	 */
	protected XmlChangeTracking getXmlChangeTracking() {
		return this.getXmlChangeTrackingHolder().getChangeTracking();
	}

	/**
	 * Build the XML change tracking if it does not exist.
	 */
	protected XmlChangeTracking getXmlChangeTrackingForUpdate() {
		XmlChangeTracking xmlChangeTracking = this.getXmlChangeTracking();
		return (xmlChangeTracking != null) ? xmlChangeTracking : this.buildXmlChangeTracking();
	}

	protected XmlChangeTracking buildXmlChangeTracking() {
		XmlChangeTracking xmlChangeTracking = EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking();
		this.getXmlChangeTrackingHolder().setChangeTracking(xmlChangeTracking);
		return xmlChangeTracking;
	}

	protected void removeXmlChangeTrackingIfUnset() {
		if (this.getXmlChangeTracking().isUnset()) {
			this.removeXmlChangeTracking();
		}
	}

	protected void removeXmlChangeTracking() {
		this.getXmlChangeTrackingHolder().setChangeTracking(null);
	}


	// ********** misc **********

	protected EclipseLinkOrmTypeMapping getTypeMapping() {
		return this.parent;
	}

	protected XmlTypeMapping getXmlTypeMapping() {
		return this.getTypeMapping().getXmlTypeMapping();
	}

	protected XmlChangeTrackingHolder getXmlChangeTrackingHolder() {
		return (XmlChangeTrackingHolder) this.getXmlTypeMapping();
	}

	protected EclipseLinkJavaTypeMapping getJavaTypeMappingForDefaults() {
		return this.getTypeMapping().getJavaTypeMappingForDefaults();
	}

	protected EclipseLinkChangeTracking getJavaChangeTrackingForDefaults() {
		EclipseLinkJavaTypeMapping javaTypeMapping = this.getJavaTypeMappingForDefaults();
		return (javaTypeMapping == null) ? null : javaTypeMapping.getChangeTracking();
	}


	// ********** validation **********

	public TextRange getValidationTextRange() {
		TextRange textRange = this.getXmlValidationTextRange();
		return (textRange != null) ? textRange : this.getTypeMapping().getValidationTextRange();
	}

	protected TextRange getXmlValidationTextRange() {
		XmlChangeTracking xmlChangeTracking = this.getXmlChangeTracking();
		return (xmlChangeTracking == null) ? null : xmlChangeTracking.getValidationTextRange();
	}
}

Back to the top