SWS-220, now tokenizing the context path string, and using equals() rather than startsWith

This commit is contained in:
Arjen Poutsma
2007-11-06 12:41:09 +00:00
parent 4c567e7d98
commit 91f2133d4f
2 changed files with 24 additions and 2 deletions

View File

@@ -209,7 +209,13 @@ public class Jaxb2Marshaller extends AbstractJaxbMarshaller
return false;
}
String packageName = className.substring(0, lastDotIndex);
return getContextPath().startsWith(packageName);
String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
for (int i = 0; i < contextPaths.length; i++) {
if (contextPaths[i].equals(packageName)) {
return true;
}
}
return false;
}
else if (!ObjectUtils.isEmpty(classesToBeBound)) {
return Arrays.asList(classesToBeBound).contains(clazz);

View File

@@ -194,7 +194,23 @@ public class Jaxb2MarshallerTest extends XMLTestCase {
verify(handlerMock);
}
public void testSupports() throws Exception {
public void testSupportsContextPath() throws Exception {
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
marshaller.supports(createFlight.getGenericReturnType()));
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
JAXBElement<Jaxb2MarshallerTest> testElement =
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
}
public void testSupportsClassesToBeBound() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class});
marshaller.afterPropertiesSet();
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
assertTrue("Jaxb2Marshaller does not support Flights",
marshaller.supports(createFlights.getGenericReturnType()));