diff options
author | Paul Fullbright | 2012-09-01 18:11:40 +0000 |
---|---|---|
committer | Paul Fullbright | 2012-09-01 18:12:12 +0000 |
commit | 9758de688a96c4bdb4c5476991e3b953840f9cf9 (patch) | |
tree | 9f0886ac3cf6c1fa87c36cc335364493586c0773 /common | |
parent | 7786214ad5164c314767f10ba4f13254795be695 (diff) | |
download | webtools.dali-9758de688a96c4bdb4c5476991e3b953840f9cf9.tar.gz webtools.dali-9758de688a96c4bdb4c5476991e3b953840f9cf9.tar.xz webtools.dali-9758de688a96c4bdb4c5476991e3b953840f9cf9.zip |
support for versionless xml files
Diffstat (limited to 'common')
5 files changed, 198 insertions, 20 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/model/common.ecore b/common/plugins/org.eclipse.jpt.common.core/model/common.ecore index 5c57f5c1e1..5463a6c9dd 100644 --- a/common/plugins/org.eclipse.jpt.common.core/model/common.ecore +++ b/common/plugins/org.eclipse.jpt.common.core/model/common.ecore @@ -3,9 +3,9 @@ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="xml" nsURI="jpt.common.xmi" nsPrefix="org.eclipse.jpt.jpa.core.resource.xml">
<eClassifiers xsi:type="ecore:EClass" name="ERootObjectImpl" abstract="true" eSuperTypes="#//ERootObject"/>
<eClassifiers xsi:type="ecore:EClass" name="ERootObject" abstract="true" interface="true">
- <eStructuralFeatures xsi:type="ecore:EAttribute" name="version" lowerBound="1"
- eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="version" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="schemaLocation" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="impliedVersion" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java index 62860008af..32ef119952 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java @@ -13,6 +13,7 @@ package org.eclipse.jpt.common.core.resource.xml; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EOperation; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.impl.EPackageImpl; @@ -99,13 +100,22 @@ public class CommonPackage extends EPackageImpl public static final int EROOT_OBJECT__SCHEMA_LOCATION = 1; /** + * The feature id for the '<em><b>Implied Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT__IMPLIED_VERSION = 2; + + /** * The number of structural features of the '<em>ERoot Object</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated * @ordered */ - public static final int EROOT_OBJECT_FEATURE_COUNT = 2; + public static final int EROOT_OBJECT_FEATURE_COUNT = 3; /** * The meta object id for the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl <em>ERoot Object Impl</em>}' class. @@ -136,6 +146,15 @@ public class CommonPackage extends EPackageImpl public static final int EROOT_OBJECT_IMPL__SCHEMA_LOCATION = EROOT_OBJECT__SCHEMA_LOCATION; /** + * The feature id for the '<em><b>Implied Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT_IMPL__IMPLIED_VERSION = EROOT_OBJECT__IMPLIED_VERSION; + + /** * The number of structural features of the '<em>ERoot Object Impl</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -281,6 +300,21 @@ public class CommonPackage extends EPackageImpl /** + * Returns the meta object for the attribute '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getImpliedVersion <em>Implied Version</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Implied Version</em>'. + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject#getImpliedVersion() + * @see #getERootObject() + * @generated + */ + public EAttribute getERootObject_ImpliedVersion() + { + return (EAttribute)eRootObjectEClass.getEStructuralFeatures().get(2); + } + + + /** * Returns the factory that creates the instances of the model. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -317,6 +351,7 @@ public class CommonPackage extends EPackageImpl eRootObjectEClass = createEClass(EROOT_OBJECT); createEAttribute(eRootObjectEClass, EROOT_OBJECT__VERSION); createEAttribute(eRootObjectEClass, EROOT_OBJECT__SCHEMA_LOCATION); + createEAttribute(eRootObjectEClass, EROOT_OBJECT__IMPLIED_VERSION); } /** @@ -354,8 +389,9 @@ public class CommonPackage extends EPackageImpl initEClass(eRootObjectImplEClass, ERootObjectImpl.class, "ERootObjectImpl", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEClass(eRootObjectEClass, ERootObject.class, "ERootObject", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getERootObject_Version(), ecorePackage.getEString(), "version", null, 1, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getERootObject_Version(), ecorePackage.getEString(), "version", null, 0, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getERootObject_SchemaLocation(), ecorePackage.getEString(), "schemaLocation", null, 1, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getERootObject_ImpliedVersion(), ecorePackage.getEString(), "impliedVersion", null, 0, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); // Create resource createResource(eNS_URI); @@ -411,6 +447,14 @@ public class CommonPackage extends EPackageImpl */ public static final EAttribute EROOT_OBJECT__SCHEMA_LOCATION = eINSTANCE.getERootObject_SchemaLocation(); + /** + * The meta object literal for the '<em><b>Implied Version</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute EROOT_OBJECT__IMPLIED_VERSION = eINSTANCE.getERootObject_ImpliedVersion(); + } } //CommonPackage diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java index 8f9fec5fbc..0117173846 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java @@ -30,6 +30,7 @@ import org.eclipse.jpt.common.core.utility.TextRange; * <ul> * <li>{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getVersion <em>Version</em>}</li> * <li>{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getSchemaLocation <em>Schema Location</em>}</li> + * <li>{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getImpliedVersion <em>Implied Version</em>}</li> * </ul> * </p> * @@ -51,7 +52,7 @@ public interface ERootObject extends EBaseObject * @return the value of the '<em>Version</em>' attribute. * @see #setVersion(String) * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_Version() - * @model required="true" + * @model * @generated */ String getVersion(); @@ -92,5 +93,42 @@ public interface ERootObject extends EBaseObject */ void setSchemaLocation(String value); + /** + * Returns the value of the '<em><b>Implied Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Implied Version</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Implied Version</em>' attribute. + * @see #setImpliedVersion(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_ImpliedVersion() + * @model + * @generated + */ + String getImpliedVersion(); + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getImpliedVersion <em>Implied Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Implied Version</em>' attribute. + * @see #getImpliedVersion() + * @generated + */ + void setImpliedVersion(String value); + + /** + * Return either the value of {@link #getVersion()} (if set) or failing that, the version + * implied by the schema location ({@link #getImpliedVersion()}) + */ + String getDocumentVersion(); + + /** + * Sets the version and updates the schema location to correspond to the version + */ + void setDocumentVersion(String versionString); + TextRange getVersionTextRange(); } diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java index c11f483a0a..f0463e6f11 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java @@ -11,13 +11,15 @@ package org.eclipse.jpt.common.core.resource.xml; +import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.jpt.common.core.internal.utility.translators.EnumeratedValueTranslator; import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; import org.eclipse.wst.common.internal.emf.resource.ConstantAttributeTranslator; import org.eclipse.wst.common.internal.emf.resource.Translator; @@ -80,6 +82,26 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb protected String schemaLocation = SCHEMA_LOCATION_EDEFAULT; /** + * The default value of the '{@link #getImpliedVersion() <em>Implied Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getImpliedVersion() + * @generated + * @ordered + */ + protected static final String IMPLIED_VERSION_EDEFAULT = null; + + /** + * The cached value of the '{@link #getImpliedVersion() <em>Implied Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getImpliedVersion() + * @generated + * @ordered + */ + protected String impliedVersion = IMPLIED_VERSION_EDEFAULT; + + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -111,7 +133,7 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb * @return the value of the '<em>Version</em>' attribute. * @see #setVersion(String) * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_Version() - * @model required="true" + * @model * @generated */ public String getVersion() @@ -127,7 +149,7 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb * @see #getVersion() * @generated */ - protected void setVersionGen(String newVersion) + public void setVersion(String newVersion) { String oldVersion = version; version = newVersion; @@ -135,9 +157,14 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb eNotify(new ENotificationImpl(this, Notification.SET, CommonPackage.EROOT_OBJECT_IMPL__VERSION, oldVersion, version)); } - public void setVersion(String newVersion) { - setVersionGen(newVersion); - setSchemaLocation(buildSchemaLocationString(getNamespace(), getSchemaLocationForVersion(newVersion))); + public String getDocumentVersion() { + String version = getVersion(); + return (version == null) ? getImpliedVersion() : version; + } + + public void setDocumentVersion(String newVersion) { + setVersion(newVersion); + setSchemaLocation(getSchemaLocationForVersion(newVersion)); } /** @@ -167,13 +194,59 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb * @see #getSchemaLocation() * @generated */ - public void setSchemaLocation(String newSchemaLocation) + public void setSchemaLocationGen(String newSchemaLocation) { String oldSchemaLocation = schemaLocation; schemaLocation = newSchemaLocation; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION, oldSchemaLocation, schemaLocation)); } + + public void setSchemaLocation(String newSchemaLocation) { + setSchemaLocationGen(newSchemaLocation); + for (Entry<String, String> entry : schemaLocations().entrySet()) { + if (entry.getValue().equals(newSchemaLocation)) { + setImpliedVersion(entry.getKey()); + return; + } + } + setImpliedVersion(null); + } + + /** + * Returns the value of the '<em><b>Implied Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Implied Version</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Implied Version</em>' attribute. + * @see #setImpliedVersion(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_ImpliedVersion() + * @model + * @generated + */ + public String getImpliedVersion() + { + return impliedVersion; + } + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl#getImpliedVersion <em>Implied Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Implied Version</em>' attribute. + * @see #getImpliedVersion() + * @generated + */ + public void setImpliedVersion(String newImpliedVersion) + { + String oldImpliedVersion = impliedVersion; + impliedVersion = newImpliedVersion; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, CommonPackage.EROOT_OBJECT_IMPL__IMPLIED_VERSION, oldImpliedVersion, impliedVersion)); + } /** * <!-- begin-user-doc --> @@ -189,6 +262,8 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb return getVersion(); case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: return getSchemaLocation(); + case CommonPackage.EROOT_OBJECT_IMPL__IMPLIED_VERSION: + return getImpliedVersion(); } return super.eGet(featureID, resolve, coreType); } @@ -209,6 +284,9 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: setSchemaLocation((String)newValue); return; + case CommonPackage.EROOT_OBJECT_IMPL__IMPLIED_VERSION: + setImpliedVersion((String)newValue); + return; } super.eSet(featureID, newValue); } @@ -229,6 +307,9 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: setSchemaLocation(SCHEMA_LOCATION_EDEFAULT); return; + case CommonPackage.EROOT_OBJECT_IMPL__IMPLIED_VERSION: + setImpliedVersion(IMPLIED_VERSION_EDEFAULT); + return; } super.eUnset(featureID); } @@ -247,6 +328,8 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb return VERSION_EDEFAULT == null ? version != null : !VERSION_EDEFAULT.equals(version); case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: return SCHEMA_LOCATION_EDEFAULT == null ? schemaLocation != null : !SCHEMA_LOCATION_EDEFAULT.equals(schemaLocation); + case CommonPackage.EROOT_OBJECT_IMPL__IMPLIED_VERSION: + return IMPLIED_VERSION_EDEFAULT == null ? impliedVersion != null : !IMPLIED_VERSION_EDEFAULT.equals(impliedVersion); } return super.eIsSet(featureID); } @@ -266,6 +349,8 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb result.append(version); result.append(", schemaLocation: "); result.append(schemaLocation); + result.append(", impliedVersion: "); + result.append(impliedVersion); result.append(')'); return result.toString(); } @@ -282,7 +367,11 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb protected abstract String getNamespace(); - protected abstract String getSchemaLocationForVersion(String version); + protected abstract HashMap<String, String> schemaLocations(); + + protected String getSchemaLocationForVersion(String version) { + return schemaLocations().get(version); + } private static String buildSchemaLocationString(String namespace, String schemaLocation) { return namespace + ' ' + schemaLocation; @@ -323,12 +412,19 @@ public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootOb @Override protected Iterable<String> getEnumeratedObjectValues() { - return new TransformationIterable<String, String>(versionsToSchemaLocations.values()) { - @Override - protected String transform(String next) { - return buildSchemaLocationString(namespace, next); - } - }; + return versionsToSchemaLocations.values(); + } + + @Override + public Object convertStringToValue(String string, EObject owner) { + String[] split = string.split("\\s+"); // splits on any whitespace + int length = split.length; + return (length == 0) ? null : split[length - 1]; + } + + @Override + public String convertValueToString(Object value, EObject owner) { + return buildSchemaLocationString(namespace, (String) value); } }; } diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java index 7ee51dc154..db5d391b07 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java @@ -85,7 +85,7 @@ public class JptXmlResource public String getVersion() { ERootObject root = this.getRootObject(); - return (root == null) ? null : root.getVersion(); + return (root == null) ? null : root.getDocumentVersion(); } /** |