Skip to main content
summaryrefslogtreecommitdiffstats
blob: 42c7470dab16c7fef6b7c1f59a7b46c79f8f0edd (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
/*******************************************************************************
 *  Copyright (c) 2008, 2009  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.context.orm;

import org.eclipse.jpt.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.eclipselink.core.context.ChangeTracking;
import org.eclipse.jpt.eclipselink.core.context.ChangeTrackingType;
import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTracking;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingHolder;

public class EclipseLinkOrmChangeTracking extends AbstractXmlContextNode
	implements ChangeTracking
{
	protected final XmlChangeTrackingHolder resource;
	
	protected ChangeTrackingType defaultType;
	
	protected ChangeTrackingType specifiedType;
	
	
	public EclipseLinkOrmChangeTracking(OrmTypeMapping parent, XmlChangeTrackingHolder resource, ChangeTracking javaChangeTracking) {
		super(parent);
		this.resource = resource;
		this.defaultType = calculateDefaultType(javaChangeTracking);
		this.specifiedType = getResourceChangeTracking();
	}
	
	
	public ChangeTrackingType getType() {
		return (getSpecifiedType() != null) ? getSpecifiedType() : getDefaultType();
	}
	
	public ChangeTrackingType getDefaultType() {
		return this.defaultType;
	}
	
	protected void setDefaultType_(ChangeTrackingType newDefaultType) {
		ChangeTrackingType oldDefaultType = this.defaultType;
		this.defaultType = newDefaultType;
		firePropertyChanged(DEFAULT_TYPE_PROPERTY, oldDefaultType, newDefaultType);
	}
	
	public ChangeTrackingType getSpecifiedType() {
		return this.specifiedType;
	}
	
	public void setSpecifiedType(ChangeTrackingType newSpecifiedType) {
		ChangeTrackingType oldSpecifiedType = this.specifiedType;
		this.specifiedType = newSpecifiedType;
		
		if (newSpecifiedType == null) {
			this.resource.setChangeTracking(null);
		}
		else {
			if (this.resource.getChangeTracking() == null) {
				this.resource.setChangeTracking(EclipseLinkOrmFactory.eINSTANCE.createXmlChangeTracking());
			}
			this.resource.getChangeTracking().setType(ChangeTrackingType.toOrmResourceModel(newSpecifiedType));
		}
		
		firePropertyChanged(SPECIFIED_TYPE_PROPERTY, oldSpecifiedType, newSpecifiedType);
	}
	
	protected void setSpecifiedType_(ChangeTrackingType newSpecifiedType) {
		ChangeTrackingType oldSpecifiedType = this.specifiedType;
		this.specifiedType = newSpecifiedType;
		firePropertyChanged(SPECIFIED_TYPE_PROPERTY, oldSpecifiedType, newSpecifiedType);
	}
	
	
	// **************** updating **************************************
	
	protected void update(ChangeTracking javaChangeTracking) {
		setDefaultType_(calculateDefaultType(javaChangeTracking));
		setSpecifiedType_(getResourceChangeTracking());
	}
	
	protected ChangeTrackingType calculateDefaultType(ChangeTracking javaChangeTracking) {
		return (javaChangeTracking != null) ? javaChangeTracking.getType() : ChangeTracking.DEFAULT_TYPE;
	}
	
	protected ChangeTrackingType getResourceChangeTracking() {
		XmlChangeTracking xmlChangeTracking = this.resource.getChangeTracking();
		return (xmlChangeTracking != null) ? ChangeTrackingType.fromOrmResourceModel(xmlChangeTracking.getType()) : null;
	}
	
	
	// **************** validation **************************************
	
	public TextRange getValidationTextRange() {
		return this.resource.getValidationTextRange();
	}
}

Back to the top