From 5fe7e15f37d722a5563ca625a45dc101cf65045c Mon Sep 17 00:00:00 2001 From: scottkurz Date: Thu, 31 Mar 2011 15:25:19 +0000 Subject: Revert 1086760 change pending solution to TUSCANY-3857 to keep itest functioning. Ignore new test in databinding-axiom for now as well. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1087339 13f79535-47bb-0310-9956-ffa450edef68 --- .../databinding/axiom/OMElementWrapperHandler.java | 31 +++++++++++----------- .../axiom/OMElementWrapperHandlerTestCase.java | 2 ++ 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'sca-java-2.x/trunk/modules') 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 { List elements = new ArrayList(); 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 { 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> getElements(OMElement wrapper) { List> elements = new ArrayList>(); List current = new ArrayList(); @@ -179,18 +175,21 @@ public class OMElementWrapperHandler implements WrapperHandler { 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 = getElements(wrapper); + List 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 { } /** - * 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); -- cgit v1.2.3