summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-05-02 17:16:58 (EDT)
committer pelder2007-05-02 17:16:58 (EDT)
commitaead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1 (patch)
treec264474f6553b29fa6e3da18c2cc20621da79ffa
parent8e67ef4fb3949b9c4c899f0d4f0e787e2968fa14 (diff)
downloadorg.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.zip
org.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.tar.gz
org.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.tar.bz2
[175036] Use extendedMeta data to determine element and attribute names.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java108
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EStructuralFeatureSettingInspector.java29
-rw-r--r--tests/org.eclipse.jet.tests/data/DOMInspector.xml2
-rw-r--r--tests/org.eclipse.jet.tests/data/beans.xsd1
-rw-r--r--tests/org.eclipse.jet.tests/data/library.xml2
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java3
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java124
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java21
8 files changed, 197 insertions, 93 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 a45f41b..05491aa 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
@@ -18,8 +18,11 @@ package org.eclipse.jet.internal.xpath.inspectors;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.EList;
@@ -35,6 +38,8 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.EcoreEMap;
import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -65,7 +70,10 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- private final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData();
+ /**
+ *
+ */
+ private final static Map resourceSetMetaData = Collections.synchronizedMap(new WeakHashMap());
protected static final Object[] EMPTY_ARRAY = new Object []{};
@@ -97,14 +105,15 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
*/
private Object[] getAttributesInternal(EObject eObject, boolean includeUnsets)
{
+ ExtendedMetaData exMD = getExtendedMetaData(eObject);
// this is all the EStructuralFeatures that are explicitly tagged as
// attributes...
- List allAttributes = new ArrayList(getExtendedMetaData().getAllAttributes(eObject.eClass()));
+ List allAttributes = new ArrayList(exMD.getAllAttributes(eObject.eClass()));
// now add those EAttributes which don't have an explicit metadata...
for (Iterator i = eObject.eClass().getEAllAttributes().iterator(); i.hasNext();)
{
EAttribute attribute = (EAttribute)i.next();
- if (getExtendedMetaData().getFeatureKind(attribute) == ExtendedMetaData.UNSPECIFIED_FEATURE)
+ if (exMD.getFeatureKind(attribute) == ExtendedMetaData.UNSPECIFIED_FEATURE)
{
allAttributes.add(attribute);
}
@@ -118,7 +127,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (eObject.eIsSet(feature) || includeUnsets)
{
- if (getExtendedMetaData().getFeatureKind(feature) == ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE)
+ if (exMD.getFeatureKind(feature) == ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE)
{
// this feature represents an anyAttribute wildcard, extract
// from the FeatureMap the actual attributes/features.
@@ -174,12 +183,13 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
// the extendedMetaData.getAttribute() fails to find schema-based
// attributes.
//
+ ExtendedMetaData exMD = getExtendedMetaData(eObject);
Object[] allAttributeSettings = getAttributesInternal(eObject, true);
for (int i = 0; i < allAttributeSettings.length; i++)
{
EStructuralFeature.Setting setting = (EStructuralFeature.Setting)allAttributeSettings[i];
EStructuralFeature settingFeature = setting.getEStructuralFeature();
- if (matchesFeature(nameTestExpandedName, settingFeature))
+ if (matchesFeature(nameTestExpandedName, settingFeature, exMD))
{
return setting;
}
@@ -240,22 +250,24 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
/**
* @param expandedName
* @param feature
+ * @param exMD TODO
* @return
*/
- private boolean matchesFeature(ExpandedName expandedName, EStructuralFeature feature)
+ private boolean matchesFeature(ExpandedName expandedName, EStructuralFeature feature, ExtendedMetaData exMD)
{
- ExpandedName featureEN = expandedNameOfFeature(feature);
+ ExpandedName featureEN = internalExpandedNameOfFeature(feature, exMD);
final boolean equals = expandedName.equals(featureEN) || expandedName.equals(new ExpandedName(feature.getName()));
return equals;
}
/**
* @param feature
+ * @param exMD TODO
* @return
*/
- private ExpandedName expandedNameOfFeature(EStructuralFeature feature)
+ private ExpandedName internalExpandedNameOfFeature(EStructuralFeature feature, ExtendedMetaData exMD)
{
- ExpandedName featureEN = new ExpandedName(getExtendedMetaData().getNamespace(feature), feature.getName());
+ ExpandedName featureEN = new ExpandedName(exMD.getNamespace(feature), exMD.getName(feature));
return featureEN;
}
@@ -284,10 +296,10 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
return true;
}
- final EStructuralFeature feature = getExtendedMetaData().demandFeature(null,
+ final EStructuralFeature feature = getExtendedMetaData(eObject).demandFeature(null,
attributeName,
false);
- EStructuralFeature affiliation = getExtendedMetaData().getAffiliation(eClass, feature);
+ EStructuralFeature affiliation = getExtendedMetaData(eObject).getAffiliation(eClass, feature);
if (affiliation != null)
{
eObject.eSet(feature, value);
@@ -311,7 +323,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
// mostly EObjects map to ELEMENTs, but some EObjects are
// ATTRIBUTES.
// We check the extended meta data on the containing feature to see.
- switch (getExtendedMetaData().getFeatureKind(containingFeature))
+ switch (getExtendedMetaData(eObject).getFeatureKind(containingFeature))
{
case ExtendedMetaData.ATTRIBUTE_FEATURE:
case ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE:
@@ -319,7 +331,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
break;
}
}
- else if (EMPTY_STRING.equals(getExtendedMetaData().getName(eObject.eClass())))
+ else if (EMPTY_STRING.equals(getExtendedMetaData(eObject).getName(eObject.eClass())))
{
// it's a XML Document Root.
result = NodeKind.ROOT;
@@ -354,14 +366,14 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
EClass eClass = eObject.eClass();
if (isXMLNode(eClass))
{
- switch (getExtendedMetaData().getContentKind(eClass))
+ switch (getExtendedMetaData(eObject).getContentKind(eClass))
{
case ExtendedMetaData.UNSPECIFIED_CONTENT:
case ExtendedMetaData.EMPTY_CONTENT:
return EMPTY_STRING;
case ExtendedMetaData.SIMPLE_CONTENT:
{
- EStructuralFeature simpleFeature = getExtendedMetaData().getSimpleFeature(eClass);
+ EStructuralFeature simpleFeature = getExtendedMetaData(eObject).getSimpleFeature(eClass);
final Object rawValue = eObject.eGet(simpleFeature);
return stringValueOfFeature(simpleFeature, rawValue);
}
@@ -442,7 +454,8 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (feature != null && isXMLNode(eClass))
{
- return expandedNameOfFeature(feature);
+ ExtendedMetaData exMD = getExtendedMetaData(eObject);
+ return internalExpandedNameOfFeature(feature, exMD);
}
else if (feature != null)
{
@@ -474,7 +487,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (isXMLNode(eClass))
{
- switch (getExtendedMetaData().getContentKind(eClass))
+ switch (getExtendedMetaData(eObject).getContentKind(eClass))
{
case ExtendedMetaData.UNSPECIFIED_CONTENT:
case ExtendedMetaData.EMPTY_CONTENT:
@@ -482,12 +495,12 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
return EMPTY_ARRAY;
case ExtendedMetaData.ELEMENT_ONLY_CONTENT:
{
- final List allElementsFeatures = getExtendedMetaData().getAllElements(eClass);
+ final List allElementsFeatures = getExtendedMetaData(eObject).getAllElements(eClass);
List result = new ArrayList(allElementsFeatures.size());
for (Iterator i = allElementsFeatures.iterator(); i.hasNext();)
{
EStructuralFeature feature = (EStructuralFeature)i.next();
- switch (getExtendedMetaData().getFeatureKind(feature))
+ switch (getExtendedMetaData(eObject).getFeatureKind(feature))
{
case ExtendedMetaData.ELEMENT_FEATURE:
if (feature instanceof EAttribute)
@@ -549,7 +562,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
case ExtendedMetaData.MIXED_CONTENT:
{
- EAttribute mixedFeature = getExtendedMetaData().getMixedFeature(eClass);
+ EAttribute mixedFeature = getExtendedMetaData(eObject).getMixedFeature(eClass);
FeatureMap featureMap = (FeatureMap)eObject.eGet(mixedFeature);
Object[] result = new Object [featureMap.size()];
int resultIndex = 0;
@@ -593,7 +606,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
for (EObject parent = eObject; parent != null; parent = parent.eContainer())
{
// we know document roots have an empty name in the extended metadata.
- if (EMPTY_STRING.equals(getExtendedMetaData().getName(parent.eClass())))
+ if (EMPTY_STRING.equals(getExtendedMetaData(eObject).getName(parent.eClass())))
{
return parent;
}
@@ -630,7 +643,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
Object root = inspector.getDocumentRoot(eObject);
if (root instanceof EObject)
{
- String namespace2 = getExtendedMetaData().getNamespace(feature);
+ String namespace2 = getExtendedMetaData(eObject).getNamespace(feature);
if (namespace2 == null)
{
nsPrefix = null;
@@ -639,7 +652,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
{
// it's a DocumentRoot, look up the namespace prefix map.
EObject rootEObject = (EObject)root;
- EReference prefixMapFeature = getExtendedMetaData().getXMLNSPrefixMapFeature(rootEObject.eClass());
+ EReference prefixMapFeature = getExtendedMetaData(eObject).getXMLNSPrefixMapFeature(rootEObject.eClass());
if (prefixMapFeature != null)
{
EcoreEMap xmlnsPrefixMap = (EcoreEMap)rootEObject.eGet(prefixMapFeature);
@@ -682,6 +695,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (isXMLNode(eClass))
{
+ ExtendedMetaData exMD = getExtendedMetaData(eObject);
Object[] allChildren = getChildren(eObject);
List result = new ArrayList(allChildren.length);
for (int i = 0; i < allChildren.length; i++)
@@ -689,8 +703,8 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (allChildren[i] instanceof EObject)
{
EObject child = (EObject)allChildren[i];
- if (matchesFeature(nameTestExpandedName, child.eContainingFeature())
- || matchesFeature(nameTestExpandedName, child.eContainmentFeature()))
+ if (matchesFeature(nameTestExpandedName, child.eContainingFeature(), exMD)
+ || matchesFeature(nameTestExpandedName, child.eContainmentFeature(), exMD))
{
result.add(child);
}
@@ -698,7 +712,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
else if (allChildren[i] instanceof EMFEAttrAsElementWrapper)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)allChildren[i];
- if (matchesFeature(nameTestExpandedName, wrapper.getFeature()))
+ if (matchesFeature(nameTestExpandedName, wrapper.getFeature(), exMD))
{
result.add(wrapper);
}
@@ -786,7 +800,8 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
{
return false;
}
- if (!matchesFeature(expandedNameOfFeature(feature), sibling.eContainmentFeature()))
+ ExtendedMetaData exMD = getExtendedMetaData(parent);
+ if (!matchesFeature(internalExpandedNameOfFeature(feature, exMD), sibling.eContainmentFeature(), exMD))
{
return false;
}
@@ -808,11 +823,9 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
InvalidChildException
{
EObject eObject = (EObject)contextNode;
- EClass eClass = eObject.eClass();
-
EStructuralFeature feature;
- feature = getElementFeature(eClass, elementName);
+ feature = getElementFeature(eObject, elementName);
if (feature == null)
{
@@ -852,7 +865,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
private Object addElementToParent(EObject eParent, EStructuralFeature feature, Object newElement, Object addBeforeThisSibling)
{
// see if there is a feature map containing 'feature'
- EStructuralFeature affiliation = getExtendedMetaData().getAffiliation(eParent.eClass(), feature);
+ EStructuralFeature affiliation = getExtendedMetaData(eParent).getAffiliation(eParent.eClass(), feature);
if (FeatureMapUtil.isFeatureMap(affiliation))
{
FeatureMap fm = (FeatureMap)eParent.eGet(affiliation);
@@ -901,26 +914,28 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
/**
- * @param eClass
+ * @param eObject TODO
* @param elementName
+ * @param eClass
* @return
*/
- private EStructuralFeature getElementFeature(EClass eClass, ExpandedName elementName)
+ private EStructuralFeature getElementFeature(EObject eObject, ExpandedName elementName)
{
+ EClass eClass = eObject.eClass();
EStructuralFeature feature;
// find the feature that will contain the element...
String elementNS = elementName.getNamespaceURI();
String localName = elementName.getLocalPart();
if (isXMLNode(eClass))
{
- feature = getExtendedMetaData().getElement(eClass, elementNS, localName);
+ feature = getExtendedMetaData(eObject).getElement(eClass, elementNS, localName);
if (feature == null)
{
// generic XML processing creates features on the document root, look for them there...
- EStructuralFeature wildCardFeature = getExtendedMetaData().getElementWildcardAffiliation(eClass, elementNS, localName);
+ EStructuralFeature wildCardFeature = getExtendedMetaData(eObject).getElementWildcardAffiliation(eClass, elementNS, localName);
if (wildCardFeature != null)
{
- feature = getExtendedMetaData().demandFeature(elementNS, localName, true);
+ feature = getExtendedMetaData(eObject).demandFeature(elementNS, localName, true);
}
}
}
@@ -987,7 +1002,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
{
EObject eObject = (EObject)tgtParent;
- EStructuralFeature feature = getElementFeature(eObject.eClass(), new ExpandedName(name));
+ EStructuralFeature feature = getElementFeature(eObject, new ExpandedName(name));
Object newElement = null;
@@ -1007,7 +1022,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if(isXMLNode(eClass)) {
// copyReferences will have copied mixed and any features, if present
// we need to remove these...
- final EAttribute mixedFeature = extendedMetaData.getMixedFeature(eClass);
+ final EAttribute mixedFeature = getExtendedMetaData(eObject).getMixedFeature(eClass);
if(mixedFeature != null)
{
FeatureMap fm = (FeatureMap)newEObject.eGet(mixedFeature);
@@ -1037,12 +1052,11 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
public Object addTextElement(Object parentElement, String name, String bodyContent, boolean asCData) throws AddElementException
{
EObject eObject = (EObject)parentElement;
- EClass eClass = eObject.eClass();
ExpandedName elementName = new ExpandedName(name);
EStructuralFeature feature;
- feature = getElementFeature(eClass, elementName);
+ feature = getElementFeature(eObject, elementName);
if (feature == null)
{
@@ -1052,7 +1066,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
if (feature.getEType() == EcorePackage.eINSTANCE.getEObject())
{
// it's a demand created type...
- EStructuralFeature affiliation = getExtendedMetaData().getAffiliation(eObject.eClass(), feature);
+ EStructuralFeature affiliation = getExtendedMetaData(eObject).getAffiliation(eObject.eClass(), feature);
AnyType newElement = XMLTypeFactory.eINSTANCE.createAnyType();
if(asCData)
@@ -1121,10 +1135,20 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
/**
+ * @param eObject TODO
* @return Returns the extendedMetaData.
*/
- private ExtendedMetaData getExtendedMetaData()
+ public static ExtendedMetaData getExtendedMetaData(EObject eObject)
{
+ Resource resource = eObject.eResource();
+ ResourceSet resourceSet = resource == null ? null : resource.getResourceSet();
+
+ ExtendedMetaData extendedMetaData = (ExtendedMetaData)resourceSetMetaData.get(resourceSet);
+ if(extendedMetaData == null)
+ {
+ extendedMetaData = resourceSet == null ? new BasicExtendedMetaData() : new BasicExtendedMetaData(resourceSet.getPackageRegistry());
+ resourceSetMetaData.put(resourceSet, extendedMetaData);
+ }
return extendedMetaData;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EStructuralFeatureSettingInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EStructuralFeatureSettingInspector.java
index d1a5c67..56dcae2 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EStructuralFeatureSettingInspector.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EStructuralFeatureSettingInspector.java
@@ -17,8 +17,8 @@
package org.eclipse.jet.internal.xpath.inspectors;
-import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.jet.internal.xpath.functions.StringFunction;
import org.eclipse.jet.xpath.inspector.ExpandedName;
import org.eclipse.jet.xpath.inspector.INodeInspector;
@@ -31,6 +31,7 @@ import org.eclipse.jet.xpath.inspector.INodeInspector;
public class EStructuralFeatureSettingInspector implements INodeInspector
{
+ private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
/**
*
*/
@@ -71,24 +72,9 @@ public class EStructuralFeatureSettingInspector implements INodeInspector
public ExpandedName expandedNameOf(Object object)
{
EStructuralFeature.Setting setting = (EStructuralFeature.Setting)object;
- EPackage ePackage = (EPackage)setting.getEStructuralFeature().eContainer().eContainer();
- return new ExpandedName(ePackage.getNsURI(), setting.getEStructuralFeature().getName());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.xpath.INodeInspector#getAttributes(java.lang.Object)
- */
- public Object[] getAttributes(Object contextNode)
- {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jet.xpath.INodeInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.ExpandedName)
- */
- public Object getNamedAttribute(Object contextNode, ExpandedName nameTestExpandedName)
- {
- return null;
+ ExtendedMetaData exMD = EObjectInspector.getExtendedMetaData(setting.getEObject());
+ EStructuralFeature feature = setting.getEStructuralFeature();
+ return new ExpandedName(exMD.getNamespace(feature), exMD.getName(feature));
}
/* (non-Javadoc)
@@ -105,7 +91,7 @@ public class EStructuralFeatureSettingInspector implements INodeInspector
*/
public Object[] getChildren(Object contextNode)
{
- return null;
+ return EMPTY_OBJECT_ARRAY;
}
/* (non-Javadoc)
@@ -114,7 +100,8 @@ public class EStructuralFeatureSettingInspector implements INodeInspector
public String nameOf(Object contextNode)
{
EStructuralFeature.Setting setting = (EStructuralFeature.Setting)contextNode;
- return setting.getEStructuralFeature().getName();
+ ExtendedMetaData exMD = EObjectInspector.getExtendedMetaData(setting.getEObject());
+ return exMD.getName(setting.getEStructuralFeature());
}
public boolean testExpandedName(Object node, ExpandedName testName)
diff --git a/tests/org.eclipse.jet.tests/data/DOMInspector.xml b/tests/org.eclipse.jet.tests/data/DOMInspector.xml
index 9095579..dd08e67 100644
--- a/tests/org.eclipse.jet.tests/data/DOMInspector.xml
+++ b/tests/org.eclipse.jet.tests/data/DOMInspector.xml
@@ -2,7 +2,7 @@
<?eclipse version="3.0"?>
<root rootAttr="test">
<!-- a comment within root -->
- <a name="foo">
+ <a name="foo" name-with_hyphen="hello">
<b>Some foo text.</b>
</a>
<a name="bar">
diff --git a/tests/org.eclipse.jet.tests/data/beans.xsd b/tests/org.eclipse.jet.tests/data/beans.xsd
index 8635462..f886846 100644
--- a/tests/org.eclipse.jet.tests/data/beans.xsd
+++ b/tests/org.eclipse.jet.tests/data/beans.xsd
@@ -35,6 +35,7 @@
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="kind" type="xsd:string"/>
+ <xsd:attribute name="name-with_hyphen" type="xsd:string" use="optional"/>
</xsd:complexType>
<xsd:element name="root" type="root"/>
diff --git a/tests/org.eclipse.jet.tests/data/library.xml b/tests/org.eclipse.jet.tests/data/library.xml
index 51ba39c..12e1c14 100644
--- a/tests/org.eclipse.jet.tests/data/library.xml
+++ b/tests/org.eclipse.jet.tests/data/library.xml
@@ -3,7 +3,7 @@
<project name="test.beans">
<beanModel basePackage="org.example" name="Library">
<bean name="Library">
- <attribute kind="FIELD" name="name" type="String"/>
+ <attribute kind="FIELD" name="name" type="String" name-with_hyphen="hello"/>
<attribute kind="FIELD" name="yearFounded" type="int"/>
<attribute kind="DERIVED" name="yearsOpen" type="int"/>
<attribute kind="LIST" name="books" type="Book"/>
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
index e62fd77..a18bf36 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
@@ -83,8 +83,9 @@ public class DOMInspectorTests extends AbstractExprTest {
Object[] aAttributes = inspector.getAttributes(elementA);
assertNotNull(aAttributes);
- assertEquals(1, aAttributes.length);
+ assertEquals(2, aAttributes.length);
assertEquals("name", inspector.expandedNameOf(aAttributes[0]).toString());
+ assertEquals("name-with_hyphen", inspector.expandedNameOf(aAttributes[1]).toString());
assertEquals("foo", inspector.stringValueOf(aAttributes[0]));
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
index 616fd18..53b05c3 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
@@ -1,5 +1,6 @@
package org.eclipse.jet.tests.xpath;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
@@ -14,9 +15,11 @@ import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.emf.ecore.xml.type.XMLTypeDocumentRoot;
+import org.eclipse.jet.internal.runtime.model.EMFXMLModelLoader;
import org.eclipse.jet.internal.xpath.inspectors.AnyAttributeSetting;
import org.eclipse.jet.internal.xpath.inspectors.EMFEAttrAsElementWrapper;
import org.eclipse.jet.internal.xpath.inspectors.EObjectInspector;
+import org.eclipse.jet.internal.xpath.inspectors.EStructuralFeatureSettingInspector;
import org.eclipse.jet.xpath.inspector.AddElementException;
import org.eclipse.jet.xpath.inspector.CopyElementException;
import org.eclipse.jet.xpath.inspector.ExpandedName;
@@ -34,13 +37,12 @@ public class EObjectInspectorTests extends TestCase {
protected void xsdSetUp() throws Exception {
- URI fileURI = URI.createURI("platform:/plugin/org.eclipse.jet.tests/data/library.xml");
- Factory factory = new GenericXMLResourceFactoryImpl();
-
- xsdResource = factory.createResource(fileURI);
- xsdResource.load(null);
+ Object load = new EMFXMLModelLoader().load(new URL("platform:/plugin/org.eclipse.jet.tests/data/library.xml"));
+
+ assertTrue(load instanceof EObject);
- xsdDocumentRoot = (EObject) xsdResource.getContents().get(0);
+ xsdDocumentRoot = (EObject) load;
+ xsdResource = xsdDocumentRoot.eResource();
xsdRootElement = (EObject) xsdDocumentRoot.eContents().get(0);
}
@@ -124,6 +126,31 @@ public class EObjectInspectorTests extends TestCase {
assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
}
+
+
+ }
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
+ */
+ public void testGetAttributes_hyphens_xml() {
+ Object elementA1 = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+ Object[] attributes = inspector.getAttributes(elementA1);
+
+ assertNotNull(attributes);
+ String[] expectedAttributeNames = new String[] {
+ "name",
+ "name-with_hyphen",
+ };
+ String[] expectedAttributeValues = new String[] {
+ "foo",
+ "hello",
+ };
+ assertEquals(expectedAttributeNames.length, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting) attributes[i];
+ assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
+ assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
+ }
}
/*
@@ -150,6 +177,38 @@ public class EObjectInspectorTests extends TestCase {
/*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
*/
+ public void testGetAttributes_xsd_hyphens() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object[] attributes = inspector.getAttributes(attrElement);
+
+ assertNotNull(attributes);
+ String[] expectedAttributeNames = new String[] {
+ "kind",
+ "name",
+ "nameWithHyphen", // EMF has mangled name-with_hypen this to nameWithHyphen. Figure something out
+ "type",
+
+ };
+ String[] expectedAttributeValues = new String[] {
+ "FIELD",
+ "name",
+ "hello",
+ "String",
+ };
+ assertEquals(expectedAttributeNames.length, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting) attributes[i];
+ assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
+ assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
+ */
public void testGetAttributes_xsd_simpleElement() {
// testing the the <doc> element underneath attributeElement DOES NOT
// show up
@@ -157,8 +216,8 @@ public class EObjectInspectorTests extends TestCase {
EObject beanModelElement = (EObject) projectElement.eContents().get(0);
EObject thirdBeanElement = (EObject) beanModelElement.eContents().get(2);
EObject attributeElement = (EObject) thirdBeanElement.eContents().get(0);
- // verify that there is indeed a fourth EAttribute, but that we won't see it.
- assertEquals(4, attributeElement.eClass().getEAttributes().size());
+ // verify that there is indeed a fifth EAttribute, but that we won't see it.
+ assertEquals(5, attributeElement.eClass().getEAttributes().size());
Object[] attributes = inspector.getAttributes(attributeElement);
assertNotNull(attributes);
@@ -227,6 +286,14 @@ public class EObjectInspectorTests extends TestCase {
setting = (EStructuralFeature.Setting)a1Name;
assertEquals("name", setting.getEStructuralFeature().getName());
assertEquals("foo", setting.get(true));
+
+ Object a1HyphenedAttr = inspector.getNamedAttribute(elementA1, new ExpandedName("name-with_hyphen"));
+ assertNotNull(a1HyphenedAttr);
+ assertTrue("instanceof EStructuralFeature.Setting", a1HyphenedAttr instanceof EStructuralFeature.Setting);
+ setting = (EStructuralFeature.Setting)a1HyphenedAttr;
+ assertEquals("name-with_hyphen", setting.getEStructuralFeature().getName());
+ assertEquals("hello", setting.get(true));
+
}
/*
@@ -245,6 +312,25 @@ public class EObjectInspectorTests extends TestCase {
}
/*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getNamedAttribute(Object, ExpandedName)'
+ */
+ public void testGetNamedAttribute_xsd_hyphen() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object attribute = inspector.getNamedAttribute(attrElement, new ExpandedName("name-with_hyphen"));
+
+ assertNotNull(attribute);
+ assertTrue("instanceof EStructuralFeature.Setting", attribute instanceof EStructuralFeature.Setting);
+
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting)attribute;
+ assertEquals("nameWithHyphen", setting.getEStructuralFeature().getName()); // the mangled EMF name
+ assertEquals("name-with_hyphen", new EStructuralFeatureSettingInspector().nameOf(setting));
+ assertEquals("hello", setting.get(true));
+ }
+
+ /*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.createAttribute(Object, String, String)'
*/
public void testCreateAttribute_emf() {
@@ -374,7 +460,7 @@ public class EObjectInspectorTests extends TestCase {
/*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
*/
- public void testExpandedNameOf_xsd() {
+ public void testExpandedNameOf_xsd_rootElement() {
ExpandedName enEmfRoot = inspector.expandedNameOf(xsdRootElement);
assertEquals("http://www.example.org/beans:root", enEmfRoot.toString());
@@ -383,6 +469,26 @@ public class EObjectInspectorTests extends TestCase {
}
/*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
+ */
+ public void testExpandedNameOf_xsd_childElement() {
+ ExpandedName enProject = inspector.expandedNameOf(xsdRootElement.eContents().get(0));
+ assertEquals("project", enProject.toString());
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
+ */
+ public void testExpandedNameOf_xsd_hyphen() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object attribute = inspector.getNamedAttribute(attrElement, new ExpandedName("name-with_hyphen"));
+ ExpandedName enProject = new EStructuralFeatureSettingInspector().expandedNameOf(attribute);
+ assertEquals("name-with_hyphen", enProject.toString());
+ }
+ /*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getDocumentRoot(Object)'
*/
public void testGetDocumentRoot_emf() {
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
index 47bc12f..fc94897 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
@@ -67,23 +67,7 @@ public class EStructuralFeatureSettingTests extends TestCase {
*/
public void testExpandedNameOf() {
ExpandedName expandedName = inspector.expandedNameOf(root_name_attr);
- assertEquals("http:///dataAccess.ecore:name", expandedName.toString());
- }
-
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.EStructuralFeatureSettingInspector.getAttributes(Object)'
- */
- public void testGetAttributes() {
- Object[] attributes = inspector.getAttributes(root_name_attr);
- assertNull(attributes);
- }
-
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.EStructuralFeatureSettingInspector.getNamedAttribute(Object, ExpandedName)'
- */
- public void testGetNamedAttribute() {
- Object namedAttribute = inspector.getNamedAttribute(root_name_attr, new ExpandedName("foo"));
- assertNull(namedAttribute);
+ assertEquals("name", expandedName.toString());
}
/*
@@ -99,7 +83,8 @@ public class EStructuralFeatureSettingTests extends TestCase {
*/
public void testGetChildren() {
Object[] children = inspector.getChildren(root_name_attr);
- assertNull(children);
+ assertNotNull(children);
+ assertEquals(0, children.length);
}
/*