Skip to content

Commit 91f2133

Browse files
committed
SWS-220, now tokenizing the context path string, and using equals() rather than startsWith
1 parent 4c567e7 commit 91f2133

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

oxm-tiger/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,13 @@ private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement)
209209
return false;
210210
}
211211
String packageName = className.substring(0, lastDotIndex);
212-
return getContextPath().startsWith(packageName);
212+
String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
213+
for (int i = 0; i < contextPaths.length; i++) {
214+
if (contextPaths[i].equals(packageName)) {
215+
return true;
216+
}
217+
}
218+
return false;
213219
}
214220
else if (!ObjectUtils.isEmpty(classesToBeBound)) {
215221
return Arrays.asList(classesToBeBound).contains(clazz);

oxm-tiger/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,23 @@ public void testMarshalSaxResult() throws Exception {
194194
verify(handlerMock);
195195
}
196196

197-
public void testSupports() throws Exception {
197+
public void testSupportsContextPath() throws Exception {
198+
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
199+
assertTrue("Jaxb2Marshaller does not support Flights",
200+
marshaller.supports(createFlights.getGenericReturnType()));
201+
Method createFlight = ObjectFactory.class.getDeclaredMethod("createFlight", FlightType.class);
202+
assertTrue("Jaxb2Marshaller does not support JAXBElement<FlightsType>",
203+
marshaller.supports(createFlight.getGenericReturnType()));
204+
assertFalse("Jaxb2Marshaller supports non-parameterized JAXBElement", marshaller.supports(JAXBElement.class));
205+
JAXBElement<Jaxb2MarshallerTest> testElement =
206+
new JAXBElement<Jaxb2MarshallerTest>(new QName("something"), Jaxb2MarshallerTest.class, null, this);
207+
assertFalse("Jaxb2Marshaller supports wrong JAXBElement", marshaller.supports(testElement.getClass()));
208+
}
209+
210+
public void testSupportsClassesToBeBound() throws Exception {
211+
marshaller = new Jaxb2Marshaller();
212+
marshaller.setClassesToBeBound(new Class[]{Flights.class, FlightType.class});
213+
marshaller.afterPropertiesSet();
198214
Method createFlights = ObjectFactory.class.getDeclaredMethod("createFlights");
199215
assertTrue("Jaxb2Marshaller does not support Flights",
200216
marshaller.supports(createFlights.getGenericReturnType()));

0 commit comments

Comments
 (0)