Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-09-03 17:23:51 +0000
committerkmoore2008-09-03 17:23:51 +0000
commit67938ff2bf1db843cd13ee6c398bfe167d5eef51 (patch)
tree0f929f2bbdc4bd44f2ef6964850bcb71a06a2372 /jpa
parent051e01c88041fe899f37ff0db52a2ae6336fe553 (diff)
downloadwebtools.dali-67938ff2bf1db843cd13ee6c398bfe167d5eef51.tar.gz
webtools.dali-67938ff2bf1db843cd13ee6c398bfe167d5eef51.tar.xz
webtools.dali-67938ff2bf1db843cd13ee6c398bfe167d5eef51.zip
eclipselink java resource model support for @Convert, @Converter, @TypeConverter, @StructConverter
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConvertImpl.java121
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConverterImpl.java153
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/StructConverterImpl.java152
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TypeConverterImpl.java185
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConvertAnnotation.java54
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConverterAnnotation.java73
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java26
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/StructConverterAnnotation.java73
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TypeConverterAnnotation.java92
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java106
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java157
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java157
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java209
15 files changed, 1570 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
index ccbf1ae06a..35192c6c13 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaAnnotationProvider.java
@@ -14,10 +14,14 @@ import java.util.List;
import org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider;
import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.CacheImpl.CacheAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.ConvertImpl.ConvertAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.ConverterImpl.ConverterAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.ExistenceCheckingImpl.ExistenceCheckingAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.MutableImpl.MutableAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.ReadTransformerImpl.ReadTransformerAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.StructConverterImpl.StructConverterAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.TransformationImpl.TransformationAnnotationDefinition;
+import org.eclipse.jpt.eclipselink.core.internal.resource.java.TypeConverterImpl.TypeConverterAnnotationDefinition;
import org.eclipse.jpt.eclipselink.core.internal.resource.java.WriteTransformerImpl.WriteTransformerAnnotationDefinition;
public class EclipseLinkJpaAnnotationProvider
@@ -41,8 +45,12 @@ public class EclipseLinkJpaAnnotationProvider
@Override
protected void addAttributeAnnotationDefinitionsTo(Collection<AnnotationDefinition> definitions) {
super.addAttributeAnnotationDefinitionsTo(definitions);
+ definitions.add(ConvertAnnotationDefinition.instance());
+ definitions.add(ConverterAnnotationDefinition.instance());
definitions.add(MutableAnnotationDefinition.instance());
definitions.add(ReadTransformerAnnotationDefinition.instance());
+ definitions.add(StructConverterAnnotationDefinition.instance());
+ definitions.add(TypeConverterAnnotationDefinition.instance());
definitions.add(WriteTransformerAnnotationDefinition.instance());
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConvertImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConvertImpl.java
new file mode 100644
index 0000000000..649195e290
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConvertImpl.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.StringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.ConvertAnnotation;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+
+
+public class ConvertImpl extends AbstractResourceAnnotation<Attribute> implements ConvertAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> valueAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter();
+
+
+ private String value;
+
+ protected ConvertImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.valueAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, VALUE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.value = this.value(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** Convert implementation ****************
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String newValue) {
+ if (attributeValueHasNotChanged(this.value, newValue)) {
+ return;
+ }
+ String oldValue = this.value;
+ this.value = newValue;
+ this.valueAdapter.setValue(newValue);
+ firePropertyChanged(VALUE_PROPERTY, oldValue, newValue);
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(VALUE_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setValue(this.value(astRoot));
+ }
+
+ protected String value(CompilationUnit astRoot) {
+ return this.valueAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.CONVERT__VALUE, false, StringExpressionConverter.instance());
+ }
+
+
+ public static class ConvertAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final ConvertAnnotationDefinition INSTANCE = new ConvertAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static ConvertAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private ConvertAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new ConvertImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConverterImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConverterImpl.java
new file mode 100644
index 0000000000..248500031b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/ConverterImpl.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.internal.utility.jdt.StringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.ConverterAnnotation;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+
+
+public class ConverterImpl extends AbstractResourceAnnotation<Attribute> implements ConverterAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private final AnnotationElementAdapter<String> converterClassAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> CONVERTER_CLASS_ADAPTER = buildConverterClassAdapter();
+
+
+ private String name;
+ private String converterClass;
+
+ protected ConverterImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, NAME_ADAPTER);
+ this.converterClassAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, CONVERTER_CLASS_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.name(astRoot);
+ this.converterClass = this.converterClass(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** Converter implementation ****************
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String newName) {
+ if (attributeValueHasNotChanged(this.name, newName)) {
+ return;
+ }
+ String oldName = this.name;
+ this.name = newName;
+ this.nameAdapter.setValue(newName);
+ firePropertyChanged(NAME_PROPERTY, oldName, newName);
+ }
+
+ public String getConverterClass() {
+ return this.converterClass;
+ }
+
+ public void setConverterClass(String newConverterClass) {
+ if (attributeValueHasNotChanged(this.converterClass, newConverterClass)) {
+ return;
+ }
+ String oldConverterClass = this.converterClass;
+ this.converterClass = newConverterClass;
+ this.converterClassAdapter.setValue(newConverterClass);
+ firePropertyChanged(CONVERTER_CLASS_PROPERTY, oldConverterClass, newConverterClass);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAME_ADAPTER, astRoot);
+ }
+
+ public TextRange getConverterClassTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(CONVERTER_CLASS_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setName(this.name(astRoot));
+ this.setConverterClass(this.converterClass(astRoot));
+ }
+
+ protected String name(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ protected String converterClass(CompilationUnit astRoot) {
+ return this.converterClassAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.CONVERTER__NAME, false, StringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildConverterClassAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.CONVERTER__CONVERTER_CLASS, false, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ public static class ConverterAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final ConverterAnnotationDefinition INSTANCE = new ConverterAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static ConverterAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private ConverterAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new ConverterImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/StructConverterImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/StructConverterImpl.java
new file mode 100644
index 0000000000..df479200bd
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/StructConverterImpl.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.StringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.StructConverterAnnotation;
+
+
+public class StructConverterImpl extends AbstractResourceAnnotation<Attribute> implements StructConverterAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private final AnnotationElementAdapter<String> converterAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> CONVERTER_ADAPTER = buildConverterAdapter();
+
+
+ private String name;
+ private String converter;
+
+ protected StructConverterImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, NAME_ADAPTER);
+ this.converterAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, CONVERTER_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.name(astRoot);
+ this.converter = this.converter(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** Converter implementation ****************
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String newName) {
+ if (attributeValueHasNotChanged(this.name, newName)) {
+ return;
+ }
+ String oldName = this.name;
+ this.name = newName;
+ this.nameAdapter.setValue(newName);
+ firePropertyChanged(NAME_PROPERTY, oldName, newName);
+ }
+
+ public String getConverter() {
+ return this.converter;
+ }
+
+ public void setConverter(String newConverter) {
+ if (attributeValueHasNotChanged(this.converter, newConverter)) {
+ return;
+ }
+ String oldConverter = this.converter;
+ this.converter = newConverter;
+ this.converterAdapter.setValue(newConverter);
+ firePropertyChanged(CONVERTER_PROPERTY, oldConverter, newConverter);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAME_ADAPTER, astRoot);
+ }
+
+ public TextRange getConverterTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(CONVERTER_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setName(this.name(astRoot));
+ this.setConverter(this.converter(astRoot));
+ }
+
+ protected String name(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ protected String converter(CompilationUnit astRoot) {
+ return this.converterAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.STRUCT_CONVERTER__NAME, false, StringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildConverterAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.STRUCT_CONVERTER__CONVERTER, false, StringExpressionConverter.instance());
+ }
+
+ public static class StructConverterAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final StructConverterAnnotationDefinition INSTANCE = new StructConverterAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static StructConverterAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private StructConverterAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new StructConverterImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TypeConverterImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TypeConverterImpl.java
new file mode 100644
index 0000000000..9c18ac077f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/java/TypeConverterImpl.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.AbstractResourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.internal.utility.jdt.StringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.TypeConverterAnnotation;
+
+
+public class TypeConverterImpl extends AbstractResourceAnnotation<Attribute> implements TypeConverterAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private final AnnotationElementAdapter<String> dataTypeAdapter;
+ private final AnnotationElementAdapter<String> objectTypeAdapter;
+
+ private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER = buildNameAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> DATA_TYPE_ADAPTER = buildDataTypeAdapter();
+ private static final DeclarationAnnotationElementAdapter<String> OBJECT_TYPE_ADAPTER = buildObjectTypeAdapter();
+
+
+ private String name;
+ private String dataType;
+ private String objectType;
+
+ protected TypeConverterImpl(JavaResourcePersistentAttribute parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, NAME_ADAPTER);
+ this.dataTypeAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, DATA_TYPE_ADAPTER);
+ this.objectTypeAdapter = new ShortCircuitAnnotationElementAdapter<String>(attribute, OBJECT_TYPE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.name(astRoot);
+ this.dataType = this.dataType(astRoot);
+ this.objectType = this.objectType(astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ //*************** TypeConverter implementation ****************
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String newName) {
+ if (attributeValueHasNotChanged(this.name, newName)) {
+ return;
+ }
+ String oldName = this.name;
+ this.name = newName;
+ this.nameAdapter.setValue(newName);
+ firePropertyChanged(NAME_PROPERTY, oldName, newName);
+ }
+
+ public String getDataType() {
+ return this.dataType;
+ }
+
+ public void setDataType(String newDataType) {
+ if (attributeValueHasNotChanged(this.dataType, newDataType)) {
+ return;
+ }
+ String oldDataType = this.dataType;
+ this.dataType = newDataType;
+ this.dataTypeAdapter.setValue(newDataType);
+ firePropertyChanged(DATA_TYPE_PROPERTY, oldDataType, newDataType);
+ }
+
+ public String getObjectType() {
+ return this.objectType;
+ }
+
+ public void setObjectType(String newObjectType) {
+ if (attributeValueHasNotChanged(this.objectType, newObjectType)) {
+ return;
+ }
+ String oldObjectType = this.objectType;
+ this.objectType = newObjectType;
+ this.objectTypeAdapter.setValue(newObjectType);
+ firePropertyChanged(OBJECT_TYPE_PROPERTY, oldObjectType, newObjectType);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAME_ADAPTER, astRoot);
+ }
+
+ public TextRange getDataTypeTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(DATA_TYPE_ADAPTER, astRoot);
+ }
+
+ public TextRange getObjectTypeTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(OBJECT_TYPE_ADAPTER, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setName(this.name(astRoot));
+ this.setDataType(this.dataType(astRoot));
+ this.setObjectType(this.objectType(astRoot));
+ }
+
+ protected String name(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ protected String dataType(CompilationUnit astRoot) {
+ return this.dataTypeAdapter.getValue(astRoot);
+ }
+
+ protected String objectType(CompilationUnit astRoot) {
+ return this.objectTypeAdapter.getValue(astRoot);
+ }
+
+ // ********** static methods **********
+ private static DeclarationAnnotationElementAdapter<String> buildNameAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.TYPE_CONVERTER__NAME, false, StringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildDataTypeAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.TYPE_CONVERTER__DATE_TYPE, false, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildObjectTypeAdapter() {
+ return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLinkJPA.TYPE_CONVERTER__OBJECT_TYPE, false, SimpleTypeStringExpressionConverter.instance());
+ }
+
+ public static class TypeConverterAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final TypeConverterAnnotationDefinition INSTANCE = new TypeConverterAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static TypeConverterAnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private TypeConverterAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return new TypeConverterImpl((JavaResourcePersistentAttribute) parent, (Attribute) member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return null;
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConvertAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConvertAnnotation.java
new file mode 100644
index 0000000000..d52a8368f9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConvertAnnotation.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.Convert
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface ConvertAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.CONVERT;
+
+
+ /**
+ * Corresponds to the value element of the Convert annotation.
+ * Returns null if the value element does not exist in java.
+ */
+ String getValue();
+
+ /**
+ * Corresponds to the value element of the Convert annotation.
+ * Set to null to remove the value element.
+ */
+ void setValue(String value);
+ String VALUE_PROPERTY = "valueProperty";
+
+ /**
+ * Return the {@link TextRange} for the value element. If the value element
+ * does not exist return the {@link TextRange} for the Convert annotation.
+ */
+ TextRange getValueTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConverterAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConverterAnnotation.java
new file mode 100644
index 0000000000..0afc11a5c9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/ConverterAnnotation.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.Converter
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface ConverterAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.CONVERTER;
+
+
+ /**
+ * Corresponds to the name element of the Converter annotation.
+ * Returns null if the name element does not exist in java.
+ */
+ String getName();
+
+ /**
+ * Corresponds to the name element of the Converter annotation.
+ * Set to null to remove the name element.
+ */
+ void setName(String value);
+ String NAME_PROPERTY = "nameProperty";
+
+ /**
+ * Corresponds to the converterClass element of the Converter annotation.
+ * Returns null if the converterClass element does not exist in java.
+ */
+ String getConverterClass();
+
+ /**
+ * Corresponds to the converterClass element of the Converter annotation.
+ * Set to null to remove the converterClass element.
+ */
+ void setConverterClass(String value);
+ String CONVERTER_CLASS_PROPERTY = "converterClassProperty";
+
+ /**
+ * Return the {@link TextRange} for the name element. If the name element
+ * does not exist return the {@link TextRange} for the Converter annotation.
+ */
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the converterClass element. If the converterClass element
+ * does not exist return the {@link TextRange} for the Converter annotation.
+ */
+ TextRange getConverterClassTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
index 985c7a7fe8..e049f9f6f8 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/EclipseLinkJPA.java
@@ -59,7 +59,17 @@ public interface EclipseLinkJPA {
String CACHE_COORDINATION_TYPE__SEND_NEW_OBJECTS_WITH_CHANGES = CACHE_COORDINATION_TYPE_ + "SEND_NEW_OBJECTS_WITH_CHANGES";
String CACHE_COORDINATION_TYPE__NONE = CACHE_COORDINATION_TYPE_ + "NONE";
+ String CONVERSION_VALUE = PACKAGE_ + "ConversionValue";
+ String CONVERSION_VALUE__DATA_VALUE = "dataValue";
+ String CONVERSION_VALUE__OBJECT_VALUE = "objectValue";
+ String CONVERT = PACKAGE_ + "Convert";
+ String CONVERT__VALUE = "value";
+
+ String CONVERTER = PACKAGE_ + "Converter";
+ String CONVERTER__NAME = "name";
+ String CONVERTER__CONVERTER_CLASS = "converterClass";
+
String EXISTENCE_CHECKING = PACKAGE_ + "ExistenceChecking";
String EXISTENCE_CHECKING__VALUE = "value";
@@ -73,10 +83,21 @@ public interface EclipseLinkJPA {
String MUTABLE = PACKAGE_ + "Mutable";
String MUTABLE__VALUE = "value";
+ String OBJECT_TYPE_CONVERTER = PACKAGE_ + "ObjectTypeConverter";
+ String OBJECT_TYPE_CONVERTER__NAME = "name";
+ String OBJECT_TYPE_CONVERTER__DATE_TYPE = "dataType";
+ String OBJECT_TYPE_CONVERTER__OBJECT_TYPE = "objectType";
+ String OBJECT_TYPE_CONVERTER__CONVERSION_VALUES = "conversionValues";
+ String OBJECT_TYPE_CONVERTER__DEFAULT_OBJECT_VALUE = "defaultObjectValue";
+
String READ_TRANSFORMER = PACKAGE_ + "ReadTransformer";
String READ_TRANSFORMER__TRANSFORMER_CLASS = "transformerClass";
String READ_TRANSFORMER__METHOD = "method";
+ String STRUCT_CONVERTER = PACKAGE_ + "StructConverter";
+ String STRUCT_CONVERTER__NAME = "name";
+ String STRUCT_CONVERTER__CONVERTER = "converter";
+
String TIME_OF_DAY = PACKAGE_ + "TimeOfDay";
String TIME_OF_DAY__HOUR = "hour";
String TIME_OF_DAY__MINUTE = "minute";
@@ -87,6 +108,11 @@ public interface EclipseLinkJPA {
String TRANSFORMATION__FETCH = "fetch";
String TRANSFORMATION__OPTIONAL = "optional";
+ String TYPE_CONVERTER = PACKAGE_ + "TypeConverter";
+ String TYPE_CONVERTER__NAME = "name";
+ String TYPE_CONVERTER__DATE_TYPE = "dataType";
+ String TYPE_CONVERTER__OBJECT_TYPE = "objectType";
+
String WRITE_TRANSFORMER = PACKAGE_ + "WriteTransformer";
String WRITE_TRANSFORMER__TRANSFORMER_CLASS = "transformerClass";
String WRITE_TRANSFORMER__METHOD = "method";
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/StructConverterAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/StructConverterAnnotation.java
new file mode 100644
index 0000000000..10148c2e23
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/StructConverterAnnotation.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.StructConverter
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface StructConverterAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.STRUCT_CONVERTER;
+
+
+ /**
+ * Corresponds to the name element of the StructConverter annotation.
+ * Returns null if the name element does not exist in java.
+ */
+ String getName();
+
+ /**
+ * Corresponds to the name element of the StructConverter annotation.
+ * Set to null to remove the name element.
+ */
+ void setName(String value);
+ String NAME_PROPERTY = "nameProperty";
+
+ /**
+ * Corresponds to the converter element of the StructConverter annotation.
+ * Returns null if the converter element does not exist in java.
+ */
+ String getConverter();
+
+ /**
+ * Corresponds to the converter element of the StructConverter annotation.
+ * Set to null to remove the converter element.
+ */
+ void setConverter(String value);
+ String CONVERTER_PROPERTY = "converterProperty";
+
+ /**
+ * Return the {@link TextRange} for the name element. If the name element
+ * does not exist return the {@link TextRange} for the StructConverter annotation.
+ */
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the converter element. If the converter element
+ * does not exist return the {@link TextRange} for the StructConverter annotation.
+ */
+ TextRange getConverterTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TypeConverterAnnotation.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TypeConverterAnnotation.java
new file mode 100644
index 0000000000..ff585971cf
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/java/TypeConverterAnnotation.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Java resource model interface that corresponds to the Eclipselink
+ * annotation org.eclipse.persistence.annotations.TypeConverter
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 2.1
+ * @since 2.1
+ */
+public interface TypeConverterAnnotation extends JavaResourceNode
+{
+
+ String ANNOTATION_NAME = EclipseLinkJPA.TYPE_CONVERTER;
+
+
+ /**
+ * Corresponds to the name element of the TypeConverter annotation.
+ * Returns null if the name element does not exist in java.
+ */
+ String getName();
+
+ /**
+ * Corresponds to the name element of the TypeConverter annotation.
+ * Set to null to remove the name element.
+ */
+ void setName(String value);
+ String NAME_PROPERTY = "nameProperty";
+
+ /**
+ * Corresponds to the dataType element of the TypeConverter annotation.
+ * Returns null if the dataType element does not exist in java.
+ */
+ String getDataType();
+
+ /**
+ * Corresponds to the dataType element of the TypeConverter annotation.
+ * Set to null to remove the dataType element.
+ */
+ void setDataType(String value);
+ String DATA_TYPE_PROPERTY = "dataTypeProperty";
+
+ /**
+ * Corresponds to the objectType element of the TypeConverter annotation.
+ * Returns null if the objectType element does not exist in java.
+ */
+ String getObjectType();
+
+ /**
+ * Corresponds to the objectType element of the TypeConverter annotation.
+ * Set to null to remove the objectType element.
+ */
+ void setObjectType(String value);
+ String OBJECT_TYPE_PROPERTY = "objectTypeProperty";
+
+ /**
+ * Return the {@link TextRange} for the name element. If the name element
+ * does not exist return the {@link TextRange} for the TypeConverter annotation.
+ */
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the dataType element. If the dataType element
+ * does not exist return the {@link TextRange} for the TypeConverter annotation.
+ */
+ TextRange getDataTypeTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the {@link TextRange} for the objectType element. If the objectType element
+ * does not exist return the {@link TextRange} for the TypeConverter annotation.
+ */
+ TextRange getObjectTypeTextRange(CompilationUnit astRoot);
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java
new file mode 100644
index 0000000000..b8d4e80782
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConvertAnnotationTests.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.ConvertAnnotation;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class ConvertAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public ConvertAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestConvert() throws Exception {
+ this.createAnnotationAndMembers("Convert", "String value() default \"none\"");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.CONVERT);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Convert");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestConverterWithValue() throws Exception {
+ this.createAnnotationAndMembers("Convert", "String value() default \"none\"");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.CONVERT);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Convert(value=\"myConverter\")");
+ }
+ });
+ }
+
+ public void testConvertAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestConvert();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.CONVERT);
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.CONVERT);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERT));
+ }
+
+ public void testGetValue() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT);
+ assertEquals("myConverter", convert.getValue());
+ }
+
+ public void testSetValue() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT);
+ assertEquals("myConverter", convert.getValue());
+
+ convert.setValue("Bar");
+ assertEquals("Bar", convert.getValue());
+
+ assertSourceContains("@Convert(value=\"Bar\")", cu);
+ }
+
+ public void testSetValueNull() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConvertAnnotation convert = (ConvertAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERT);
+ assertEquals("myConverter", convert.getValue());
+
+ convert.setValue(null);
+ assertNull(convert.getValue());
+
+ assertSourceContains("@Convert", cu);
+ assertSourceDoesNotContain("value", cu);
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java
new file mode 100644
index 0000000000..1a5e739548
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/ConverterAnnotationTests.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.ConverterAnnotation;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class ConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public ConverterAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestConverter() throws Exception {
+ this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Converter");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestConverterWithConverterClass() throws Exception {
+ this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Converter(converterClass=Foo.class)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestConverterWithName() throws Exception {
+ this.createAnnotationAndMembers("Converter", "String name(); Class converterClass()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@Converter(name=\"bar\")");
+ }
+ });
+ }
+
+ public void testConverterAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.CONVERTER);
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.CONVERTER);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER));
+ }
+
+ public void testGetConverterClass() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithConverterClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("Foo", converter.getConverterClass());
+ }
+
+ public void testSetConverterClass() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithConverterClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("Foo", converter.getConverterClass());
+
+ converter.setConverterClass("Bar");
+ assertEquals("Bar", converter.getConverterClass());
+
+ assertSourceContains("@Converter(converterClass=Bar.class)", cu);
+ }
+
+ public void testSetConverterClassNull() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithConverterClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("Foo", converter.getConverterClass());
+
+ converter.setConverterClass(null);
+ assertNull(converter.getConverterClass());
+
+ assertSourceContains("@Converter", cu);
+ assertSourceDoesNotContain("converterClass", cu);
+ }
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("bar", converter.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName("foo");
+ assertEquals("foo", converter.getName());
+
+ assertSourceContains("@Converter(name=\"foo\")", cu);
+ }
+
+ public void testSetNameNull() throws Exception {
+ ICompilationUnit cu = this.createTestConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ ConverterAnnotation converter = (ConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName(null);
+ assertNull(converter.getName());
+
+ assertSourceContains("@Converter", cu);
+ assertSourceDoesNotContain("name=", cu);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
index eddfef97e6..dee7bf9c8b 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/JptEclipseLinkCoreJavaResourceModelTests.java
@@ -22,11 +22,15 @@ public class JptEclipseLinkCoreJavaResourceModelTests {
TestSuite suite = new TestSuite(JptEclipseLinkCoreJavaResourceModelTests.class.getName());
suite.addTestSuite(CacheTests.class);
+ suite.addTestSuite(ConvertAnnotationTests.class);
+ suite.addTestSuite(ConverterAnnotationTests.class);
suite.addTestSuite(ExistenceCheckingTests.class);
suite.addTestSuite(MutableAnnotationTests.class);
suite.addTestSuite(ReadTransformerAnnotationTests.class);
+ suite.addTestSuite(StructConverterAnnotationTests.class);
suite.addTestSuite(TimeOfDayTests.class);
suite.addTestSuite(TransformationAnnotationTests.class);
+ suite.addTestSuite(TypeConverterAnnotationTests.class);
suite.addTestSuite(WriteTransformerAnnotationTests.class);
return suite;
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java
new file mode 100644
index 0000000000..6028ac9c26
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/StructConverterAnnotationTests.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.StructConverterAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class StructConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public StructConverterAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestStructConverter() throws Exception {
+ this.createAnnotationAndMembers("StructConverter", "String name(); String converter()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@StructConverter");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestStructConverterWithConverter() throws Exception {
+ this.createAnnotationAndMembers("StructConverter", "String name(); String converter()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@StructConverter(converter=\"Foo\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestStructConverterWithName() throws Exception {
+ this.createAnnotationAndMembers("StructConverter", "String name(); String converter()");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.STRUCT_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@StructConverter(name=\"bar\")");
+ }
+ });
+ }
+
+ public void testStructConverterAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER));
+ }
+
+ public void testGetConverter() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("Foo", converter.getConverter());
+ }
+
+ public void testSetConverter() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("Foo", converter.getConverter());
+
+ converter.setConverter("Bar");
+ assertEquals("Bar", converter.getConverter());
+
+ assertSourceContains("@StructConverter(converter=\"Bar\")", cu);
+ }
+
+ public void testSetConverterNull() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("Foo", converter.getConverter());
+
+ converter.setConverter(null);
+ assertNull(converter.getConverter());
+
+ assertSourceContains("@StructConverter", cu);
+ assertSourceDoesNotContain("converter", cu);
+ }
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("bar", converter.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName("foo");
+ assertEquals("foo", converter.getName());
+
+ assertSourceContains("@StructConverter(name=\"foo\")", cu);
+ }
+
+ public void testSetNameNull() throws Exception {
+ ICompilationUnit cu = this.createTestStructConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ StructConverterAnnotation converter = (StructConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.STRUCT_CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName(null);
+ assertNull(converter.getName());
+
+ assertSourceContains("@StructConverter", cu);
+ assertSourceDoesNotContain("name=", cu);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java
new file mode 100644
index 0000000000..50c4ed90f2
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/TypeConverterAnnotationTests.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.resource.java;
+
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA;
+import org.eclipse.jpt.eclipselink.core.resource.java.TypeConverterAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+public class TypeConverterAnnotationTests extends EclipseLinkJavaResourceModelTestCase {
+
+ public TypeConverterAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestTypeConverter() throws Exception {
+ this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class ");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@TypeConverter");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestTypeConverterWithDataType() throws Exception {
+ this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class ");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@TypeConverter(dataType=Foo.class)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestTypeConverterWithObjectType() throws Exception {
+ this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class ");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@TypeConverter(objectType=Foo.class)");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestTypeConverterWithName() throws Exception {
+ this.createAnnotationAndMembers("TypeConverter", "String name(); Class dataType() default void.class; Class objectType() default void.class ");
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(EclipseLinkJPA.TYPE_CONVERTER);
+ }
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append("@TypeConverter(name=\"bar\")");
+ }
+ });
+ }
+
+ public void testTypeConverterAnnotation() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverter();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER));
+
+ attributeResource.removeAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER));
+
+ attributeResource.addAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertNotNull(attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER));
+ }
+
+ public void testGetTypeDataType() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithDataType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getDataType());
+ }
+
+ public void testSetDataType() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithDataType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getDataType());
+
+ converter.setDataType("Bar");
+ assertEquals("Bar", converter.getDataType());
+
+ assertSourceContains("@TypeConverter(dataType=Bar.class)", cu);
+ }
+
+ public void testSetDataTypeNull() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithDataType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getDataType());
+
+ converter.setDataType(null);
+ assertNull(converter.getDataType());
+
+ assertSourceContains("@TypeConverter", cu);
+ assertSourceDoesNotContain("dataType", cu);
+ }
+
+ public void testGetTypeObjectType() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithObjectType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getObjectType());
+ }
+
+ public void testSetObjectType() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithObjectType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getObjectType());
+
+ converter.setObjectType("Bar");
+ assertEquals("Bar", converter.getObjectType());
+
+ assertSourceContains("@TypeConverter(objectType=Bar.class)", cu);
+ }
+
+ public void testSetObjectTypeNull() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithObjectType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("Foo", converter.getObjectType());
+
+ converter.setObjectType(null);
+ assertNull(converter.getObjectType());
+
+ assertSourceContains("@TypeConverter", cu);
+ assertSourceDoesNotContain("objectType", cu);
+ }
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("bar", converter.getName());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName("foo");
+ assertEquals("foo", converter.getName());
+
+ assertSourceContains("@TypeConverter(name=\"foo\")", cu);
+ }
+
+ public void testSetNameNull() throws Exception {
+ ICompilationUnit cu = this.createTestTypeConverterWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+ JavaResourcePersistentAttribute attributeResource = typeResource.fields().next();
+
+ TypeConverterAnnotation converter = (TypeConverterAnnotation) attributeResource.getAnnotation(EclipseLinkJPA.TYPE_CONVERTER);
+ assertEquals("bar", converter.getName());
+
+ converter.setName(null);
+ assertNull(converter.getName());
+
+ assertSourceContains("@TypeConverter", cu);
+ assertSourceDoesNotContain("name=", cu);
+ }
+}

Back to the top