blob: 281cdfd50599bc8731c317a6f04161b74927d66d (
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
|
/*******************************************************************************
* 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.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaAttributeMapping;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkPrivateOwned;
import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkPrivateOwnedAnnotation;
public class JavaEclipseLinkPrivateOwned extends AbstractJavaJpaContextNode implements EclipseLinkPrivateOwned
{
protected boolean privateOwned;
protected JavaResourcePersistentAttribute resourcePersistentAttribute;
public JavaEclipseLinkPrivateOwned(JavaAttributeMapping parent) {
super(parent);
}
protected String getPrivateOwnedAnnotationName() {
return EclipseLinkPrivateOwnedAnnotation.ANNOTATION_NAME;
}
protected EclipseLinkPrivateOwnedAnnotation getResourcePrivateOwned() {
return (EclipseLinkPrivateOwnedAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(getPrivateOwnedAnnotationName());
}
protected void addResourcePrivateOwned() {
this.resourcePersistentAttribute.addSupportingAnnotation(getPrivateOwnedAnnotationName());
}
protected void removeResourcePrivateOwned() {
this.resourcePersistentAttribute.removeSupportingAnnotation(getPrivateOwnedAnnotationName());
}
public boolean isPrivateOwned() {
return this.privateOwned;
}
public void setPrivateOwned(boolean newPrivateOwned) {
if (this.privateOwned == newPrivateOwned) {
return;
}
boolean oldPrivateOwned = this.privateOwned;
this.privateOwned = newPrivateOwned;
if (newPrivateOwned) {
addResourcePrivateOwned();
}
else {
//have to check if annotation exists in case the change is from false to null or vice versa
if (getResourcePrivateOwned() != null) {
removeResourcePrivateOwned();
}
}
firePropertyChanged(PRIVATE_OWNED_PROPERTY, oldPrivateOwned, newPrivateOwned);
}
protected void setPrivateOwned_(boolean newPrivateOwned) {
boolean oldPrivateOwned = this.privateOwned;
this.privateOwned = newPrivateOwned;
firePropertyChanged(PRIVATE_OWNED_PROPERTY, oldPrivateOwned, newPrivateOwned);
}
public void initialize(JavaResourcePersistentAttribute jrpa) {
this.resourcePersistentAttribute = jrpa;
this.privateOwned = privateOwned();
}
public void update(JavaResourcePersistentAttribute jrpa) {
this.resourcePersistentAttribute = jrpa;
this.setPrivateOwned_(privateOwned());
}
private boolean privateOwned() {
return getResourcePrivateOwned() != null;
}
public TextRange getValidationTextRange(CompilationUnit astRoot) {
EclipseLinkPrivateOwnedAnnotation resourcePrivateOwned = this.getResourcePrivateOwned();
return resourcePrivateOwned == null ? null : resourcePrivateOwned.getTextRange(astRoot);
}
}
|