diff options
author | kmoore | 2010-03-24 18:09:18 +0000 |
---|---|---|
committer | kmoore | 2010-03-24 18:09:18 +0000 |
commit | 7eca507d9b980754c1d8c823dab99553b04e7a69 (patch) | |
tree | 968fd52f90c9f56dca93f14aa6d137cac95a1e02 | |
parent | 1688c45a12e9165f1908cc56f9ed49d03dce4fe1 (diff) | |
download | webtools.dali-7eca507d9b980754c1d8c823dab99553b04e7a69.tar.gz webtools.dali-7eca507d9b980754c1d8c823dab99553b04e7a69.tar.xz webtools.dali-7eca507d9b980754c1d8c823dab99553b04e7a69.zip |
297531 - added just enough support for ClassExtractor to make sure we don't have an error message for DiscriminatorColumn if the ClassExtractor is specified
9 files changed, 514 insertions, 6 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java index 2d5b00846f..9300e417f4 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java @@ -25,6 +25,7 @@ import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkConverterHol import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEntity; import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkEntityPrimaryKeyValidator; import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -105,7 +106,20 @@ public class JavaEclipseLinkEntityImpl this.changeTracking.update(jrpt); } + @Override + protected boolean buildSpecifiedDiscriminatorColumnIsAllowed() { + return super.buildSpecifiedDiscriminatorColumnIsAllowed() && !classExtractorIsUsed(); + } + + protected boolean classExtractorIsUsed() { + return getClassExtractorAnnotation() != null; + } + protected EclipseLinkClassExtractorAnnotation2_1 getClassExtractorAnnotation() { + return (EclipseLinkClassExtractorAnnotation2_1) + getResourcePersistentType().getAnnotation(EclipseLinkClassExtractorAnnotation2_1.ANNOTATION_NAME); + } + //********** Validation ******************************************** @Override diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java index 7f7e4e4e45..51c8150ee6 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java @@ -16,6 +16,8 @@ import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEntity; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheable2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheableHolder2_0; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.core.resource.orm.XmlClassReference; import org.eclipse.jpt.core.resource.orm.v2_0.XmlCacheable_2_0; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkChangeTracking; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkCustomizer; @@ -32,6 +34,7 @@ import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConvertersHolder; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCustomizerHolder; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlReadOnly; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -97,7 +100,29 @@ public class OrmEclipseLinkEntityImpl public boolean calculateDefaultCacheable() { return ((CacheableHolder2_0) getCaching()).calculateDefaultCacheable(); } + + + @Override + protected boolean buildSpecifiedDiscriminatorColumnIsAllowed() { + return super.buildSpecifiedDiscriminatorColumnIsAllowed() && !classExtractorIsUsed(); + } + + protected boolean classExtractorIsUsed() { + return getResourceClassExtractor() != null || getClassExtractorAnnotation() != null; + } + protected XmlClassReference getResourceClassExtractor() { + return getResourceTypeMapping().getClassExtractor(); + } + + protected EclipseLinkClassExtractorAnnotation2_1 getClassExtractorAnnotation() { + if (getJavaEntityForDefaults() != null) { + JavaResourcePersistentType jrpt = getJavaPersistentType().getResourcePersistentType(); + return (EclipseLinkClassExtractorAnnotation2_1) jrpt.getAnnotation(EclipseLinkClassExtractorAnnotation2_1.ANNOTATION_NAME); + } + return null; + } + // **************** resource-context interaction *************************** @Override diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaAnnotationDefinitionProvider.java new file mode 100644 index 0000000000..fb885ff4f8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaAnnotationDefinitionProvider.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * 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.eclipselink.core.internal.v2_1; + +import java.util.List; +import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; +import org.eclipse.jpt.core.internal.AbstractJpaAnnotationDefintionProvider; +import org.eclipse.jpt.core.resource.java.AnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkBasicCollectionAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkBasicMapAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkCacheAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkChangeTrackingAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkConvertAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkConverterAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkCustomizerAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkExistenceCheckingAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkJoinFetchAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkMutableAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkObjectTypeConverterAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkPrimaryKeyAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkPrivateOwnedAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkReadOnlyAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkReadTransformerAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkStructConverterAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkTransformationAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkTypeConverterAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkVariableOneToOneAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.resource.java.EclipseLinkWriteTransformerAnnotationDefinition; +import org.eclipse.jpt.eclipselink.core.internal.v2_1.resource.java.EclipseLinkClassExtractor2_1AnnotationDefinition; + +/** + * Provides annotations for 1.0 EclipseLink platform + */ +public class EclipseLink2_1JpaAnnotationDefinitionProvider + extends AbstractJpaAnnotationDefintionProvider +{ + // singleton + private static final JpaAnnotationDefinitionProvider INSTANCE = + new EclipseLink2_1JpaAnnotationDefinitionProvider(); + + + /** + * Return the singleton + */ + public static JpaAnnotationDefinitionProvider instance() { + return INSTANCE; + } + + + /** + * Enforce singleton usage + */ + private EclipseLink2_1JpaAnnotationDefinitionProvider() { + super(); + } + + + @Override + protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + definitions.add(EclipseLinkCacheAnnotationDefinition.instance()); + definitions.add(EclipseLinkChangeTrackingAnnotationDefinition.instance()); + definitions.add(EclipseLinkClassExtractor2_1AnnotationDefinition.instance()); + definitions.add(EclipseLinkConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkCustomizerAnnotationDefinition.instance()); + definitions.add(EclipseLinkExistenceCheckingAnnotationDefinition.instance()); + definitions.add(EclipseLinkObjectTypeConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkPrimaryKeyAnnotationDefinition.instance()); + definitions.add(EclipseLinkReadOnlyAnnotationDefinition.instance()); + definitions.add(EclipseLinkStructConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkTypeConverterAnnotationDefinition.instance()); + } + + @Override + protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + definitions.add(EclipseLinkBasicCollectionAnnotationDefinition.instance()); + definitions.add(EclipseLinkBasicMapAnnotationDefinition.instance()); + definitions.add(EclipseLinkConvertAnnotationDefinition.instance()); + definitions.add(EclipseLinkConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkJoinFetchAnnotationDefinition.instance()); + definitions.add(EclipseLinkMutableAnnotationDefinition.instance()); + definitions.add(EclipseLinkObjectTypeConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkPrivateOwnedAnnotationDefinition.instance()); + definitions.add(EclipseLinkReadTransformerAnnotationDefinition.instance()); + definitions.add(EclipseLinkStructConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkTransformationAnnotationDefinition.instance()); + definitions.add(EclipseLinkTypeConverterAnnotationDefinition.instance()); + definitions.add(EclipseLinkVariableOneToOneAnnotationDefinition.instance()); + definitions.add(EclipseLinkWriteTransformerAnnotationDefinition.instance()); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaPlatformFactory.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaPlatformFactory.java index 001602b88d..b590d04ec2 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaPlatformFactory.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/EclipseLink2_1JpaPlatformFactory.java @@ -10,9 +10,12 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.v2_1; +import org.eclipse.jpt.core.JpaAnnotationProvider; import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider; import org.eclipse.jpt.core.internal.GenericJpaPlatform; +import org.eclipse.jpt.core.internal.jpa2.Generic2_0JpaAnnotationDefinitionProvider; import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaPlatformFactory.EclipseLinkVersion; import org.eclipse.jpt.eclipselink.core.internal.v2_0.EclipseLink2_0JpaFactory; @@ -47,12 +50,12 @@ public class EclipseLink2_1JpaPlatformFactory JptCorePlugin.JPA_FACET_VERSION_2_0); } -// @Override -// protected JpaAnnotationProvider buildJpaAnnotationProvider() { -// return new GenericJpaAnnotationProvider( -// Generic2_0JpaAnnotationDefinitionProvider.instance(), -// EclipseLinkJpaAnnotationDefinitionProvider.instance()); -// } + @Override + protected JpaAnnotationProvider buildJpaAnnotationProvider() { + return new GenericJpaAnnotationProvider( + Generic2_0JpaAnnotationDefinitionProvider.instance(), + EclipseLink2_1JpaAnnotationDefinitionProvider.instance()); + } // @Override // protected JpaPlatformVariation buildJpaVariation() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/EclipseLinkClassExtractor2_1AnnotationDefinition.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/EclipseLinkClassExtractor2_1AnnotationDefinition.java new file mode 100644 index 0000000000..8791add2f8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/EclipseLinkClassExtractor2_1AnnotationDefinition.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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.eclipselink.core.internal.v2_1.resource.java; + +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jpt.core.resource.java.Annotation; +import org.eclipse.jpt.core.resource.java.AnnotationDefinition; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.core.utility.jdt.Member; +import org.eclipse.jpt.core.utility.jdt.Type; +import org.eclipse.jpt.eclipselink.core.internal.v2_1.resource.java.binary.BinaryEclipseLinkClassExtractorAnnotation2_1; +import org.eclipse.jpt.eclipselink.core.internal.v2_1.resource.java.source.SourceEclipseLinkClassExtractorAnnotation2_1; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; + +/** + * org.eclipse.persistence.annotations.ClassExtractor + */ +public class EclipseLinkClassExtractor2_1AnnotationDefinition + implements AnnotationDefinition +{ + // singleton + private static final AnnotationDefinition INSTANCE = new EclipseLinkClassExtractor2_1AnnotationDefinition(); + + /** + * Return the singleton. + */ + public static AnnotationDefinition instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkClassExtractor2_1AnnotationDefinition() { + super(); + } + + public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) { + return new SourceEclipseLinkClassExtractorAnnotation2_1((JavaResourcePersistentType) parent, (Type) member); + } + + public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) { + throw new UnsupportedOperationException(); + } + + public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation jdtAnnotation) { + return new BinaryEclipseLinkClassExtractorAnnotation2_1((JavaResourcePersistentType) parent, jdtAnnotation); + } + + public String getAnnotationName() { + return EclipseLinkClassExtractorAnnotation2_1.ANNOTATION_NAME; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/binary/BinaryEclipseLinkClassExtractorAnnotation2_1.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/binary/BinaryEclipseLinkClassExtractorAnnotation2_1.java new file mode 100644 index 0000000000..df99233a42 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/binary/BinaryEclipseLinkClassExtractorAnnotation2_1.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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.eclipselink.core.internal.v2_1.resource.java.binary; + +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLink2_1; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; + +/** + * org.eclipse.persistence.annotations.ClassExtractor + */ +public final class BinaryEclipseLinkClassExtractorAnnotation2_1 + extends BinaryAnnotation + implements EclipseLinkClassExtractorAnnotation2_1 +{ + private String value; + + + public BinaryEclipseLinkClassExtractorAnnotation2_1(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { + super(parent, jdtAnnotation); + this.value = this.buildValue(); + } + + public String getAnnotationName() { + return ANNOTATION_NAME; + } + + @Override + public void update() { + super.update(); + this.setValue_(this.buildValue()); + } + + + // ********** EclipseLinkClassExtractorAnnotation2_1 implementation ********** + + // ***** value + public String getValue() { + return this.value; + } + + public void setValue(String value) { + throw new UnsupportedOperationException(); + } + + private void setValue_(String value) { + String old = this.value; + this.value = value; + this.firePropertyChanged(VALUE_PROPERTY, old, value); + this.firePropertyChanged(FULLY_QUALIFIED_CLASS_NAME_PROPERTY, old, value); + } + + private String buildValue() { + return (String) this.getJdtMemberValue(EclipseLink2_1.CLASS_EXTRACTOR__VALUE); + } + + public TextRange getValueTextRange(CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } + + // ***** fully-qualified class name + /** + * binary is already fully-qualified + */ + public String getFullyQualifiedClassName() { + return this.value; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/source/SourceEclipseLinkClassExtractorAnnotation2_1.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/source/SourceEclipseLinkClassExtractorAnnotation2_1.java new file mode 100644 index 0000000000..597d14f88f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_1/resource/java/source/SourceEclipseLinkClassExtractorAnnotation2_1.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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.eclipselink.core.internal.v2_1.resource.java.source; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation; +import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; +import org.eclipse.jpt.core.internal.utility.jdt.ASTTools; +import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationElementAdapter; +import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; +import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; +import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; +import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; +import org.eclipse.jpt.core.utility.jdt.Type; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLink2_1; +import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; + +/** + * org.eclipse.persistence.annotations.ClassExtractor + */ + +public final class SourceEclipseLinkClassExtractorAnnotation2_1 + extends SourceAnnotation<Type> + implements EclipseLinkClassExtractorAnnotation2_1 +{ + private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME); + + private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(); + private final AnnotationElementAdapter<String> valueAdapter; + private String value; + + private String fullyQualifiedClassName; + + + public SourceEclipseLinkClassExtractorAnnotation2_1(JavaResourcePersistentType parent, Type type) { + super(parent, type, DECLARATION_ANNOTATION_ADAPTER); + this.valueAdapter = new MemberAnnotationElementAdapter<String>(type, VALUE_ADAPTER); + } + + public String getAnnotationName() { + return ANNOTATION_NAME; + } + + public void initialize(CompilationUnit astRoot) { + this.value = this.buildValue(astRoot); + this.fullyQualifiedClassName = this.buildFullyQualifiedClassName(astRoot); + } + + public void synchronizeWith(CompilationUnit astRoot) { + this.syncValue(this.buildValue(astRoot)); + this.syncFullyQualifiedClassName(this.buildFullyQualifiedClassName(astRoot)); + } + + @Override + public void toString(StringBuilder sb) { + sb.append(this.value); + } + + + // ********** EclipseLinkClassExtractorAnnotation2_1 implementation ********** + + // ***** value + public String getValue() { + return this.value; + } + + public void setValue(String value) { + if (this.attributeValueHasChanged(this.value, value)) { + this.value = value; + this.valueAdapter.setValue(value); + } + } + + private void syncValue(String astValue) { + String old = this.value; + this.value = astValue; + this.firePropertyChanged(VALUE_PROPERTY, old, astValue); + } + + private String buildValue(CompilationUnit astRoot) { + return this.valueAdapter.getValue(astRoot); + } + + public TextRange getValueTextRange(CompilationUnit astRoot) { + return this.getElementTextRange(VALUE_ADAPTER, astRoot); + } + + // ***** fully-qualified class name + public String getFullyQualifiedClassName() { + return this.fullyQualifiedClassName; + } + + private void syncFullyQualifiedClassName(String astFullyQualifiedClassName) { + String old = this.fullyQualifiedClassName; + this.fullyQualifiedClassName = astFullyQualifiedClassName; + this.firePropertyChanged(FULLY_QUALIFIED_CLASS_NAME_PROPERTY, old, astFullyQualifiedClassName); + } + + private String buildFullyQualifiedClassName(CompilationUnit astRoot) { + return (this.value == null) ? null : ASTTools.resolveFullyQualifiedName(this.valueAdapter.getExpression(astRoot)); + } + + + // ********** static methods ********** + + protected static DeclarationAnnotationElementAdapter<String> buildValueAdapter() { + return new ConversionDeclarationAnnotationElementAdapter<String>(DECLARATION_ANNOTATION_ADAPTER, EclipseLink2_1.CLASS_EXTRACTOR__VALUE, SimpleTypeStringExpressionConverter.instance()); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLink2_1.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLink2_1.java new file mode 100644 index 0000000000..cf87dbda02 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLink2_1.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.eclipselink.core.v2_0.resource.java; + +/** + * EclipseLink Java-related stuff (annotations etc.) + * + * 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.3 + * @since 2.3 + */ +@SuppressWarnings("nls") +public interface EclipseLink2_1 { + + // EclipseLink package + String PACKAGE = "org.eclipse.persistence.annotations"; //$NON-NLS-1$ + String PACKAGE_ = PACKAGE + "."; + + + // ********** API ********** + + // EclispeLink 2.1 annotations + String CLASS_EXTRACTOR = PACKAGE_ + "ClassExtractor"; + String CLASS_EXTRACTOR__VALUE = "value"; + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLinkClassExtractorAnnotation2_1.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLinkClassExtractorAnnotation2_1.java new file mode 100644 index 0000000000..580da8f0ee --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/v2_0/resource/java/EclipseLinkClassExtractorAnnotation2_1.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.eclipselink.core.v2_0.resource.java; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.resource.java.Annotation; +import org.eclipse.jpt.core.utility.TextRange; + +/** + * Corresponds to the EclipseLink annotation + * org.eclipse.persistence.annotations.Cache + * + * 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.3 + * @since 2.3 + */ +public interface EclipseLinkClassExtractorAnnotation2_1 + extends Annotation +{ + String ANNOTATION_NAME = EclipseLink2_1.CLASS_EXTRACTOR; + + /** + * Corresponds to the 'value' element of the ClassExtractor annotation. + * Return null if the element does not exist in Java. + * Return the portion of the value preceding ".class". + * <pre> + * @ClassExtractor(value=MyExtractor.class) + * </pre> + * will return "MyExtractor" + */ + String getValue(); + String VALUE_PROPERTY = "value"; //$NON-NLS-1$ + + /** + * Corresponds to the 'value' element of the ClassExtractor annotation. + * Set to null to remove the element. + * This will also remove the ClassExtractor annotation itself. + */ + void setValue(String value); + + /** + * Return the {@link TextRange} for the 'value' element. If the element + * does not exist return the {@link TextRange} for the ClassExtractor annotation. + */ + TextRange getValueTextRange(CompilationUnit astRoot); + + /** + * Return the fully-qualified ClassExtractor name as resolved by the AST's bindings. + * <pre> + * @ClassExtractor(MyExtractor.class) + * </pre> + * will return "model.MyExtractor" if there is an import for model.MyExtractor. + */ + String getFullyQualifiedClassName(); + String FULLY_QUALIFIED_CLASS_NAME_PROPERTY = "fullyQualifiedClassName"; //$NON-NLS-1$ + +} |