blob: d43101901b91ec04221c0521d309abc08a7c0f44 (
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) 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.jaxb.core.internal.context.java;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant;
import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant;
import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumAnnotation;
public class GenericJavaPersistentEnum
extends AbstractJavaPersistentType
implements JaxbPersistentEnum {
protected String enumType;
protected final EnumConstantContainer enumConstantContainer;
public GenericJavaPersistentEnum(JaxbContextRoot parent, JavaResourceEnum resourceEnum) {
super(parent, resourceEnum);
this.enumType = this.getResourceEnumType();
this.enumConstantContainer = new EnumConstantContainer();
}
@Override
public JavaResourceEnum getJavaResourceType() {
return (JavaResourceEnum) super.getJavaResourceType();
}
// ********** JaxbType impl **********
public Kind getKind() {
return Kind.PERSISTENT_ENUM;
}
// ********** synchronize/update **********
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
this.setEnumType_(this.getResourceEnumType());
this.enumConstantContainer.synchronizeWithResourceModel();
}
@Override
public void update() {
super.update();
this.enumConstantContainer.update();
}
// ********** xml enum annotation **********
protected XmlEnumAnnotation getXmlEnumAnnotation() {
return (XmlEnumAnnotation) this.getJavaResourceType().getNonNullAnnotation(XmlEnumAnnotation.ANNOTATION_NAME);
}
// ********** JaxbPersistentEnum impl **********
// ********** enum type **********
public String getEnumType() {
return this.enumType;
}
public void setEnumType(String enumType) {
this.getXmlEnumAnnotation().setValue(enumType);
this.setEnumType_(enumType);
}
protected void setEnumType_(String enumType) {
String old = this.enumType;
this.enumType = enumType;
this.firePropertyChanged(ENUM_TYPE_PROPERTY, old, enumType);
}
protected String getResourceEnumType() {
return this.getXmlEnumAnnotation().getValue();
}
public Iterable<JaxbEnumConstant> getEnumConstants() {
return this.enumConstantContainer.getContextElements();
}
public int getEnumConstantsSize() {
return this.enumConstantContainer.getContextElementsSize();
}
private Iterable<JavaResourceEnumConstant> getResourceEnumConstants() {
return getJavaResourceType().getEnumConstants();
}
private JaxbEnumConstant buildEnumConstant(JavaResourceEnumConstant resourceEnumConstant) {
return getFactory().buildJavaEnumConstant(this, resourceEnumConstant);
}
/**
* enum constant container adapter
*/
protected class EnumConstantContainer
extends ContextCollectionContainer<JaxbEnumConstant, JavaResourceEnumConstant>
{
@Override
protected String getContextElementsPropertyName() {
return ENUM_CONSTANTS_COLLECTION;
}
@Override
protected JaxbEnumConstant buildContextElement(JavaResourceEnumConstant resourceElement) {
return GenericJavaPersistentEnum.this.buildEnumConstant(resourceElement);
}
@Override
protected Iterable<JavaResourceEnumConstant> getResourceElements() {
return GenericJavaPersistentEnum.this.getResourceEnumConstants();
}
@Override
protected JavaResourceEnumConstant getResourceElement(JaxbEnumConstant contextElement) {
return contextElement.getResourceEnumConstant();
}
}
}
|