From b9329053cb337d46e5540aaf7b9999eb01d3fefc Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 21 Nov 2007 01:07:21 +0000 Subject: [PATCH] SWS-229 in 1.0 branch --- .../oxm/jibx/JibxMarshaller.java | 21 +++++++++++++------ .../oxm/jibx/JibxMarshallerTest.java | 5 ++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/oxm/src/main/java/org/springframework/oxm/jibx/JibxMarshaller.java b/oxm/src/main/java/org/springframework/oxm/jibx/JibxMarshaller.java index 99137668..9d68d3a2 100644 --- a/oxm/src/main/java/org/springframework/oxm/jibx/JibxMarshaller.java +++ b/oxm/src/main/java/org/springframework/oxm/jibx/JibxMarshaller.java @@ -49,6 +49,12 @@ import org.jibx.runtime.impl.MarshallingContext; import org.jibx.runtime.impl.StAXReaderWrapper; import org.jibx.runtime.impl.StAXWriter; import org.jibx.runtime.impl.UnmarshallingContext; +import org.w3c.dom.Node; +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; +import org.xml.sax.ext.LexicalHandler; + import org.springframework.beans.factory.InitializingBean; import org.springframework.oxm.AbstractMarshaller; import org.springframework.oxm.XmlMappingException; @@ -56,11 +62,6 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.xml.stream.StaxEventContentHandler; import org.springframework.xml.stream.XmlEventStreamReader; -import org.w3c.dom.Node; -import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.ext.LexicalHandler; /** * Implementation of the Marshaller and Unmarshaller interfaces for JiBX. @@ -138,7 +139,15 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe } public boolean supports(Class clazz) { - return targetClass.isAssignableFrom(clazz); + Assert.notNull(clazz, "'clazz' must not be null"); + String[] mappedClasses = bindingFactory.getMappedClasses(); + String className = clazz.getName(); + for (int i = 0; i < mappedClasses.length; i++) { + if (className.equals(mappedClasses[i])) { + return true; + } + } + return false; } /** diff --git a/oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTest.java b/oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTest.java index e093fa2b..38c3fa27 100644 --- a/oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTest.java +++ b/oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTest.java @@ -17,6 +17,7 @@ package org.springframework.oxm.jibx; import org.custommonkey.xmlunit.XMLUnit; + import org.springframework.oxm.AbstractMarshallerTestCase; import org.springframework.oxm.Marshaller; import org.springframework.xml.transform.StringResult; @@ -69,7 +70,9 @@ public class JibxMarshallerTest extends AbstractMarshallerTestCase { } public void testSupports() throws Exception { - assertTrue("Jaxb2Marshaller does not support Flights", marshaller.supports(Flights.class)); + assertTrue("JibxMarshaller does not support Flights", marshaller.supports(Flights.class)); + assertTrue("JibxMarshaller does not support FlightType", marshaller.supports(FlightType.class)); + assertFalse("JibxMarshaller supports illegal type", marshaller.supports(getClass())); }