Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-08-28 12:25:28 -0400
committerpelder2008-08-28 12:25:28 -0400
commit1bae69b75b8c505b61e3c5da7cfdb6ec071f3152 (patch)
tree3bfd1ae72bd1acfb9446a0b19e2e46e91a963974
parentd961087f3ba0911b6181def3e0cb8476b36287f9 (diff)
downloadorg.eclipse.jet-1bae69b75b8c505b61e3c5da7cfdb6ec071f3152.tar.gz
org.eclipse.jet-1bae69b75b8c505b61e3c5da7cfdb6ec071f3152.tar.xz
org.eclipse.jet-1bae69b75b8c505b61e3c5da7cfdb6ec071f3152.zip
[245398,245400,245401] XPath steps matching substitution group head members produce unpredictable results - commit to head
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java135
-rw-r--r--tests/org.eclipse.jet.tests-feature/feature.xml2
-rw-r--r--tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF2
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup/ChildrenOnly.xml5
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup/MixedChildren.xml7
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup/SpecialChildrenOnly.xml5
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup/XMLSchemaWithGroups.xsd36
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup_2.4/ChildrenOnly.xml5
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup_2.4/MixedChildren.xml7
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup_2.4/SpecialChildrenOnly.xml5
-rw-r--r--tests/org.eclipse.jet.tests/data/substGroup_2.4/XMLSchemaWithGroups.xsd38
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractSubstitutionGroupTests.java128
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java18
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXML24SubstitutionGroupTests.java40
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/LegacyEMFXMLSubstitutionGroupTests.java28
16 files changed, 419 insertions, 43 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java
index f5282ab..9de85df 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java
@@ -17,6 +17,7 @@ package org.eclipse.jet.internal.xpath.inspectors;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -67,6 +68,8 @@ import org.eclipse.jet.xpath.inspector.SimpleElementRequiresValueException;
public class EObjectInspector implements IElementInspector, INodeInspectorExtension1
{
+ private static final String SCHEMA_ELEMENT_PREFIX = "_schema-element_"; //$NON-NLS-1$
+
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
/**
@@ -727,47 +730,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (isXMLNode(eClass))
{
- ExtendedMetaData exMD = getExtendedMetaData(eObject);
-// Object[] allChildren = getChildren(eObject);
- final List allElementsFeatures = exMD.getAllElements(eClass);
-// List result = new ArrayList(allElementsFeatures.size());
- for (Iterator i = allElementsFeatures.iterator(); i.hasNext();)
- {
- EStructuralFeature feature = (EStructuralFeature)i.next();
- final int featureKind = exMD.getFeatureKind(feature);
- if(featureKind == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE || featureKind == ExtendedMetaData.GROUP_FEATURE) {
- // for feature-maps, traverse the entry list, looking entries matching the given feature name
- FeatureMap fm = (FeatureMap)eObject.eGet(feature, true);
- List result = new ArrayList(fm.size());
- for (Iterator ifm = fm.iterator(); ifm.hasNext();)
- {
- FeatureMap.Entry entry = (FeatureMap.Entry)ifm.next();
- final EStructuralFeature entryFeature = entry.getEStructuralFeature();
- final NodeKind nodeKind = XMLTypeUtil2.getNodeKind(entryFeature);
- if(nodeKind == NodeKind.ELEMENT && matchesFeature(nameTestExpandedName, entryFeature, exMD))
- {
- if (entryFeature instanceof EAttribute)
- {
- result.add(new EMFEAttrAsElementWrapper(new AnyAttributeSetting(entry, eObject)));
- }
- else
- {
- result.add(entry.getValue());
- }
- }
-
- }
- // only return if we actually match, if we don't, we want to continue looking at the next feature
- if(result.size() > 0) {
- return result.toArray();
- }
- }
- else if(matchesFeature(nameTestExpandedName, feature, exMD))
- {
- return getFeatureValue(eObject, feature);
- }
- }
- return new Object[0];
+ return getXMLNamedElement(eObject, eClass, nameTestExpandedName);
}
else
@@ -806,6 +769,96 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
}
+ private Object[] getXMLNamedElement(EObject eObject, EClass eClass, ExpandedName nameTestExpandedName)
+ {
+ final ExtendedMetaData exMD = getExtendedMetaData(eObject);
+// exMD.get
+ final String testNsURI = nameTestExpandedName.getNamespaceURI();
+ boolean isSchemaElementTest = false;
+ String testLocalPart = nameTestExpandedName.getLocalPart();
+ if(testLocalPart.startsWith(SCHEMA_ELEMENT_PREFIX)) {
+ testLocalPart = testLocalPart.substring(SCHEMA_ELEMENT_PREFIX.length());
+ isSchemaElementTest = true;
+ }
+
+ final String[] namespacesToTry = testNsURI != null ? new String[] {testNsURI} : getApplicableNamespaces(exMD, eObject,eClass);
+ EStructuralFeature feature = null;
+ for (int i = 0; i < namespacesToTry.length && feature == null; i++)
+ {
+ feature = exMD.getElement(eClass, namespacesToTry[i], testLocalPart);
+ }
+
+ if(feature == null && namespacesToTry.length == 1 && namespacesToTry[0] == null) {
+ // if the document has not namespace, getElement doesn't find elements registered on document root
+ // try to find it ourselves...
+ EObject rootContainer = EcoreUtil.getRootContainer(eObject);
+ feature = exMD.getElement(rootContainer.eClass(), null, testLocalPart);
+ }
+ if(feature == null) {
+ // didn't find a direct feature, see if there is a 'demand' feature...
+ feature = exMD.demandFeature(testNsURI, testLocalPart, true);
+ }
+
+ if(feature != null) {
+ EStructuralFeature affiliation = exMD.getAffiliation(eClass, feature);
+ final int affiliationKind = exMD.getFeatureKind(affiliation);
+ if(affiliationKind == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE) {
+ FeatureMap fm = (FeatureMap)eObject.eGet(affiliation);
+ return fm.list(feature).toArray();
+ } else {
+ Object[] values = getFeatureValue(eObject, affiliation);
+ // Can get here in the following cases:
+ // 1) testLocalPart(feature) is the head of a substitution group
+ // In this case, affiliation == feature, but values includes all group members.
+ // Unless isSchemaElementTest == true, must filter for actual instances of feature.getEType()
+ // 2) testLocalPart(feature) is a substitution group member (not the head)
+ // In this case, affiliation is the head and values includes all group members.
+ // Must filter for actual instances of feature.getEType()
+ // 3) testLocalPart(feature) is a local or global element not associated with a feature map
+ // In this case, affiliation == feature and values contains only feature.getEType() instances.
+ // 4) testLocalPart(feature) is a global type and
+ // So, unless isSchemaElementTest is true, we must filter...
+ if(!isSchemaElementTest) {
+ // Filter the result to those that match the declared type of the feature
+ // This is necessary because as of EMF 2.4, substitution groups map to a single
+ // e-feature without a feature map
+ List newValues = new ArrayList(Arrays.asList(values));
+ for (Iterator i = newValues.iterator(); i.hasNext();)
+ {
+ Object candidate = i.next();
+ // candidate may be an instance of AnyType, which indicates
+ // an element for which no schema information was available. In such
+ // cases, there is no possibility of substitution, and there is no
+ // need to filter the element
+ if(candidate instanceof EObject
+ && !(candidate instanceof AnyType)
+ && ((EObject)candidate).eClass() != feature.getEType()) {
+ i.remove();
+ }
+ }
+ values = newValues.toArray();
+ }
+ return values;
+ }
+ } else {
+ return new Object[0];
+ }
+ }
+
+ private String[] getApplicableNamespaces(ExtendedMetaData exMD, EObject eObject, EClass eClass)
+ {
+ EObject rootContainer = EcoreUtil.getRootContainer(eObject);
+ EReference prefixMapFeature = exMD.getXMLNSPrefixMapFeature(rootContainer.eClass());
+ if(prefixMapFeature != null) {
+ EcoreEMap map = (EcoreEMap)rootContainer.eGet(prefixMapFeature);
+ String[] nsArray = (String[])map.values().toArray(new String[map.values().size()+1]);
+ nsArray[nsArray.length - 1] = null;
+ return nsArray;
+ } else {
+ return new String[] {null};
+ }
+ }
+
/**
* @param eObject
diff --git a/tests/org.eclipse.jet.tests-feature/feature.xml b/tests/org.eclipse.jet.tests-feature/feature.xml
index 787d35f..caa7031 100644
--- a/tests/org.eclipse.jet.tests-feature/feature.xml
+++ b/tests/org.eclipse.jet.tests-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jet.tests"
label="%featureName"
- version="0.9.0.qualifier"
+ version="0.9.100.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/modeling/m2t">
diff --git a/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
index 6e54c3d..a41f2cc 100644
--- a/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.jet.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jet.tests;singleton:=true
-Bundle-Version: 0.9.0.qualifier
+Bundle-Version: 0.9.100.qualifier
Bundle-ClassPath: tests.jar
Bundle-Localization: plugin
Require-Bundle: org.eclipse.jet,
diff --git a/tests/org.eclipse.jet.tests/data/substGroup/ChildrenOnly.xml b/tests/org.eclipse.jet.tests/data/substGroup/ChildrenOnly.xml
new file mode 100644
index 0000000..c806657
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup/ChildrenOnly.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:child name="Francis"/>
+ <tns:child name="Jason"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup/MixedChildren.xml b/tests/org.eclipse.jet.tests/data/substGroup/MixedChildren.xml
new file mode 100644
index 0000000..bd715e9
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup/MixedChildren.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:child name="James"/>
+ <tns:specialChild name="Harry" specialNeed="Lots of Action"/>
+ <tns:child name="Lilly"/>
+ <tns:specialChild name="Dudley" specialNeed="Lots of Candy"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup/SpecialChildrenOnly.xml b/tests/org.eclipse.jet.tests/data/substGroup/SpecialChildrenOnly.xml
new file mode 100644
index 0000000..36aa2ef
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup/SpecialChildrenOnly.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:specialChild name="Jim" specialNeed="Lots of Food"/>
+ <tns:specialChild name="Bob" specialNeed="Lots of TV"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup/XMLSchemaWithGroups.xsd b/tests/org.eclipse.jet.tests/data/substGroup/XMLSchemaWithGroups.xsd
new file mode 100644
index 0000000..77ec9da
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup/XMLSchemaWithGroups.xsd
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/XMLSchemaWithGroups" xmlns:tns="http://www.example.org/XMLSchemaWithGroups" elementFormDefault="qualified">
+
+ <element name="topElement">
+ <complexType>
+ <sequence>
+ <element ref="tns:child" maxOccurs="unbounded" minOccurs="0"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+
+
+ <element name="child" type="tns:childComplexType">
+ </element>
+
+ <element name="specialChild" type="tns:SpecialChildComplexType" substitutionGroup="tns:child"></element>
+ <complexType name="childComplexType">
+ <sequence>
+ <element name="hobby" maxOccurs="unbounded" minOccurs="0">
+ <complexType>
+ <attribute name="type" type="string" use="required"></attribute>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute use="required" name="name" type="string"></attribute>
+ </complexType>
+
+ <complexType name="SpecialChildComplexType">
+ <complexContent>
+ <extension base="tns:childComplexType">
+ <attribute name="specialNeed" type="string" use="required"></attribute>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/data/substGroup_2.4/ChildrenOnly.xml b/tests/org.eclipse.jet.tests/data/substGroup_2.4/ChildrenOnly.xml
new file mode 100644
index 0000000..c806657
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup_2.4/ChildrenOnly.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:child name="Francis"/>
+ <tns:child name="Jason"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup_2.4/MixedChildren.xml b/tests/org.eclipse.jet.tests/data/substGroup_2.4/MixedChildren.xml
new file mode 100644
index 0000000..bd715e9
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup_2.4/MixedChildren.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:child name="James"/>
+ <tns:specialChild name="Harry" specialNeed="Lots of Action"/>
+ <tns:child name="Lilly"/>
+ <tns:specialChild name="Dudley" specialNeed="Lots of Candy"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup_2.4/SpecialChildrenOnly.xml b/tests/org.eclipse.jet.tests/data/substGroup_2.4/SpecialChildrenOnly.xml
new file mode 100644
index 0000000..36aa2ef
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup_2.4/SpecialChildrenOnly.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:topElement xmlns:tns="http://www.example.org/XMLSchemaWithGroups" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/XMLSchemaWithGroups XMLSchemaWithGroups.xsd ">
+ <tns:specialChild name="Jim" specialNeed="Lots of Food"/>
+ <tns:specialChild name="Bob" specialNeed="Lots of TV"/>
+</tns:topElement>
diff --git a/tests/org.eclipse.jet.tests/data/substGroup_2.4/XMLSchemaWithGroups.xsd b/tests/org.eclipse.jet.tests/data/substGroup_2.4/XMLSchemaWithGroups.xsd
new file mode 100644
index 0000000..b07e459
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/substGroup_2.4/XMLSchemaWithGroups.xsd
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/XMLSchemaWithGroups" xmlns:tns="http://www.example.org/XMLSchemaWithGroups" elementFormDefault="qualified"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ ecore:ignoreSubstitutionGroups="true">
+
+ <element name="topElement">
+ <complexType>
+ <sequence>
+ <element ref="tns:child" maxOccurs="unbounded" minOccurs="0"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+
+
+ <element name="child" type="tns:childComplexType">
+ </element>
+
+ <element name="specialChild" type="tns:SpecialChildComplexType" substitutionGroup="tns:child"></element>
+ <complexType name="childComplexType">
+ <sequence>
+ <element name="hobby" maxOccurs="unbounded" minOccurs="0">
+ <complexType>
+ <attribute name="type" type="string" use="required"></attribute>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute use="required" name="name" type="string"></attribute>
+ </complexType>
+
+ <complexType name="SpecialChildComplexType">
+ <complexContent>
+ <extension base="tns:childComplexType">
+ <attribute name="specialNeed" type="string" use="required"></attribute>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
index 6445e93..c1fd966 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/AllTests.java
@@ -10,6 +10,7 @@ public class AllTests {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests");
suite.addTest(org.eclipse.jet.tests.compiler.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.xpath.AllTests.suite());
+ suite.addTest(org.eclipse.jet.tests.xpath.inspectors.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.xpath.functions.extras.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.model.load.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.taglib.AllTests.suite());
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractSubstitutionGroupTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractSubstitutionGroupTests.java
new file mode 100644
index 0000000..9427616
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractSubstitutionGroupTests.java
@@ -0,0 +1,128 @@
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jet.runtime.model.IModelLoader;
+import org.eclipse.jet.xpath.XPath;
+import org.eclipse.jet.xpath.XPathException;
+import org.eclipse.jet.xpath.XPathExpression;
+import org.eclipse.jet.xpath.XPathFactory;
+import org.eclipse.jet.xpath.XPathUtil;
+
+public abstract class AbstractSubstitutionGroupTests extends TestCase {
+
+ private final XPath xpathEngine = XPathFactory.newInstance().newXPath(null);
+
+ public AbstractSubstitutionGroupTests() {
+ super();
+ }
+
+ protected abstract URL getPluginURL() throws MalformedURLException;
+
+ protected abstract String getTestDataFolder();
+
+ protected abstract IModelLoader getModelLoader();
+
+ public AbstractSubstitutionGroupTests(String name) {
+ super(name);
+ }
+
+ public void testHeadElementOnly() throws XPathException, IOException {
+ final Object documentRoot = loadEMFXML("ChildrenOnly.xml");
+
+ final String xpath = "/topElement/child";
+
+ final XPathExpression compiledXPath = xpathEngine.compile(xpath);
+
+ Collection result = compiledXPath.evaluateAsNodeSet(documentRoot);
+
+ assertEquals("result.size()", 2, result.size());
+ Object[] resultArray = result.toArray();
+
+ assertEquals("result[0]/@name", "Francis", getXPath(resultArray[0], "@name"));
+ assertEquals("result[1]/@name", "Jason", getXPath(resultArray[1], "@name"));
+ }
+
+ public void testMixedChildren_child() throws XPathException, IOException {
+ final Object documentRoot = loadEMFXML("MixedChildren.xml");
+
+ final String xpath = "/topElement/child";
+
+ final XPathExpression compiledXPath = xpathEngine.compile(xpath);
+
+ Collection result = compiledXPath.evaluateAsNodeSet(documentRoot);
+
+ assertEquals("result.size()", 2, result.size());
+ Object[] resultArray = result.toArray();
+
+ assertEquals("result[0]/@name", "James", getXPath(resultArray[0], "@name"));
+ assertEquals("result[1]/@name", "Lilly", getXPath(resultArray[1], "@name"));
+ }
+
+ public void testMixedChildren_specialChild() throws XPathException,
+ IOException {
+ final Object documentRoot = loadEMFXML("MixedChildren.xml");
+
+ final String xpath = "/topElement/specialChild";
+
+ final XPathExpression compiledXPath = xpathEngine.compile(xpath);
+
+ Collection result = compiledXPath.evaluateAsNodeSet(documentRoot);
+
+ assertEquals("result.size()", 2, result.size());
+ Object[] resultArray = result.toArray();
+
+ assertEquals("result[0]/@name", "Harry", getXPath(resultArray[0], "@name"));
+ assertEquals("result[1]/@name", "Dudley", getXPath(resultArray[1], "@name"));
+ }
+
+ public void testMixedChildren_schema_element_child() throws XPathException,
+ IOException {
+ final Object documentRoot = loadEMFXML("MixedChildren.xml");
+
+ final String xpath = "/topElement/_schema-element_child";
+
+ final XPathExpression compiledXPath = xpathEngine.compile(xpath);
+
+ Collection result = compiledXPath.evaluateAsNodeSet(documentRoot);
+
+ assertEquals("result.size()", 4, result.size());
+ Object[] resultArray = result.toArray();
+
+ assertEquals("result[0]/@name", "James", getXPath(resultArray[0], "@name"));
+ assertEquals("result[1]/@name", "Harry", getXPath(resultArray[1], "@name"));
+ assertEquals("result[0]/@name", "Lilly", getXPath(resultArray[2], "@name"));
+ assertEquals("result[1]/@name", "Dudley", getXPath(resultArray[3], "@name"));
+ }
+
+ public void testSpecialChildrenOnly() throws XPathException, IOException {
+ final Object documentRoot = loadEMFXML("SpecialChildrenOnly.xml");
+
+ final String xpath = "/topElement/child";
+
+ final XPathExpression compiledXPath = xpathEngine.compile(xpath);
+
+ Collection result = compiledXPath.evaluateAsNodeSet(documentRoot);
+
+ assertEquals("result.size()", 0, result.size());
+ }
+
+ private String getXPath(Object contextObject, String expression) throws XPathException {
+ final XPathExpression compiledExpression = xpathEngine.compile(expression);
+ return XPathUtil.xpathString(compiledExpression.evaluate(contextObject));
+ }
+
+ private Object loadEMFXML(String pluginRelativePath) throws IOException {
+ final IModelLoader loader = getModelLoader();
+ final URL baseURL = getPluginURL();
+ final URL resourceURL = new URL(baseURL, getTestDataFolder() + pluginRelativePath);
+ return loader.load(resourceURL);
+
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java
new file mode 100644
index 0000000..7cb6e9c
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java
@@ -0,0 +1,18 @@
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.eclipse.jet.tests.xpath.inspectors");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(EMFXML24SubstitutionGroupTests.class);
+ suite.addTestSuite(LegacyEMFXMLSubstitutionGroupTests.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXML24SubstitutionGroupTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXML24SubstitutionGroupTests.java
new file mode 100644
index 0000000..48c5ddb
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXML24SubstitutionGroupTests.java
@@ -0,0 +1,40 @@
+/**
+ *
+ */
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.jet.internal.runtime.model.EMFXMLModelLoader;
+import org.eclipse.jet.runtime.model.IModelLoader;
+
+/**
+ * Perform substitution group tests using EMF 2.4 style schemas
+ *
+ */
+public class EMFXML24SubstitutionGroupTests extends
+ AbstractSubstitutionGroupTests {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tests.xpath.inspectors.AbstractSubstitutionGroupTests#getModelLoader()
+ */
+ protected IModelLoader getModelLoader() {
+ return new EMFXMLModelLoader();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tests.xpath.inspectors.AbstractSubstitutionGroupTests#getPluginURL()
+ */
+ protected URL getPluginURL() throws MalformedURLException {
+ return new URL("platform:/plugin/org.eclipse.jet.tests/");
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.tests.xpath.inspectors.AbstractSubstitutionGroupTests#getTestDataFolder()
+ */
+ protected String getTestDataFolder() {
+ return "data/substGroup_2.4/";
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/LegacyEMFXMLSubstitutionGroupTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/LegacyEMFXMLSubstitutionGroupTests.java
new file mode 100644
index 0000000..ec289fe
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/LegacyEMFXMLSubstitutionGroupTests.java
@@ -0,0 +1,28 @@
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+import org.eclipse.jet.internal.runtime.model.EMFXMLModelLoader;
+import org.eclipse.jet.runtime.model.IModelLoader;
+
+/**
+ * Perform substitution group tests using legacy (pre EMF 2.4) substitution groups
+ *
+ */
+public class LegacyEMFXMLSubstitutionGroupTests extends AbstractSubstitutionGroupTests {
+
+ protected IModelLoader getModelLoader() {
+ return new EMFXMLModelLoader();
+ }
+
+ protected String getTestDataFolder() {
+ return "data/substGroup/";
+ }
+
+ protected URL getPluginURL() throws MalformedURLException {
+ return new URL("platform:/plugin/org.eclipse.jet.tests/");
+ }
+
+}

Back to the top