summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-09-11 13:00:59 (EDT)
committer pelder2006-09-11 13:00:59 (EDT)
commit7b9290b4ad8f977cb34a5dac0214cc425506abb1 (patch)
tree22a40aa477dcd0b39829e551633fda7f3e5f119c
parent932defde2fcc19eaae307f032bd708af80ea5936 (diff)
downloadorg.eclipse.jet-7b9290b4ad8f977cb34a5dac0214cc425506abb1.zip
org.eclipse.jet-7b9290b4ad8f977cb34a5dac0214cc425506abb1.tar.gz
org.eclipse.jet-7b9290b4ad8f977cb34a5dac0214cc425506abb1.tar.bz2
[156895] Handle single elements (represented as EAttributes) that recur, plus handle EEnumLiterals.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EMFEAttrAsElementWrapperInspector.java55
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EObjectInspector.java33
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java6
3 files changed, 70 insertions, 24 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EMFEAttrAsElementWrapperInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EMFEAttrAsElementWrapperInspector.java
index 684786b..6031b2d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EMFEAttrAsElementWrapperInspector.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/EMFEAttrAsElementWrapperInspector.java
@@ -18,7 +18,7 @@
package org.eclipse.jet.internal.xpath.inspectors;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.jet.xpath.inspector.AddElementException;
import org.eclipse.jet.xpath.inspector.ExpandedName;
import org.eclipse.jet.xpath.inspector.IElementInspector;
import org.eclipse.jet.xpath.inspector.InvalidChildException;
@@ -54,7 +54,7 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public Object getParent(Object obj)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)obj;
- return wrapper.getSetting().getEObject();
+ return wrapper.getEObject();
}
/* (non-Javadoc)
@@ -63,8 +63,7 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public String stringValueOf(Object object)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)object;
- final Setting setting = wrapper.getSetting();
- return stringValueOfFeature(setting.getEStructuralFeature(), setting.get(true));
+ return stringValueOfFeature(wrapper.getFeature(), wrapper.getValue());
}
/* (non-Javadoc)
@@ -73,8 +72,7 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public ExpandedName expandedNameOf(Object object)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)object;
- final Setting setting = wrapper.getSetting();
- return expandedNameOfFeature(setting.getEObject(), setting.getEStructuralFeature());
+ return expandedNameOfFeature(wrapper.getEObject(), wrapper.getFeature());
}
/* (non-Javadoc)
@@ -83,7 +81,7 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public Object getDocumentRoot(Object contextNode)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)contextNode;
- return super.getDocumentRoot(wrapper.getSetting().getEObject());
+ return super.getDocumentRoot(wrapper.getEObject());
}
/* (non-Javadoc)
@@ -91,7 +89,8 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
*/
public Object[] getChildren(Object contextNode)
{
- return EMPTY_ARRAY;
+ // this is a simple element, which has a single text node as a child, containing its value...
+ return new Object[] { new EMFXMLNodeWrapper(contextNode, stringValueOf(contextNode), NodeKind.TEXT)};
}
/* (non-Javadoc)
@@ -100,8 +99,7 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public String nameOf(Object contextNode)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)contextNode;
- final Setting setting = wrapper.getSetting();
- return nameOfFeature(setting.getEObject(), setting.getEStructuralFeature());
+ return nameOfFeature(wrapper.getEObject(), wrapper.getFeature());
}
public Object addElement(Object contextNode, ExpandedName elementName, Object addBeforeThisSibling) throws SimpleElementRequiresValueException,
@@ -113,8 +111,39 @@ public class EMFEAttrAsElementWrapperInspector extends EObjectInspector implemen
public void removeElement(Object contextNode)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)contextNode;
- final Setting setting = wrapper.getSetting();
- setting.unset();
-
+ wrapper.remove();
+ }
+
+ public Object[] getAttributes(Object contextNode)
+ {
+ return new Object[0];
+ }
+
+ public Object[] getNamedChildren(Object contextNode, ExpandedName nameTestExpandedName)
+ {
+ return new Object[0];
+ }
+
+ public void removeAttribute(Object element, String name)
+ {
+ // do nothing
+ }
+
+ public Object addTextElement(Object parentElement, String name, String bodyContent, boolean asCData) throws AddElementException
+ {
+ // FIXME Externalize
+ throw new AddElementException("Cannot add child element to simple types");
+ }
+
+ public boolean createAttribute(Object contextNode, String attributeName, String value)
+ {
+ return false;
+ }
+
+ public Object getNamedAttribute(Object contextNode, ExpandedName nameTestExpandedName)
+ {
+ return null;
}
+
+
}
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 cf585bd..a45f41b 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
@@ -26,6 +26,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
@@ -48,7 +49,9 @@ import org.eclipse.jet.xpath.inspector.AddElementException;
import org.eclipse.jet.xpath.inspector.CopyElementException;
import org.eclipse.jet.xpath.inspector.ExpandedName;
import org.eclipse.jet.xpath.inspector.IElementInspector;
+import org.eclipse.jet.xpath.inspector.INodeInspector;
import org.eclipse.jet.xpath.inspector.INodeInspectorExtension1;
+import org.eclipse.jet.xpath.inspector.InspectorManager;
import org.eclipse.jet.xpath.inspector.InvalidChildException;
import org.eclipse.jet.xpath.inspector.SimpleElementRequiresValueException;
@@ -371,6 +374,9 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
}
}
+ else if(object instanceof EEnumLiteral) {
+ return ((EEnumLiteral)object).getLiteral();
+ }
return EMPTY_STRING;
}
@@ -393,9 +399,9 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
}
else if (children[i] instanceof EMFEAttrAsElementWrapper)
{
- Setting setting = ((EMFEAttrAsElementWrapper)children[i]).getSetting();
- Object rawValue = setting.get(true);
- result.append(stringValueOfFeature(setting.getEStructuralFeature(), rawValue));
+ final EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)children[i];
+ Object rawValue = wrapper.getValue();
+ result.append(stringValueOfFeature(wrapper.getFeature(), rawValue));
}
}
}
@@ -488,7 +494,18 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
{
if (eObject.eIsSet(feature))
{
- result.add(new EMFEAttrAsElementWrapper(((InternalEObject)eObject).eSetting(feature)));
+ final Setting setting = ((InternalEObject)eObject).eSetting(feature);
+ if(!feature.isMany())
+ {
+ result.add(new EMFEAttrAsElementWrapper(setting));
+ }
+ else
+ {
+ final EList list = (EList)setting.get(true);
+ for(int j = 0; j < list.size(); j++ ) {
+ result.add(new EMFEAttrAsElementWrapper(setting, j));
+ }
+ }
}
}
else if (feature.isMany())
@@ -609,7 +626,8 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
EPackage ePkg = feature.getEContainingClass().getEPackage();
String namespace = ePkg.getNsURI();
String nsPrefix = ePkg.getNsPrefix();
- Object root = getDocumentRoot(eObject);
+ final INodeInspector inspector = InspectorManager.getInstance().getInspector(eObject);
+ Object root = inspector.getDocumentRoot(eObject);
if (root instanceof EObject)
{
String namespace2 = getExtendedMetaData().getNamespace(feature);
@@ -680,7 +698,7 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
else if (allChildren[i] instanceof EMFEAttrAsElementWrapper)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)allChildren[i];
- if (matchesFeature(nameTestExpandedName, wrapper.getSetting().getEStructuralFeature()))
+ if (matchesFeature(nameTestExpandedName, wrapper.getFeature()))
{
result.add(wrapper);
}
@@ -1005,9 +1023,8 @@ public class EObjectInspector implements IElementInspector, INodeInspectorExtens
else if (srcElement instanceof EMFEAttrAsElementWrapper)
{
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper)srcElement;
- Setting setting = wrapper.getSetting();
- eObject.eSet(feature, setting.get(true));
+ eObject.eSet(feature, wrapper.getValue());
newElement = new EMFEAttrAsElementWrapper(((InternalEObject)eObject).eSetting(feature));
}
else
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 699cd44..3c2912e 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
@@ -474,7 +474,7 @@ public class EObjectInspectorTests extends TestCase {
assertEquals(1, doc.length);
assertTrue("instanceof EMFEAttrAsElementWrapper", doc[0] instanceof EMFEAttrAsElementWrapper);
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper) doc[0];
- assertEquals("doc for Author.name", wrapper.getSetting().get(true));
+ assertEquals("doc for Author.name", wrapper.getValue());
}
/*
@@ -587,7 +587,7 @@ public class EObjectInspectorTests extends TestCase {
assertEquals(1, namedChildren.length);
for (int i = 0; i < namedChildren.length; i++) {
EMFEAttrAsElementWrapper child = (EMFEAttrAsElementWrapper) namedChildren[i];
- assertEquals("doc for Author.name", child.getSetting().get(true));
+ assertEquals("doc for Author.name", child.getValue());
}
}
@@ -877,7 +877,7 @@ public class EObjectInspectorTests extends TestCase {
assertEquals(1, doc.length);
assertTrue("instanceof EMFEAttrAsElementWrapper", doc[0] instanceof EMFEAttrAsElementWrapper);
EMFEAttrAsElementWrapper wrapper = (EMFEAttrAsElementWrapper) doc[0];
- assertEquals("Hello Attribute 1", wrapper.getSetting().get(true));
+ assertEquals("Hello Attribute 1", wrapper.getValue());
}
public void testAddTextElement_xml() throws AddElementException {