From b0d1c71cd30961ffcc41d0fa6dceccc9d1fd56cf Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 22 Oct 2007 21:52:00 +0000 Subject: [PATCH] Improved supports() --- .../org/springframework/oxm/castor/CastorMarshaller.java | 8 +++++++- .../springframework/oxm/castor/CastorMarshallerTest.java | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java index 8b28656e..8db54dfa 100644 --- a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java +++ b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java @@ -34,6 +34,7 @@ import org.exolab.castor.mapping.MappingLoader; import org.exolab.castor.xml.ClassDescriptorResolverFactory; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.Marshaller; +import org.exolab.castor.xml.ResolverException; import org.exolab.castor.xml.UnmarshalHandler; import org.exolab.castor.xml.Unmarshaller; import org.exolab.castor.xml.XMLClassDescriptorResolver; @@ -200,7 +201,12 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing /** Returns true for all classes, i.e. Castor supports arbitrary classes. */ public boolean supports(Class clazz) { - return true; + try { + return classDescriptorResolver.resolve(clazz) != null; + } + catch (ResolverException e) { + return false; + } } protected final void marshalDomNode(Object graph, Node node) throws XmlMappingException { diff --git a/oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTest.java b/oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTest.java index ccf368a5..893c9ef4 100644 --- a/oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTest.java +++ b/oxm/src/test/java/org/springframework/oxm/castor/CastorMarshallerTest.java @@ -66,4 +66,10 @@ public class CastorMarshallerTest extends AbstractMarshallerTestCase { handlerControl.verify(); } + public void testSupports() throws Exception { + assertTrue("CastorMarshaller does not support Flights", marshaller.supports(Flights.class)); + assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class)); + } + + }