summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/databinding-axiom/src
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding-axiom/src')
-rw-r--r--sca-java-2.x/trunk/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java31
-rw-r--r--sca-java-2.x/trunk/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandlerTestCase.java2
2 files changed, 17 insertions, 16 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/sca-java-2.x/trunk/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
index fcaa596f6f..9084f09dc0 100644
--- a/sca-java-2.x/trunk/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
+++ b/sca-java-2.x/trunk/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
@@ -108,7 +108,7 @@ public class OMElementWrapperHandler implements WrapperHandler<OMElement> {
List<Object> elements = new ArrayList<Object>();
int i = 0;
for (ElementInfo e : childElements) {
- elements.add(getChild(wrapper, e));
+ elements.add(getChild(wrapper, e, i));
i++;
}
return elements;
@@ -152,10 +152,6 @@ public class OMElementWrapperHandler implements WrapperHandler<OMElement> {
private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi");
- /*
- * Left this method in the code to show the idea of grouping like wrapper children without
- * knowing the QName from the ElementInfo, but this code isn't currently used any more.
- */
private List<List<OMElement>> getElements(OMElement wrapper) {
List<List<OMElement>> elements = new ArrayList<List<OMElement>>();
List<OMElement> current = new ArrayList<OMElement>();
@@ -179,18 +175,21 @@ public class OMElementWrapperHandler implements WrapperHandler<OMElement> {
return elements;
}
- public Object getChild(OMElement wrapper, ElementInfo childElement) {
+ public Object getChild(OMElement wrapper, ElementInfo childElement, int index) {
Iterator children = wrapper.getChildrenWithName(childElement.getQName());
if (!children.hasNext()) {
- // We used to at this point call getElements(wrapper) to group children
- // into like elements and then try to index into this list by integer index.
- // The problem with this approach is that it ignores the possibility that
- // we have a wrapper child with schema specifying minOccurs="0", in which case
- // there are no wrapper children with this QName and so the index would be wrong.
- //
- // It doesn't look like anyone is depending on this function currently, so just remove
- // it and return "null".
- return null;
+ // No name match, try by index
+ List<List<OMElement>> list = getElements(wrapper);
+ List<OMElement> elements = list.get(index);
+ if (!childElement.isMany()) {
+ return elements.isEmpty() ? null : attachXSIType(childElement, elements.get(0));
+ } else {
+ Object[] array = elements.toArray();
+ for (Object item : array) {
+ attachXSIType(childElement, (OMElement)item);
+ }
+ return array;
+ }
}
if (!childElement.isMany()) {
if (children.hasNext()) {
@@ -212,7 +211,7 @@ public class OMElementWrapperHandler implements WrapperHandler<OMElement> {
}
/**
- * Create xsi:type if required
+ * Create xis:type if required
* @param childElement
* @param element
* @return
diff --git a/sca-java-2.x/trunk/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandlerTestCase.java b/sca-java-2.x/trunk/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandlerTestCase.java
index 1d2a22d057..874013e886 100644
--- a/sca-java-2.x/trunk/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandlerTestCase.java
+++ b/sca-java-2.x/trunk/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandlerTestCase.java
@@ -33,6 +33,7 @@ import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
@@ -79,6 +80,7 @@ public class OMElementWrapperHandlerTestCase {
// Would be nice to do a "set" test too.
@Test
+ @Ignore("TUSCANY-3857")
public void testGetChildren() {
try {
OMElement wrapperElem = AXIOMUtil.stringToOM(WRAPPER_XML);