Skip to main content
summaryrefslogtreecommitdiffstats
blob: 30d07531b9375404710535ae79828bdff3a89e7f (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
/*******************************************************************************
 * Copyright (c) 2008, 2010 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.java;

import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkReadOnly;
import org.eclipse.jpt.jpa.eclipselink.core.context.java.JavaEclipseLinkNonEmbeddableTypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.resource.java.EclipseLinkReadOnlyAnnotation;

public class JavaEclipseLinkReadOnly
	extends AbstractJavaJpaContextNode
	implements EclipseLinkReadOnly
{
	protected Boolean specifiedReadOnly;  // TRUE or null


	public JavaEclipseLinkReadOnly(JavaEclipseLinkNonEmbeddableTypeMapping parent) {
		super(parent);
		this.specifiedReadOnly = this.buildSpecifiedReadOnly();
	}


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

	@Override
	public void synchronizeWithResourceModel() {
		super.synchronizeWithResourceModel();
		this.setSpecifiedReadOnly_(this.buildSpecifiedReadOnly());
	}


	// ********** read-only **********

	public boolean isReadOnly() {
		return (this.specifiedReadOnly != null) ? this.specifiedReadOnly.booleanValue() : this.isDefaultReadOnly();
	}

	public Boolean getSpecifiedReadOnly() {
		return this.specifiedReadOnly;
	}

	public void setSpecifiedReadOnly(Boolean readOnly) {
		readOnly = (readOnly == null) ? null : readOnly.booleanValue() ? readOnly : null;
		if (this.valuesAreDifferent(readOnly, this.specifiedReadOnly)) {
			EclipseLinkReadOnlyAnnotation annotation = this.getReadOnlyAnnotation();
			if (readOnly != null) {
				if (annotation == null) {
					this.addReadOnlyAnnotation();
				}
			} else {
				if (annotation != null) {
					this.removeReadOnlyAnnotation();
				}
			}

			this.setSpecifiedReadOnly_(readOnly);
		}
	}

	protected void setSpecifiedReadOnly_(Boolean readOnly) {
		Boolean old = this.specifiedReadOnly;
		this.specifiedReadOnly = readOnly;
		this.firePropertyChanged(SPECIFIED_READ_ONLY_PROPERTY, old, readOnly);
	}

	private Boolean buildSpecifiedReadOnly() {
		return (this.getReadOnlyAnnotation() == null) ? null : Boolean.TRUE;
	}

	public boolean isDefaultReadOnly() {
		return DEFAULT_READ_ONLY;
	}


	// ********** read-only annotation **********

	protected EclipseLinkReadOnlyAnnotation getReadOnlyAnnotation() {
		return (EclipseLinkReadOnlyAnnotation) this.getResourcePersistentType().getAnnotation(this.getReadOnlyAnnotationName());
	}

	protected void addReadOnlyAnnotation() {
		this.getResourcePersistentType().addAnnotation(this.getReadOnlyAnnotationName());
	}

	protected void removeReadOnlyAnnotation() {
		this.getResourcePersistentType().removeAnnotation(this.getReadOnlyAnnotationName());
	}

	protected String getReadOnlyAnnotationName() {
		return EclipseLinkReadOnlyAnnotation.ANNOTATION_NAME;
	}


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

	@Override
	public JavaEclipseLinkNonEmbeddableTypeMapping getParent() {
		return (JavaEclipseLinkNonEmbeddableTypeMapping) super.getParent();
	}

	protected JavaEclipseLinkNonEmbeddableTypeMapping getTypeMapping() {
		return this.getParent();
	}

	protected JavaPersistentType getPersistentType() {
		return this.getTypeMapping().getPersistentType();
	}

	protected JavaResourcePersistentType getResourcePersistentType() {
		return this.getTypeMapping().getResourcePersistentType();
	}


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

	public TextRange getValidationTextRange(CompilationUnit astRoot) {
		EclipseLinkReadOnlyAnnotation annotation = this.getReadOnlyAnnotation();
		return (annotation == null) ? null : annotation.getTextRange(astRoot);
	}
}

Back to the top