diff options
author | pfullbright | 2011-12-16 17:28:56 +0000 |
---|---|---|
committer | pfullbright | 2011-12-16 17:28:56 +0000 |
commit | b257df9bc56cbea390f8e0c8b0155b95f4edb470 (patch) | |
tree | a4c40ba5fbc135c11ed277fe8ac5c7265c0d7e80 | |
parent | 0392217eb63725afc789143fea1545780a1d70d2 (diff) | |
download | webtools.dali-b257df9bc56cbea390f8e0c8b0155b95f4edb470.tar.gz webtools.dali-b257df9bc56cbea390f8e0c8b0155b95f4edb470.tar.xz webtools.dali-b257df9bc56cbea390f8e0c8b0155b95f4edb470.zip |
XmlInverseReference validation and XmlPath annotation support
18 files changed, 729 insertions, 9 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF index 10ca8c5872..97a0691986 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)", org.eclipse.jpt.jaxb.core;bundle-version="[1.0.0,2.0.0)", org.eclipse.jst.common.project.facet.core;bundle-version="[1.4.200,2.0.0)", org.eclipse.jst.j2ee;bundle-version="[1.1.500,2.0.0)", + org.eclipse.wst.common.project.facet.core;bundle-version="[1.4.200,2.0.0)", org.eclipse.wst.validation;bundle-version="[1.2.300,2.0.0)" Export-Package: org.eclipse.jpt.jaxb.eclipselink.core, org.eclipse.jpt.jaxb.eclipselink.core.internal;x-internal:=true, diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties index cd71550835..4128f96b2a 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/property_files/el_jaxb_validation.properties @@ -8,4 +8,8 @@ # Oracle - initial API and implementation ############################################################################### -PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY = Project is missing a jaxb.properties file specifying the EclipseLink JAXB context factory
\ No newline at end of file +PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY = Project is missing a jaxb.properties file specifying the EclipseLink JAXB context factory + +XML_INVERSE_REFERENCE__MAPPED_BY_NOT_SPECIFIED = The 'mappedBy' property must be specified on an XmlInverseReference. +XML_INVERSE_REFERENCE__MAPPED_BY_NOT_RESOLVED = Cannot resolve the attribute ''{0}'' on the class ''{1}''. +XML_INVERSE_REFERENCE__MAPPED_BY_NOT_XML_ELEMENT = The attribute ''{0}'' on the class ''{1}'' is not mapped to an XmlElement.
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/ELJaxbPlatform.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/ELJaxbPlatform.java index 0b168b98bc..d229bdafda 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/ELJaxbPlatform.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/ELJaxbPlatform.java @@ -9,9 +9,11 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.eclipselink.core; +import org.eclipse.jpt.jaxb.core.JaxbFacet; import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformGroupDescription; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; public class ELJaxbPlatform { @@ -30,7 +32,15 @@ public class ELJaxbPlatform { public static final JaxbPlatformDescription VERSION_2_4 = JptJaxbCorePlugin.getJaxbPlatformManager().getJaxbPlatform("eclipselink_2_4"); //$NON-NLS-1$ - + + + public static JaxbPlatformDescription getDefaultPlatform(IProjectFacetVersion jaxbVersion) { + if (jaxbVersion.equals(JaxbFacet.VERSION_2_1)) { + return VERSION_2_1; + } + return VERSION_2_4; + } + /** * Not for instantiation diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlInverseReferenceMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlInverseReferenceMapping.java new file mode 100644 index 0000000000..a9ea6091df --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlInverseReferenceMapping.java @@ -0,0 +1,39 @@ +package org.eclipse.jpt.jaxb.eclipselink.core.context.java; + +import org.eclipse.jpt.jaxb.core.context.JaxbAttributeMapping; + +/** + * Represents an EclipseLink XmlInverseReference attribute mapping in either + * java annotations or oxm file. + * + * 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 3.2 + * @since 3.2 + */ +public interface ELXmlInverseReferenceMapping + extends JaxbAttributeMapping { + + // ***** mappedBy ***** + + /** + * String associated with changes to the mappedBy property + */ + String MAPPED_BY_PROPERTY = "mappedBy"; ///$NON-NLS-1$ + + /** + * Return the mappedBy property value. + * A null indicates it is not specified. + */ + String getMappedBy(); + + /** + * Set the mappedBy property value. + * Setting to null will unspecify it. + */ + void setMappedBy(String mappedBy); +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlNamedNodeMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlNamedNodeMapping.java new file mode 100644 index 0000000000..6749c1ae3d --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/java/ELXmlNamedNodeMapping.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.eclipselink.core.context.java; + +import org.eclipse.jpt.jaxb.core.context.XmlNamedNodeMapping; + + +/** + * Common interface for ELXmlElementMapping and ELXmlAttributeMapping + * + * 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 3.2 + * @since 3.2 + */ +public interface ELXmlNamedNodeMapping + extends XmlNamedNodeMapping { + + // ***** XmlPath ***** + + +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java index 3683391644..eea73fd35b 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlInverseReferenceMapping.java @@ -9,18 +9,38 @@ *******************************************************************************/ package org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java; +import java.util.List; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.Filter; +import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; +import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; +import org.eclipse.jpt.jaxb.core.MappingKeys; +import org.eclipse.jpt.jaxb.core.context.JaxbClassMapping; import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; import org.eclipse.jpt.jaxb.core.internal.context.java.AbstractJavaAttributeMapping; import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbMappingKeys; +import org.eclipse.jpt.jaxb.eclipselink.core.context.java.ELXmlInverseReferenceMapping; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessageBuilder; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessages; import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlInverseReferenceAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class ELJavaXmlInverseReferenceMapping - extends AbstractJavaAttributeMapping<XmlInverseReferenceAnnotation> { + extends AbstractJavaAttributeMapping<XmlInverseReferenceAnnotation> + implements ELXmlInverseReferenceMapping { + + protected String mappedBy; + public ELJavaXmlInverseReferenceMapping(JaxbPersistentAttribute parent) { super(parent); + this.mappedBy = getResourceMappedBy(); } @@ -32,4 +52,161 @@ public class ELJavaXmlInverseReferenceMapping protected String getAnnotationName() { return ELJaxb.XML_INVERSE_REFERENCE; } + + + // ***** sync/update ***** + + @Override + public void synchronizeWithResourceModel() { + super.synchronizeWithResourceModel(); + + setMappedBy_(getResourceMappedBy()); + } + + + // ***** mappedBy ***** + + public String getMappedBy() { + return mappedBy; + } + + public void setMappedBy(String mappedBy) { + getXmlInverseReferenceAnnotation().setMappedBy(mappedBy); + setMappedBy_(mappedBy); + } + + protected void setMappedBy_(String mappedBy) { + String old = this.mappedBy; + this.mappedBy = mappedBy; + firePropertyChanged(MAPPED_BY_PROPERTY, old, mappedBy); + } + + public XmlInverseReferenceAnnotation getXmlInverseReferenceAnnotation() { + return (XmlInverseReferenceAnnotation) getJavaResourceAttribute().getAnnotation(ELJaxb.XML_INVERSE_REFERENCE); + } + + public String getResourceMappedBy() { + return getXmlInverseReferenceAnnotation().getMappedBy(); + } + + + // ***** misc ***** + + protected JaxbClassMapping getReferencedClassMapping() { + String referencedClassName = getValueTypeName(); + return (referencedClassName == null) ? null : getContextRoot().getClassMapping(referencedClassName); + } + + protected JaxbPersistentAttribute getReferencedAttribute() { + String mappedBy = getMappedBy(); + if (StringTools.stringIsEmpty(mappedBy)) { + return null; + } + JaxbClassMapping referencedClassMapping = getReferencedClassMapping(); + if (referencedClassMapping == null) { + return null; + } + JaxbPersistentAttribute tempResult = null; + for (JaxbPersistentAttribute attribute : referencedClassMapping.getAllLocallyDefinedAttributes()) { + if (attribute.getName().equals(mappedBy)) { + if (attribute.getMappingKey() == MappingKeys.XML_TRANSIENT_ATTRIBUTE_MAPPING_KEY) { + tempResult = attribute; + } + else { + return attribute; + } + } + } + return tempResult; + } + + + // ***** content assist ***** + + @Override + public Iterable<String> getJavaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { + Iterable<String> result = super.getJavaCompletionProposals(pos, filter, astRoot); + if (! CollectionTools.isEmpty(result)) { + return result; + } + + if (getXmlInverseReferenceAnnotation().mappedByTouches(pos, astRoot)) { + result = getMappedByProposals(filter, astRoot); + } + if (! CollectionTools.isEmpty(result)) { + return result; + } + + return EmptyIterable.instance(); + } + + protected Iterable<String> getMappedByProposals(Filter<String> filter, CompilationUnit astRoot) { + JaxbClassMapping referencedClassMapping = getReferencedClassMapping(); + + if (referencedClassMapping == null) { + return EmptyIterable.instance(); + } + + return StringTools.convertToJavaStringLiterals( + new TransformationIterable<JaxbPersistentAttribute, String>(referencedClassMapping.getAllLocallyDefinedAttributes()) { + @Override + protected String transform(JaxbPersistentAttribute o) { + return o.getName(); + } + }); + } + + + // ***** validation ***** + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + + validateMappedBy(messages, reporter, astRoot); + } + + protected void validateMappedBy(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + String mappedBy = getMappedBy(); + if (StringTools.stringIsEmpty(mappedBy)) { + messages.add( + ELJaxbValidationMessageBuilder.buildMessage( + IMessage.HIGH_SEVERITY, + ELJaxbValidationMessages.XML_INVERSE_REFERENCE__MAPPED_BY_NOT_SPECIFIED, + this, + getMappedByTextRange(astRoot))); + return; + } + + JaxbClassMapping referencedClassMapping = getReferencedClassMapping(); + if (referencedClassMapping == null) { + // TODO validate? + return; + } + + JaxbPersistentAttribute referencedAttribute = getReferencedAttribute(); + if (referencedAttribute == null) { + messages.add( + ELJaxbValidationMessageBuilder.buildMessage( + IMessage.HIGH_SEVERITY, + ELJaxbValidationMessages.XML_INVERSE_REFERENCE__MAPPED_BY_NOT_RESOLVED, + new String[] { mappedBy, referencedClassMapping.getJaxbType().getFullyQualifiedName() }, + this, + getMappedByTextRange(astRoot))); + } + else if (referencedAttribute.getMappingKey() != MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY) { + messages.add( + ELJaxbValidationMessageBuilder.buildMessage( + IMessage.HIGH_SEVERITY, + ELJaxbValidationMessages.XML_INVERSE_REFERENCE__MAPPED_BY_NOT_XML_ELEMENT, + new String[] { mappedBy, referencedClassMapping.getJaxbType().getFullyQualifiedName() }, + this, + getMappedByTextRange(astRoot))); + } + } + + protected TextRange getMappedByTextRange(CompilationUnit astRoot) { + TextRange textRange = getXmlInverseReferenceAnnotation().getMappedByTextRange(astRoot); + return (textRange != null) ? textRange : getValidationTextRange(astRoot); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathAnnotationDefinition.java new file mode 100644 index 0000000000..4c6593c38d --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathAnnotationDefinition.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java; + +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition; +import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.binary.BinaryXmlPathAnnotation; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.source.SourceXmlPathAnnotation; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; + + +public class XmlPathAnnotationDefinition + implements NestableAnnotationDefinition { + + // singleton + private static final NestableAnnotationDefinition INSTANCE = new XmlPathAnnotationDefinition(); + + + /** + * Return the singleton. + */ + public static NestableAnnotationDefinition instance() { + return INSTANCE; + } + + + private XmlPathAnnotationDefinition() { + super(); + } + + + public String getNestableAnnotationName() { + return ELJaxb.XML_PATH; + } + + public String getContainerAnnotationName() { + return ELJaxb.XML_PATHS; + } + + public String getElementName() { + return ELJaxb.XML_PATH__VALUE; + } + + public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement, int index) { + return SourceXmlPathAnnotation.buildSourceXmlPathAnnotation(parent, annotatedElement, index); + } + + public NestableAnnotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation, int index) { + return new BinaryXmlPathAnnotation(parent, jdtAnnotation); + } +} + diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathsAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathsAnnotationDefinition.java new file mode 100644 index 0000000000..61ed74de7d --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/XmlPathsAnnotationDefinition.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java; + +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryNamedAnnotation; +import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNamedAnnotation; +import org.eclipse.jpt.common.core.resource.java.Annotation; +import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; + + +public class XmlPathsAnnotationDefinition + implements AnnotationDefinition { + + // singleton + private static final AnnotationDefinition INSTANCE = new XmlPathsAnnotationDefinition(); + + + /** + * Return the singleton. + */ + public static AnnotationDefinition instance() { + return INSTANCE; + } + + + /** + * Ensure single instance. + */ + private XmlPathsAnnotationDefinition() { + super(); + } + + + public String getAnnotationName() { + return ELJaxb.XML_PATHS; + } + + public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) { + return new SourceNamedAnnotation(parent, annotatedElement, getAnnotationName()); + } + + public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) { + throw new UnsupportedOperationException(); + } + + public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) { + return new BinaryNamedAnnotation(parent, jdtAnnotation, getAnnotationName()); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlInverseReferenceAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlInverseReferenceAnnotation.java index b92cc05254..e2a600b5c9 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlInverseReferenceAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlInverseReferenceAnnotation.java @@ -47,7 +47,7 @@ public class BinaryXmlInverseReferenceAnnotation } - // ***** mappedBy + // ***** mappedBy ***** public String getMappedBy() { return this.mappedBy; @@ -70,4 +70,8 @@ public class BinaryXmlInverseReferenceAnnotation public TextRange getMappedByTextRange(CompilationUnit astRoot) { throw new UnsupportedOperationException(); } + + public boolean mappedByTouches(int pos, CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlPathAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlPathAnnotation.java new file mode 100644 index 0000000000..41e5f858dd --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/binary/BinaryXmlPathAnnotation.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.binary; + +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryAnnotation; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlPathAnnotation; + + +public class BinaryXmlPathAnnotation + extends BinaryAnnotation + implements XmlPathAnnotation { + + private String value; + + + public BinaryXmlPathAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) { + super(parent, jdtAnnotation); + this.value = buildValue(); + } + + + public String getAnnotationName() { + return ELJaxb.XML_PATH; + } + + @Override + public void update() { + super.update(); + setValue_(buildValue()); + } + + @Override + public void toString(StringBuilder sb) { + sb.append(this.value); + } + + + // ***** 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); + } + + private String buildValue() { + return (String) this.getJdtMemberValue(ELJaxb.XML_PATH__VALUE); + } + + public TextRange getValueTextRange(CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } + + public boolean valueTouches(int pos, CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlInverseReferenceAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlInverseReferenceAnnotation.java index 35f34eaacb..305eb4e2cd 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlInverseReferenceAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlInverseReferenceAnnotation.java @@ -75,7 +75,7 @@ public class SourceXmlInverseReferenceAnnotation } - // ********** mappedBy + // ***** mappedBy ***** public String getMappedBy() { return this.mappedBy; @@ -101,4 +101,8 @@ public class SourceXmlInverseReferenceAnnotation public TextRange getMappedByTextRange(CompilationUnit astRoot) { return this.getElementTextRange(this.mappedByDeclarationAdapter, astRoot); } + + public boolean mappedByTouches(int pos, CompilationUnit astRoot) { + return elementTouches(this.mappedByDeclarationAdapter, pos, astRoot); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlPathAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlPathAnnotation.java new file mode 100644 index 0000000000..e3690bdbe4 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/resource/java/source/SourceXmlPathAnnotation.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2011 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.source; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation; +import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter; +import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter; +import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; +import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter; +import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; +import org.eclipse.jpt.common.core.internal.utility.jdt.StringExpressionConverter; +import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; +import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter; +import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter; +import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter; +import org.eclipse.jpt.common.core.utility.jdt.ExpressionConverter; +import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter; +import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlPathAnnotation; + + +public class SourceXmlPathAnnotation + extends SourceAnnotation + implements XmlPathAnnotation { + + public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = + new SimpleDeclarationAnnotationAdapter(ELJaxb.XML_PATH); + public static final DeclarationAnnotationAdapter CONTAINER_DECLARATION_ANNOTATION_ADAPTER = + new SimpleDeclarationAnnotationAdapter(ELJaxb.XML_PATHS); + + private final DeclarationAnnotationElementAdapter<String> valueDeclarationAdapter; + private final AnnotationElementAdapter<String> valueAdapter; + private String value; + + + public static SourceXmlPathAnnotation buildSourceXmlPathAnnotation( + JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement, int index) { + + IndexedDeclarationAnnotationAdapter idaa = buildXmlPathDeclarationAnnotationAdapter(index); + IndexedAnnotationAdapter iaa = buildXmlPathAnnotationAdapter(annotatedElement, idaa); + return new SourceXmlPathAnnotation(parent, annotatedElement, idaa, iaa); + } + + + private SourceXmlPathAnnotation( + JavaResourceAnnotatedElement parent, + AnnotatedElement annotatedElement, + IndexedDeclarationAnnotationAdapter daa, + IndexedAnnotationAdapter annotationAdapter) { + + super(parent, annotatedElement, daa, annotationAdapter); + this.valueDeclarationAdapter = buildValueAdapter(daa); + this.valueAdapter = this.buildAnnotationElementAdapter(this.valueDeclarationAdapter); + } + + + private DeclarationAnnotationElementAdapter<String> buildValueAdapter(DeclarationAnnotationAdapter daa) { + return buildAnnotationElementAdapter(daa, ELJaxb.XML_PATH__VALUE, StringExpressionConverter.instance()); + } + + private DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter( + DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) { + + return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, converter); + } + + private AnnotationElementAdapter<String> buildAnnotationElementAdapter( + DeclarationAnnotationElementAdapter<String> daea) { + + return new AnnotatedElementAnnotationElementAdapter<String>(this.annotatedElement, daea); + } + + public String getAnnotationName() { + return ELJaxb.XML_PATH; + } + + public void initialize(CompilationUnit astRoot) { + this.value = buildValue(astRoot); + } + + public void synchronizeWith(CompilationUnit astRoot) { + syncValue(buildValue(astRoot)); + } + + @Override + public void toString(StringBuilder sb) { + sb.append(this.value); + } + + + // ***** 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(this.valueDeclarationAdapter, astRoot); + } + + public boolean valueTouches(int pos, CompilationUnit astRoot) { + return elementTouches(this.valueDeclarationAdapter, pos, astRoot); + } + + + // ***** NestableAnnotation impl ***** + + /** + * convenience implementation of method from NestableAnnotation interface + * for subclasses + */ + @Override + public void moveAnnotation(int newIndex) { + this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); + } + + private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { + return (IndexedAnnotationAdapter) this.annotationAdapter; + } + + + // ********** static methods ********** + + private static IndexedAnnotationAdapter buildXmlPathAnnotationAdapter( + AnnotatedElement annotatedElement, IndexedDeclarationAnnotationAdapter idaa) { + + return new ElementIndexedAnnotationAdapter(annotatedElement, idaa); + } + + private static IndexedDeclarationAnnotationAdapter buildXmlPathDeclarationAnnotationAdapter(int index) { + IndexedDeclarationAnnotationAdapter idaa = + new CombinationIndexedDeclarationAnnotationAdapter( + DECLARATION_ANNOTATION_ADAPTER, + CONTAINER_DECLARATION_ANNOTATION_ADAPTER, + index, + ELJaxb.XML_PATH); + return idaa; + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java index e0edbf94ba..9107383b41 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_PlatformDefinition.java @@ -27,6 +27,8 @@ import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; import org.eclipse.jpt.jaxb.eclipselink.core.internal.AbstractELJaxbPlatformDefinition; import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java.ELJavaXmlInverseReferenceMappingDefinition; import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.XmlInverseReferenceAnnotationDefinition; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.XmlPathAnnotationDefinition; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.XmlPathsAnnotationDefinition; import org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.XmlTransformationAnnotationDefinition; @@ -79,12 +81,15 @@ public class ELJaxb_2_1_PlatformDefinition return ArrayTools.addAll( getGenericJaxbPlatformDefinition().getAnnotationDefinitions(), XmlInverseReferenceAnnotationDefinition.instance(), + XmlPathsAnnotationDefinition.instance(), XmlTransformationAnnotationDefinition.instance()); } @Override protected NestableAnnotationDefinition[] buildNestableAnnotationDefinitions() { - return getGenericJaxbPlatformDefinition().getNestableAnnotationDefinitions(); + return ArrayTools.addAll( + getGenericJaxbPlatformDefinition().getNestableAnnotationDefinitions(), + XmlPathAnnotationDefinition.instance()); } @Override diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_4/ELJaxb_2_4_PlatformDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_4/ELJaxb_2_4_PlatformDefinition.java index ce8d91823e..20648b20d1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_4/ELJaxb_2_4_PlatformDefinition.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_4/ELJaxb_2_4_PlatformDefinition.java @@ -12,11 +12,11 @@ package org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_4; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDefinition; import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbPlatform; -import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_2.ELJaxb_2_2_PlatformDefinition; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_3.ELJaxb_2_3_PlatformDefinition; public class ELJaxb_2_4_PlatformDefinition - extends ELJaxb_2_2_PlatformDefinition { + extends ELJaxb_2_3_PlatformDefinition { // singleton private static final JaxbPlatformDefinition INSTANCE = new ELJaxb_2_4_PlatformDefinition(); diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java index 51a0d4addc..3bea25577c 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/validation/ELJaxbValidationMessages.java @@ -18,4 +18,9 @@ public interface ELJaxbValidationMessages { // validation on project String PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY = "PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY"; + + + String XML_INVERSE_REFERENCE__MAPPED_BY_NOT_SPECIFIED = "XML_INVERSE_REFERENCE__MAPPED_BY_NOT_SPECIFIED"; + String XML_INVERSE_REFERENCE__MAPPED_BY_NOT_RESOLVED = "XML_INVERSE_REFERENCE__MAPPED_BY_NOT_RESOLVED"; + String XML_INVERSE_REFERENCE__MAPPED_BY_NOT_XML_ELEMENT = "XML_INVERSE_REFERENCE__MAPPED_BY_NOT_XML_ELEMENT"; } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/ELJaxb.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/ELJaxb.java index 74b85352aa..de22c615a1 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/ELJaxb.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/ELJaxb.java @@ -35,6 +35,11 @@ public interface ELJaxb { String XML_INVERSE_REFERENCE = PACKAGE_ + "XmlInverseReference"; String XML_INVERSE_REFERENCE__MAPPED_BY = "mappedBy"; + String XML_PATH = PACKAGE_ + "XmlPath"; + String XML_PATH__VALUE = "value"; + + String XML_PATHS = PACKAGE_ + "XmlPaths"; + String XML_TRANSFORMATION = PACKAGE_ + "XmlTransformation"; String XML_TRANSFORMATION__OPTIONAL = "optional"; } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlInverseReferenceAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlInverseReferenceAnnotation.java index a53de2e2cb..b7b7a07a11 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlInverseReferenceAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlInverseReferenceAnnotation.java @@ -13,7 +13,19 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.resource.java.Annotation; import org.eclipse.jpt.common.core.utility.TextRange; - +/** + * Corresponds to the EclipseLink annotation + * org.eclipse.persistence.oxm.annotations.XmlInverseReference + * + * 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 3.2 + * @since 3.0 + */ public interface XmlInverseReferenceAnnotation extends Annotation { @@ -39,4 +51,9 @@ public interface XmlInverseReferenceAnnotation * Return the text range of this annotation if the element is absent. */ TextRange getMappedByTextRange(CompilationUnit astRoot); + + /** + * Return whether the specified text position is within the 'mappedBy' element. + */ + boolean mappedByTouches(int pos, CompilationUnit astRoot); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlPathAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlPathAnnotation.java new file mode 100644 index 0000000000..5a6908a5fc --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/java/XmlPathAnnotation.java @@ -0,0 +1,50 @@ +package org.eclipse.jpt.jaxb.eclipselink.core.resource.java; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.common.core.utility.TextRange; + +/** + * Corresponds to the EclipseLink annotation + * org.eclipse.persistence.oxm.annotations.XmlPath + * + * 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 3.2 + * @since 3.2 + */ +public interface XmlPathAnnotation + extends NestableAnnotation { + + /** + * String associated with change events to the 'value' property + */ + String VALUE_PROPERTY = "value"; //$NON-NLS-1$ + + /** + * Corresponds to the 'value' element of the annotation. + * Return null if the element does not exist in Java (the annotation is a marker annotation.) + */ + String getValue(); + + /** + * Corresponds to the 'value' element of the annotation. + * Set to null to remove the element (to make it a marker annotation.) + */ + void setValue(String value); + + /** + * Return the text range associated with the 'value' element. + * Return the text range of this annotation if the element is absent. + */ + TextRange getValueTextRange(CompilationUnit astRoot); + + /** + * Return whether the specified text position is within the 'value' element. + */ + boolean valueTouches(int pos, CompilationUnit astRoot); +} |