Skip to main content
summaryrefslogtreecommitdiffstats
blob: 02efc3c3781fe38c92c1242da25b6f19d55a5b36 (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
/*******************************************************************************
 * 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.Customizer;
import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCustomizer;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCustomizerHolder;

public class EclipseLinkOrmCustomizer extends AbstractXmlContextNode
	implements Customizer
{
	protected final XmlCustomizerHolder resource;
	
	protected String specifiedCustomizerClass;
	
	protected String defaultCustomizerClass;
	
	public EclipseLinkOrmCustomizer(OrmTypeMapping parent, XmlCustomizerHolder resource, Customizer javaCustomizer) {
		super(parent);
		this.resource = resource;
		this.defaultCustomizerClass = getJavaCustomizerClass(javaCustomizer);
		this.specifiedCustomizerClass = getResourceCustomizerClass();
	}
	
	public String getCustomizerClass() {
		return this.specifiedCustomizerClass == null ? this.defaultCustomizerClass : this.specifiedCustomizerClass;
	}
	
	public String getDefaultCustomizerClass() {
		return this.defaultCustomizerClass;
	}
	
	protected void setDefaultCustomizerClass(String newDefaultCustomizerClass) {
		String oldDefaultCustomizerClass = this.defaultCustomizerClass;
		this.defaultCustomizerClass = newDefaultCustomizerClass;
		firePropertyChanged(DEFAULT_CUSTOMIZER_CLASS_PROPERTY, oldDefaultCustomizerClass, newDefaultCustomizerClass);
	}
	
	public String getSpecifiedCustomizerClass() {
		return this.specifiedCustomizerClass;
	}
	
	public void setSpecifiedCustomizerClass(String newCustomizerClass) {
		String oldCustomizerClass = this.specifiedCustomizerClass;
		this.specifiedCustomizerClass = newCustomizerClass;
		if (oldCustomizerClass != newCustomizerClass) {
			if (this.getResourceCustomizer() != null) {
				this.getResourceCustomizer().setCustomizerClassName(newCustomizerClass);						
				if (this.getResourceCustomizer().isUnset()) {
					removeResourceCustomizer();
				}
			}
			else if (newCustomizerClass != null) {
				addResourceCustomizer();
				getResourceCustomizer().setCustomizerClassName(newCustomizerClass);
			}
		}
		firePropertyChanged(SPECIFIED_CUSTOMIZER_CLASS_PROPERTY, oldCustomizerClass, newCustomizerClass);
	}
	
	protected void setSpecifiedCustomizerClass_(String newCustomizerClass) {
		String oldCustomizerClass = this.specifiedCustomizerClass;
		this.specifiedCustomizerClass = newCustomizerClass;
		firePropertyChanged(SPECIFIED_CUSTOMIZER_CLASS_PROPERTY, oldCustomizerClass, newCustomizerClass);
	}
	
	protected XmlCustomizer getResourceCustomizer() {
		return this.resource.getCustomizer();
	}
	
	protected void addResourceCustomizer() {
		this.resource.setCustomizer(EclipseLinkOrmFactory.eINSTANCE.createXmlCustomizer());		
	}
	
	protected void removeResourceCustomizer() {
		this.resource.setCustomizer(null);
	}
	
	
	// **************** updating **************************************
	
	protected void update(Customizer javaCustomizer) {
		setDefaultCustomizerClass(getJavaCustomizerClass(javaCustomizer));
		setSpecifiedCustomizerClass_(getResourceCustomizerClass());
	}
	
	protected String getJavaCustomizerClass(Customizer javaCustomizer) {
		return (javaCustomizer == null) ? null : javaCustomizer.getCustomizerClass();
	}
	
	protected String getResourceCustomizerClass() {
		XmlCustomizer resource = getResourceCustomizer();
		return (resource == null) ? null : resource.getCustomizerClassName();
	}
	
	
	// **************** validation **************************************
	
	public TextRange getValidationTextRange() {
		XmlCustomizer resource = getResourceCustomizer();
		return resource == null ? null : resource.getCustomizerClassNameTextRange();
	}

}

Back to the top