Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 903cca49ef7dc4e263cc0e9b6c02962f309706ed (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
132
/*******************************************************************************
 * Copyright (c) 2008, 2013 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.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaContextModel;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkReadOnly;
import org.eclipse.jpt.jpa.eclipselink.core.context.java.EclipseLinkJavaNonEmbeddableTypeMapping;
import org.eclipse.jpt.jpa.eclipselink.core.resource.java.ReadOnlyAnnotation;

public class EclipseLinkJavaReadOnly
	extends AbstractJavaContextModel<EclipseLinkJavaNonEmbeddableTypeMapping>
	implements EclipseLinkReadOnly
{
	protected Boolean specifiedReadOnly;  // TRUE or null


	public EclipseLinkJavaReadOnly(EclipseLinkJavaNonEmbeddableTypeMapping 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 (ObjectTools.notEquals(readOnly, this.specifiedReadOnly)) {
			ReadOnlyAnnotation 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 ReadOnlyAnnotation getReadOnlyAnnotation() {
		return (ReadOnlyAnnotation) this.getJavaResourceType().getAnnotation(this.getReadOnlyAnnotationName());
	}

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

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

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


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


	protected EclipseLinkJavaNonEmbeddableTypeMapping getTypeMapping() {
		return this.parent;
	}

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

	protected JavaResourceType getJavaResourceType() {
		return this.getTypeMapping().getJavaResourceType();
	}


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

	public TextRange getValidationTextRange() {
		TextRange textRange = this.getAnnotationTextRange();
		return (textRange != null) ? textRange : this.getTypeMapping().getValidationTextRange();
	}

	protected TextRange getAnnotationTextRange() {
		ReadOnlyAnnotation annotation = this.getReadOnlyAnnotation();
		return (annotation == null) ? null : annotation.getTextRange();
	}
}

Back to the top