From be4c19e21a14963533cadf1a3b016178a6c13b85 Mon Sep 17 00:00:00 2001 From: Paul Fullbright Date: Wed, 19 Sep 2012 12:58:29 -0400 Subject: added oxm files to context model --- .../internal/context/AbstractJaxbContextRoot.java | 47 ------ .../META-INF/MANIFEST.MF | 6 +- .../plugin.xml | 26 ++++ .../jpt/jaxb/eclipselink/core/ELJaxbProject.java | 32 ++++ .../core/context/ELJaxbContextRoot.java | 33 +++++ .../eclipselink/core/context/ELJaxbPackage.java | 26 ++++ .../jaxb/eclipselink/core/context/oxm/OxmFile.java | 79 ++++++++++ .../core/context/oxm/OxmXmlBindings.java | 61 ++++++++ .../core/internal/ELJaxbProjectImpl.java | 29 ++++ .../core/internal/context/ELJaxbContextRoot.java | 60 -------- .../internal/context/ELJaxbContextRootImpl.java | 161 +++++++++++++++++++++ .../core/internal/context/ELJaxbPackageImpl.java | 56 +++++++ .../core/internal/v2_1/ELJaxb_2_1_Factory.java | 27 +++- .../core/resource/oxm/EXmlBindings.java | 10 +- .../jaxb/eclipselink/core/resource/oxm/Oxm.java | 11 ++ .../jpt/jaxb/core/tests/internal/JaxbTestCase.java | 2 +- .../internal/context/ELJaxbContextRootTests.java | 70 +++++++++ .../context/ELJaxbCoreContextModelTests.java | 2 +- 18 files changed, 625 insertions(+), 113 deletions(-) create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/ELJaxbProject.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbContextRoot.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbPackage.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmFile.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmXmlBindings.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/ELJaxbProjectImpl.java delete mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRootImpl.java create mode 100644 jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbPackageImpl.java create mode 100644 jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextRootTests.java diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java index ea3b3a42b4..b19229a53e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java @@ -105,53 +105,6 @@ public abstract class AbstractJaxbContextRoot this.packages.put(pkg, buildPackage(pkg)); } } - -// // keep a master list of all types that we've processed so we don't process them again -// final Set totalTypes = CollectionTools.set(); -// -// // keep an running list of types that we need to scan for further referenced types -// final Set typesToScan = CollectionTools.set(); -// -// // process packages with annotations first -// for (String pkg : calculateInitialPackageNames()) { -// this.packages.put(pkg, buildPackage(pkg)); -// } -// -// // calculate initial types (annotated or listed in jaxb.index files) -// final Set resourceTypesToProcess = calculateInitialTypes(); -// -// // while there are resource types to process or types to scan, continue to do so -// while (! resourceTypesToProcess.isEmpty() || ! typesToScan.isEmpty()) { -// for (JavaResourceAbstractType resourceType : new SnapshotCloneIterable(resourceTypesToProcess)) { -// String className = resourceType.getQualifiedName(); -// totalTypes.add(className); -// typesToScan.add(className); -// addType_(buildType(resourceType)); -// resourceTypesToProcess.remove(resourceType); -// } -// -// for (String typeToScan : new SnapshotCloneIterable(typesToScan)) { -// JaxbType jaxbType = getType(typeToScan); -// if (jaxbType != null) { -// for (String referencedTypeName : jaxbType.getReferencedXmlTypeNames()) { -// if (! totalTypes.contains(referencedTypeName)) { -// JavaResourceAbstractType referencedType = getJaxbProject().getJavaResourceType(referencedTypeName); -// if (referencedType != null) { -// resourceTypesToProcess.add(referencedType); -// } -// } -// } -// } -// typesToScan.remove(typeToScan); -// } -// } -// -// // once all classes have been processed, add packages -// for (String pkg : calculatePackageNames(totalTypes)) { -// if (! this.packages.containsKey(pkg)) { -// this.packages.put(pkg, buildPackage(pkg)); -// } -// } } @Override 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 f6a7cdaed4..84a7947cf2 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 @@ -27,12 +27,15 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.300,4.0.0)", org.eclipse.wst.validation;bundle-version="[1.2.300,2.0.0)", org.eclipse.xsd;bundle-version="[2.8.0,3.0.0)" Export-Package: org.eclipse.jpt.jaxb.eclipselink.core, + org.eclipse.jpt.jaxb.eclipselink.core.context, org.eclipse.jpt.jaxb.eclipselink.core.context.java, + org.eclipse.jpt.jaxb.eclipselink.core.context.oxm, org.eclipse.jpt.jaxb.eclipselink.core.internal;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.context;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.context.xpath.java;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.libval;x-internal:=true, + org.eclipse.jpt.jaxb.eclipselink.core.internal.plugin, org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.binary;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.resource.java.source;x-internal:=true, @@ -43,4 +46,5 @@ Export-Package: org.eclipse.jpt.jaxb.eclipselink.core, org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_4;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.internal.validation;x-internal:=true, org.eclipse.jpt.jaxb.eclipselink.core.resource.java, - org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm + org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm, + org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm.util diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml index 1fab7735b0..331c9f5abf 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/plugin.xml @@ -111,6 +111,32 @@ + + + + + + + + + + + + + getOxmResources(); +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbContextRoot.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbContextRoot.java new file mode 100644 index 0000000000..465ed9942f --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbContextRoot.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2012 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; + +import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.context.oxm.OxmFile; + +public interface ELJaxbContextRoot + extends JaxbContextRoot { + + // ***** oxm files ***** + + static String OXM_FILES_COLLECTION = "oxmFiles"; //$NON-NLS-1$ + + /** + * The set of oxm files. + */ + Iterable getOxmFiles(); + + int getOxmFilesSize(); + + /** + * Return the (first) oxm file with the given package name + */ + OxmFile getOxmFile(String packageName); +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbPackage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbPackage.java new file mode 100644 index 0000000000..2fc60c13eb --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/ELJaxbPackage.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 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; + +import org.eclipse.jpt.jaxb.core.context.JaxbPackage; +import org.eclipse.jpt.jaxb.eclipselink.core.context.oxm.OxmFile; + +public interface ELJaxbPackage + extends JaxbPackage { + + static final String OXM_FILE_PROPERTY = "oxmFile"; //$NON-NLS-1$ + + /** + * The oxm file associated with this package. + * This will be the first oxm file encountered that specifies this package. + * May be null. + */ + OxmFile getOxmFile(); +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmFile.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmFile.java new file mode 100644 index 0000000000..63e057a383 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmFile.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2012 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.oxm; + +import org.eclipse.jpt.common.core.JptResourceType; +import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange; +import org.eclipse.jpt.common.core.resource.xml.JptXmlResource; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm.EXmlBindings; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm.Oxm; + +public class OxmFile + extends AbstractJaxbContextNode { + + // never null + protected JptXmlResource oxmResource; + + /** + * The resource type will only change if the XML file's version changes + * (since, if the content type changes, we get garbage-collected). + */ + protected JptResourceType resourceType; + + /** + * The root element of the oxm file. + */ + protected OxmXmlBindings xmlBindings; + + + + public OxmFile(ELJaxbContextRoot parent, JptXmlResource oxmResource) { + super(parent); + this.oxmResource = oxmResource; + this.resourceType = oxmResource.getResourceType(); + this.xmlBindings = buildXmlBindings(); + } + + + @Override + public ELJaxbContextRoot getContextRoot() { + return (ELJaxbContextRoot) super.getContextRoot(); + } + + public JptXmlResource getOxmResource() { + return this.oxmResource; + } + + public String getPackageName() { + return (this.xmlBindings == null) ? null : this.xmlBindings.getPackageName(); + } + + + // ***** xml bindings ***** + + protected OxmXmlBindings buildXmlBindings() { + // if less than 2.3, then there is no context model support + if (this.resourceType.isKindOf(Oxm.RESOURCE_TYPE_2_3)) { + return new OxmXmlBindings(this, (EXmlBindings) this.oxmResource.getRootObject()); + } + return null; + } + + + // ***** validation ***** + + @Override + public TextRange getValidationTextRange() { + return new SimpleTextRange(0, 0, 0); // simple beginning of document + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmXmlBindings.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmXmlBindings.java new file mode 100644 index 0000000000..5b6aec9410 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/context/oxm/OxmXmlBindings.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 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.oxm; + +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm.EXmlBindings; + +public class OxmXmlBindings + extends AbstractJaxbContextNode { + + protected EXmlBindings eXmlBindings; + + public final static String PACKAGE_NAME_PROPERTY = "packageName"; //$NON-NLS-1$ + protected String packageName; + + + public OxmXmlBindings(OxmFile parent, EXmlBindings eXmlBindings) { + super(parent); + this.eXmlBindings = eXmlBindings; + this.packageName = buildPackageName(); + } + + + // ***** package name ***** + + public String getPackageName() { + return this.packageName; + } + + public void setPackageName(String packageName) { + this.eXmlBindings.setPackageName(packageName); + setPackageName_(packageName); + } + + protected void setPackageName_(String packageName) { + String oldPackageName = this.packageName; + this.packageName = packageName; + firePropertyChanged(PACKAGE_NAME_PROPERTY, oldPackageName, packageName); + } + + protected String buildPackageName() { + return this.eXmlBindings.getPackageName(); + } + + + // ***** validation ***** + + @Override + public TextRange getValidationTextRange() { + TextRange textRange = this.eXmlBindings.getValidationTextRange(); + return (textRange != null) ? textRange : this.getParent().getValidationTextRange(); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/ELJaxbProjectImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/ELJaxbProjectImpl.java new file mode 100644 index 0000000000..77ab2673c5 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/ELJaxbProjectImpl.java @@ -0,0 +1,29 @@ +package org.eclipse.jpt.jaxb.eclipselink.core.internal; + +import org.eclipse.jpt.common.core.resource.xml.JptXmlResource; +import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; +import org.eclipse.jpt.jaxb.core.JaxbFile; +import org.eclipse.jpt.jaxb.core.JaxbProject; +import org.eclipse.jpt.jaxb.core.internal.AbstractJaxbProject; +import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbProject; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm.Oxm; + +public class ELJaxbProjectImpl + extends AbstractJaxbProject + implements ELJaxbProject { + + public ELJaxbProjectImpl(JaxbProject.Config config) { + super(config); + } + + + public Iterable getOxmResources() { + return new TransformationIterable( + getJaxbFiles(Oxm.CONTENT_TYPE)) { + @Override + protected JptXmlResource transform(JaxbFile o) { + return (JptXmlResource) o.getResourceModel(); + } + }; + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java deleted file mode 100644 index b162386a60..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRoot.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * 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.context; - -import java.util.List; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jaxb.core.JaxbProject; -import org.eclipse.jpt.jaxb.core.context.JaxbPackage; -import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextRoot; -import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource; -import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessageBuilder; -import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessages; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - - -public class ELJaxbContextRoot - extends AbstractJaxbContextRoot { - - - public ELJaxbContextRoot(JaxbProject jaxbProject) { - super(jaxbProject); - } - - - // **************** validation ******************************************** - - @Override - public void validate(List messages, IReporter reporter) { - super.validate(messages, reporter); - - validateJaxbProperties(messages, reporter); - } - - protected void validateJaxbProperties(List messages, IReporter reporter) { - String factoryProp = "javax.xml.bind.context.factory"; - String factoryPropValue = "org.eclipse.persistence.jaxb.JAXBContextFactory"; - - for (JaxbPackage jp : getPackages()) { - String pn = jp.getName(); - JaxbPropertiesResource jpr = getJaxbProject().getJaxbPropertiesResource(pn); - if (jpr != null && StringTools.stringsAreEqual(jpr.getProperty(factoryProp), factoryPropValue)) { - return; - } - } - - messages.add( - ELJaxbValidationMessageBuilder.buildMessage( - IMessage.HIGH_SEVERITY, - ELJaxbValidationMessages.PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY, - getJaxbProject())); - } -} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRootImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRootImpl.java new file mode 100644 index 0000000000..6984c455e8 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRootImpl.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * 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.context; + +import java.util.Collection; +import java.util.List; +import java.util.Vector; +import org.eclipse.jpt.common.core.resource.xml.JptXmlResource; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.common.utility.internal.iterables.SnapshotCloneIterable; +import org.eclipse.jpt.jaxb.core.JaxbProject; +import org.eclipse.jpt.jaxb.core.context.JaxbPackage; +import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextRoot; +import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource; +import org.eclipse.jpt.jaxb.eclipselink.core.ELJaxbProject; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.context.oxm.OxmFile; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessageBuilder; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.validation.ELJaxbValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + + +public class ELJaxbContextRootImpl + extends AbstractJaxbContextRoot + implements ELJaxbContextRoot { + + protected List oxmFiles; + + + public ELJaxbContextRootImpl(JaxbProject jaxbProject) { + super(jaxbProject); + } + + + // ***** overrides ***** + + @Override + public ELJaxbProject getJaxbProject() { + return (ELJaxbProject) super.getJaxbProject(); + } + + // ***** initialize/update ***** + + @Override + protected void initialize() { + + // initialize oxm files *first* + this.oxmFiles = new Vector(); // can't do this statically, since this gets called during constructor + for (JptXmlResource oxmResource : getJaxbProject().getOxmResources()) { + this.oxmFiles.add(buildOxmFile(oxmResource)); + } + + super.initialize(); + } + + @Override + public void synchronizeWithResourceModel() { + super.synchronizeWithResourceModel(); + for (OxmFile oxmFile : getOxmFiles()) { + oxmFile.synchronizeWithResourceModel(); + } + } + + @Override + public void update() { + + // update oxm files *first* + + Collection + unmatchedOxmResources = CollectionTools.collection(getJaxbProject().getOxmResources()); + + for (OxmFile oxmFile : getOxmFiles()) { + JptXmlResource oxmResource = oxmFile.getOxmResource(); + if (! unmatchedOxmResources.remove(oxmResource)) { + removeOxmFile(oxmFile); + } + } + + for (JptXmlResource oxmResource : unmatchedOxmResources) { + addOxmFile(buildOxmFile(oxmResource)); + } + + super.update(); + } + + + // ***** oxm files ***** + + public Iterable getOxmFiles() { + return new SnapshotCloneIterable(this.oxmFiles); + } + + public int getOxmFilesSize() { + return this.oxmFiles.size(); + } + + protected void addOxmFile(OxmFile oxmFile) { + addItemToCollection(oxmFile, this.oxmFiles, OXM_FILES_COLLECTION); + } + + protected void removeOxmFile(OxmFile oxmFile) { + removeItemFromCollection(oxmFile, this.oxmFiles, OXM_FILES_COLLECTION); + } + + public OxmFile getOxmFile(String packageName) { + for (OxmFile oxmFile : getOxmFiles()) { + if (packageName.equals(oxmFile.getPackageName())) { + return oxmFile; + } + } + return null; + } + + protected OxmFile buildOxmFile(JptXmlResource oxmResource) { + return new OxmFile(this, oxmResource); + } + + + // ***** validation ***** + + @Override + public TextRange getValidationTextRange() { + return TextRange.Empty.instance(); //? + } + + @Override + public void validate(List messages, IReporter reporter) { + super.validate(messages, reporter); + + validateJaxbProperties(messages, reporter); + } + + protected void validateJaxbProperties(List messages, IReporter reporter) { + String factoryProp = "javax.xml.bind.context.factory"; + String factoryPropValue = "org.eclipse.persistence.jaxb.JAXBContextFactory"; + + for (JaxbPackage jp : getPackages()) { + String pn = jp.getName(); + JaxbPropertiesResource jpr = getJaxbProject().getJaxbPropertiesResource(pn); + if (jpr != null && StringTools.stringsAreEqual(jpr.getProperty(factoryProp), factoryPropValue)) { + return; + } + } + + messages.add( + ELJaxbValidationMessageBuilder.buildMessage( + IMessage.HIGH_SEVERITY, + ELJaxbValidationMessages.PROJECT_MISSING_ECLIPSELINK_JAXB_CONTEXT_FACTORY, + getJaxbProject())); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbPackageImpl.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbPackageImpl.java new file mode 100644 index 0000000000..23477391e4 --- /dev/null +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbPackageImpl.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2012 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.context; + +import org.eclipse.jpt.jaxb.core.internal.context.GenericPackage; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbPackage; +import org.eclipse.jpt.jaxb.eclipselink.core.context.oxm.OxmFile; + +public class ELJaxbPackageImpl + extends GenericPackage + implements ELJaxbPackage { + + protected OxmFile oxmFile; + + + public ELJaxbPackageImpl(ELJaxbContextRoot parent, String name) { + super(parent, name); + this.oxmFile = parent.getOxmFile(name); + } + + + @Override + public ELJaxbContextRoot getContextRoot() { + return (ELJaxbContextRoot) super.getContextRoot(); + } + + + // ***** sync/update ***** + + @Override + public void update() { + super.update(); + setOxmFile(getContextRoot().getOxmFile(getName())); + } + + + // ***** oxm file ***** + + public OxmFile getOxmFile() { + return this.oxmFile; + } + + protected void setOxmFile(OxmFile oxmFile) { + OxmFile old = this.oxmFile; + this.oxmFile = oxmFile; + firePropertyChanged(OXM_FILE_PROPERTY, old, oxmFile); + } +} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java index cedaa85079..8a4b2d567a 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/v2_1/ELJaxb_2_1_Factory.java @@ -12,10 +12,12 @@ package org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.jaxb.core.JaxbFactory; import org.eclipse.jpt.jaxb.core.JaxbProject; +import org.eclipse.jpt.jaxb.core.JaxbProject.Config; import org.eclipse.jpt.jaxb.core.context.JaxbClass; import org.eclipse.jpt.jaxb.core.context.JaxbClassMapping; import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod; +import org.eclipse.jpt.jaxb.core.context.JaxbPackage; import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; import org.eclipse.jpt.jaxb.core.context.XmlAnyAttributeMapping; import org.eclipse.jpt.jaxb.core.context.XmlAnyElementMapping; @@ -27,7 +29,10 @@ import org.eclipse.jpt.jaxb.core.context.XmlElementsMapping; import org.eclipse.jpt.jaxb.core.context.XmlRegistry; import org.eclipse.jpt.jaxb.core.context.XmlValueMapping; import org.eclipse.jpt.jaxb.core.internal.AbstractJaxbFactory; -import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.ELJaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbContextRoot; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.ELJaxbProjectImpl; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.ELJaxbContextRootImpl; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.ELJaxbPackageImpl; import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java.ELJavaClassMapping; import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java.ELJavaElementFactoryMethod; import org.eclipse.jpt.jaxb.eclipselink.core.internal.context.java.ELJavaXmlAnyAttributeMapping; @@ -63,11 +68,29 @@ public class ELJaxb_2_1_Factory } + // ***** core model ***** + + @Override + public JaxbProject buildJaxbProject(Config config) { + return new ELJaxbProjectImpl(config); + } + + + // ***** non-resource context nodes ***** + @Override public JaxbContextRoot buildContextRoot(JaxbProject parent) { - return new ELJaxbContextRoot(parent); + return new ELJaxbContextRootImpl(parent); } + @Override + public JaxbPackage buildPackage(JaxbContextRoot parent, String packageName) { + return new ELJaxbPackageImpl((ELJaxbContextRoot) parent, packageName); + } + + + // ***** java context nodes ***** + @Override public JaxbElementFactoryMethod buildJavaElementFactoryMethod( XmlRegistry parent, JavaResourceMethod resourceMethod) { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/EXmlBindings.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/EXmlBindings.java index ff5656d803..7332df9234 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/EXmlBindings.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/EXmlBindings.java @@ -993,13 +993,21 @@ public class EXmlBindings extends ERootObjectImpl return new SimpleRootTranslator(Oxm.XML_BINDINGS, OxmPackage.eINSTANCE.getEXmlBindings(), buildTranslatorChildren()); } - private static Translator[] buildTranslatorChildren() { + protected static Translator[] buildTranslatorChildren() { return new Translator[] { buildVersionTranslator(SCHEMA_LOCATIONS), buildNamespaceTranslator(Oxm.SCHEMA_NAMESPACE), buildSchemaNamespaceTranslator(), buildSchemaLocationTranslator(Oxm.SCHEMA_NAMESPACE, SCHEMA_LOCATIONS), + buildPackageNameTranslator(), EJavaType.buildTranslator() }; } + + protected static Translator buildPackageNameTranslator() { + return new Translator( + Oxm.PACKAGE_NAME, + OxmPackage.eINSTANCE.getEXmlBindings_PackageName(), + Translator.DOM_ATTRIBUTE); + } } \ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/Oxm.java b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/Oxm.java index ee07532241..f5f73c48b5 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/Oxm.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/resource/oxm/Oxm.java @@ -10,6 +10,8 @@ package org.eclipse.jpt.jaxb.eclipselink.core.resource.oxm; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jpt.common.core.JptResourceType; +import org.eclipse.jpt.common.core.internal.utility.PlatformTools; import org.eclipse.jpt.jaxb.eclipselink.core.internal.plugin.JptJaxbEclipseLinkCorePlugin; public interface Oxm { @@ -21,20 +23,29 @@ public interface Oxm { String SCHEMA_VERSION_2_1 = "2.1"; String SCHEMA_LOCATION_2_1 = "http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_1.xsd"; + JptResourceType RESOURCE_TYPE_2_1 = PlatformTools.getResourceType(CONTENT_TYPE, SCHEMA_VERSION_2_1); + String SCHEMA_VERSION_2_2 = "2.2"; String SCHEMA_LOCATION_2_2 = "http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_2.xsd"; + JptResourceType RESOURCE_TYPE_2_2 = PlatformTools.getResourceType(CONTENT_TYPE, SCHEMA_VERSION_2_2); + String SCHEMA_VERSION_2_3 = "2.3"; String SCHEMA_LOCATION_2_3 = "http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_3.xsd"; + JptResourceType RESOURCE_TYPE_2_3 = PlatformTools.getResourceType(CONTENT_TYPE, SCHEMA_VERSION_2_3); + String SCHEMA_VERSION_2_4 = "2.4"; String SCHEMA_LOCATION_2_4 = "http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_4.xsd"; + JptResourceType RESOURCE_TYPE_2_4 = PlatformTools.getResourceType(CONTENT_TYPE, SCHEMA_VERSION_2_4); + // Oxm specific nodes String JAVA_ATTRIBUTES = "java-attributes"; //$NON-NLS-1$ String JAVA_TYPE = "java-type"; //$NON-NLS-1$ String JAVA_TYPES = "java-types"; //$NON-NLS-1$ + String PACKAGE_NAME = "package-name"; //$NON-NLS-1$ String XML_ANY_ATTRIBUTE = "xml-any-attribute"; //$NON-NLS-1$ String XML_ANY_ELEMENT = "xml-any-element"; //$NON-NLS-1$ String XML_ATTRIBUTE = "xml-attribute"; //$NON-NLS-1$ diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java index a32117f964..b14feb47d2 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java @@ -59,7 +59,7 @@ public class JaxbTestCase } protected IProjectFacetVersion getProjectFacetVersion() { - return JaxbFacet.VERSION_2_1; + return JaxbFacet.VERSION_2_2; } @Override diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextRootTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextRootTests.java new file mode 100644 index 0000000000..a8b9307ca7 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbContextRootTests.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2012 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.tests.internal.context; + +import java.io.ByteArrayInputStream; +import org.eclipse.core.resources.IFile; +import org.eclipse.jpt.jaxb.eclipselink.core.context.ELJaxbContextRoot; + +public class ELJaxbContextRootTests + extends ELJaxbContextModelTestCase { + + public ELJaxbContextRootTests(String name) { + super(name); + } + + + protected void addOxmFile(String fileName, String packageName) throws Exception { + IFile oxmFile = getJavaProject().getProject().getFolder("src").getFile(fileName); + StringBuffer sb = new StringBuffer(); + sb.append("").append(CR); + sb.append("").append(CR); + oxmFile.create(new ByteArrayInputStream(sb.toString().getBytes()), true, null); + } + + public void testOxmFiles() throws Exception { + ELJaxbContextRoot root = (ELJaxbContextRoot) getJaxbProject().getContextRoot(); + + assertEquals(0, root.getOxmFilesSize()); + + addOxmFile("oxm.xml", "test.oxm"); + + assertEquals(1, root.getOxmFilesSize()); + assertNull(root.getOxmFile("fake.pkg")); + assertNotNull(root.getOxmFile("test.oxm")); + + addOxmFile("oxm2.xml", "test.oxm"); + + assertEquals(2, root.getOxmFilesSize()); + assertNotNull(root.getOxmFile("test.oxm")); + + addOxmFile("oxm3.xml", "test.oxm2"); + assertEquals(3, root.getOxmFilesSize()); + assertNotNull(root.getOxmFile("test.oxm2")); + + getJavaProject().getProject().getFolder("src").getFile("oxm.xml").delete(true, null); + + assertEquals(2, root.getOxmFilesSize()); + assertNotNull(root.getOxmFile("test.oxm")); + + getJavaProject().getProject().getFolder("src").getFile("oxm2.xml").delete(true, null); + + assertEquals(1, root.getOxmFilesSize()); + assertNull(root.getOxmFile("test.oxm")); + + getJavaProject().getProject().getFolder("src").getFile("oxm3.xml").delete(true, null); + + assertEquals(0, root.getOxmFilesSize()); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java index 2381acc9be..a0117e9ba6 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/context/ELJaxbCoreContextModelTests.java @@ -21,7 +21,7 @@ public class ELJaxbCoreContextModelTests { TestSuite suite = new TestSuite(ELJaxbCoreContextModelTests.class.getName()); if (ELJaxbCoreTests.requiredJarsExists()) { -// suite.addTestSuite(GenericContextRootTests.class); + suite.addTestSuite(ELJaxbContextRootTests.class); suite.addTest(ELJaxbCoreJavaContextModelTests.suite()); } else { -- cgit v1.2.3