blob: d17d1400f007dcc188947275b466c6fe571792b0 (
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
|
/*******************************************************************************
* Copyright (c) 2007, 2015 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.core.internal.context.orm;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.JpaContextModel;
import org.eclipse.jpt.jpa.core.context.java.JavaGenerator;
import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator;
import org.eclipse.jpt.jpa.core.resource.orm.XmlGenerator;
import org.eclipse.jpt.jpa.core.validation.JptJpaCoreValidationMessages;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
* <code>orm.xml</code> sequence or table generator
*/
public abstract class AbstractOrmGenerator<X extends XmlGenerator>
extends AbstractOrmXmlContextModel<JpaContextModel>
implements OrmGenerator
{
protected final X xmlGenerator;
protected String name;
protected AbstractOrmGenerator(JpaContextModel parent, X xmlGenerator) {
super(parent);
this.xmlGenerator = xmlGenerator;
this.name = xmlGenerator.getName();
}
// ********** synchronize/update **********
@Override
public void synchronizeWithResourceModel(IProgressMonitor monitor) {
super.synchronizeWithResourceModel(monitor);
this.setName_(this.xmlGenerator.getName());
}
// ********** name **********
public String getName() {
return this.name;
}
public void setName(String name) {
this.setName_(name);
this.xmlGenerator.setName(name);
}
protected void setName_(String name) {
String old = this.name;
this.name = name;
this.firePropertyChanged(NAME_PROPERTY, old, name);
}
// ********** validation **********
public boolean supportsValidationMessages() {
return true;
}
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
if (StringTools.isBlank(this.name)){
messages.add(
this.buildValidationMessage(
this.getNameTextRange(),
JptJpaCoreValidationMessages.GENERATOR_NAME_UNDEFINED
)
);
}
}
public TextRange getValidationTextRange() {
TextRange textRange = this.xmlGenerator.getValidationTextRange();
return (textRange != null) ? textRange : this.parent.getValidationTextRange();
}
public TextRange getNameTextRange() {
return this.getValidationTextRange(this.xmlGenerator.getNameTextRange());
}
public boolean isEquivalentTo(Generator other) {
return (this != other) &&
(this.getGeneratorType() == other.getGeneratorType()) &&
this.isEquivalentTo_(other);
}
protected boolean isEquivalentTo_(Generator other) {
return ObjectTools.equals(this.name, other.getName());
}
// ********** metadata conversion **********
public void convertFrom(JavaGenerator javaGenerator) {
this.setName(javaGenerator.getName());
}
// ********** misc **********
public X getXmlGenerator() {
return this.xmlGenerator;
}
@Override
public void toString(StringBuilder sb) {
sb.append(this.name);
}
}
|