summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-07-24 16:21:44 (EDT)
committer pelder2007-07-24 16:21:44 (EDT)
commitcf372c952b2f35f7b58bedde8f6fed8db10c5008 (patch)
tree575b02afdae7897ba0e58ee0d1bd96588b0cf331
parent2c92151598764cb6ed342ded53a81ee66277e2f3 (diff)
downloadorg.eclipse.jet-cf372c952b2f35f7b58bedde8f6fed8db10c5008.zip
org.eclipse.jet-cf372c952b2f35f7b58bedde8f6fed8db10c5008.tar.gz
org.eclipse.jet-cf372c952b2f35f7b58bedde8f6fed8db10c5008.tar.bz2
[197706] JET fails when traversing some EMF models defined by an XSD with EMF specific enhancements
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java109
1 files changed, 78 insertions, 31 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 e5abbef..0b93ecb 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
@@ -255,7 +255,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
private boolean matchesFeature(ExpandedName expandedName, EStructuralFeature feature, ExtendedMetaData exMD)
{
ExpandedName featureEN = internalExpandedNameOfFeature(feature, exMD);
- final boolean equals = expandedName.equals(featureEN) || expandedName.equals(new ExpandedName(feature.getName()));
+ final boolean equals = expandedName.equals(featureEN) || expandedName.equals(new ExpandedName(featureEN.getLocalPart()));
return equals;
}
@@ -540,13 +540,16 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
}
}
- else if (feature.isMany())
+ else if(((EReference)feature).isContainment())
{
- result.addAll((List)eObject.eGet(feature));
- }
- else
- {
- result.add(eObject.eGet(feature));
+ if (feature.isMany())
+ {
+ result.addAll((List)eObject.eGet(feature));
+ }
+ else
+ {
+ result.add(eObject.eGet(feature));
+ }
}
break;
case ExtendedMetaData.GROUP_FEATURE:
@@ -588,15 +591,18 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
for (Iterator i = featureMap.iterator(); i.hasNext();)
{
FeatureMap.Entry entry = (FeatureMap.Entry)i.next();
- Object resultObject;
- NodeKind nodeKind = XMLTypeUtil2.getNodeKind(entry.getEStructuralFeature());
+ Object resultObject = null;
+ final EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ NodeKind nodeKind = XMLTypeUtil2.getNodeKind(entryFeature);
if (nodeKind == NodeKind.TEXT || nodeKind == NodeKind.COMMENT)
{
resultObject = new EMFXMLNodeWrapper(eObject, (String)entry.getValue(), nodeKind);
}
- else
+ else if(entryFeature instanceof EReference && ((EReference)entryFeature).isContainment())
{
resultObject = entry.getValue();
+ } else if(entryFeature instanceof EAttribute) {
+ resultObject = new EMFEAttrAsElementWrapper(new AnyAttributeSetting(entry,eObject));
}
result[resultIndex++] = resultObject;
}
@@ -687,7 +693,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
}
}
- String localName = feature.getName();
+ String localName = isXMLNode(eObject.eClass()) ? getExtendedMetaData(eObject).getName(feature) : feature.getName();
return nsPrefix != null && nsPrefix.length() > 0 ? nsPrefix + ":" //$NON-NLS-1$
+ localName : localName;
}
@@ -715,33 +721,41 @@ 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++)
+// Object[] allChildren = getChildren(eObject);
+ final List allElementsFeatures = exMD.getAllElements(eClass);
+// List result = new ArrayList(allElementsFeatures.size());
+ for (Iterator i = allElementsFeatures.iterator(); i.hasNext();)
{
- if (allChildren[i] instanceof EObject)
- {
- EObject child = (EObject)allChildren[i];
- if (matchesFeature(nameTestExpandedName, child.eContainingFeature(), exMD)
- || matchesFeature(nameTestExpandedName, child.eContainmentFeature(), exMD))
- {
- result.add(child);
- }
- }
- else if (allChildren[i] instanceof EMFEAttrAsElementWrapper)
- {
- EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)allChildren[i];
- if (matchesFeature(nameTestExpandedName, wrapper.getFeature(), exMD))
+ EStructuralFeature feature = (EStructuralFeature)i.next();
+ if(exMD.getFeatureKind(feature) == ExtendedMetaData.ELEMENT_WILDCARD_FEATURE) {
+ FeatureMap fm = (FeatureMap)eObject.eGet(feature, true);
+ List result = new ArrayList(fm.size());
+ for (Iterator ifm = fm.iterator(); ifm.hasNext();)
{
- result.add(wrapper);
+ 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());
+ }
+ }
+
}
+ return result.toArray();
}
- else
+ else if(matchesFeature(nameTestExpandedName, feature, exMD))
{
- // its either a comment or text element, which we can ignore.
+ return getFeatureValue(eObject, feature);
}
}
- return result.toArray();
+ return new Object[0];
}
else
@@ -780,6 +794,39 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
}
+
+ /**
+ * @param eObject
+ * @param feature
+ * @return
+ */
+ private Object[] getFeatureValue(EObject eObject, EStructuralFeature feature)
+ {
+ Object objResult = eObject.eGet(feature);
+ if(feature instanceof EReference) {
+ if(feature.isMany()) {
+ return ((List)objResult).toArray();
+ } else {
+ return new Object[] {objResult};
+ }
+ } else {
+ // its an EAttribute, wrap...
+ final Setting setting = ((InternalEObject)eObject).eSetting(feature);
+ if(feature.isMany())
+ {
+ Object[] result = new Object[((List)objResult).size()];
+ for(int j = 0; j < result.length; j++ ) {
+ result[j] = new EMFEAttrAsElementWrapper(setting, j);
+ }
+ return result;
+ }
+ else
+ {
+ return new Object[] {new EMFEAttrAsElementWrapper(setting)};
+ }
+ }
+ }
+
/**
* @param eClass
* @param featureURI