[SWS-418] Castor mappings are added multiple times Created: 20/Aug/08  Updated: 04/May/12  Resolved: 28/Aug/08

Status: Closed
Project: Spring Web Services
Component/s: OXM
Affects Version/s: 1.5.4
Fix Version/s: 1.5.5

Type: Bug Priority: Minor
Reporter: Andreas Stubenrauch Assignee: Arjen Poutsma
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When using multiple mapping files for castor the CastorMarshaller adds each mapping several times.

i.e.
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" >
<property name="mappingLocations">
<list>
<value>classpath:file1.xml</value>
<value>classpath:file2.xml</value>
<value>classpath:file3.xml</value>
</list>
</property>
</bean>

The mappings from file1 are added 3 times because the addMapping() method is called within the loop with the entire mapping.
I think method

protected XMLContext createXMLContext(Resource[] mappingLocations, Class targetClass)
throws MappingException, IOException, ResolverException {
XMLContext context = new XMLContext();
if (!ObjectUtils.isEmpty(mappingLocations)) {
Mapping mapping = new Mapping();
for (int i = 0; i < mappingLocations.length; i++)

{ mapping.loadMapping(SaxUtils.createInputSource(mappingLocations[i])); context.addMapping(mapping); }

}
if (targetClass != null)

{ context.addClass(targetClass); }
return context;
}

Should actually look like this

protected XMLContext createXMLContext(Resource[] mappingLocations, Class targetClass)
throws MappingException, IOException, ResolverException {
XMLContext context = new XMLContext();
if (!ObjectUtils.isEmpty(mappingLocations)) {
Mapping mapping = new Mapping();
for (int i = 0; i < mappingLocations.length; i++) { mapping.loadMapping(SaxUtils.createInputSource(mappingLocations[i])); }
context.addMapping(mapping);
}
if (targetClass != null) { context.addClass(targetClass); }

return context;
}

BTW: Adding mappings multiple times will result in strange behavior because Castor tries identify objects by their namespace if it finds multiple entries with the same name and fails because of bad namespace support within castor.



 Comments   
Comment by Arjen Poutsma [ 28/Aug/08 ]

Fixed! Thanks for spotting this.

Comment by Arjen Poutsma [ 04/May/12 ]

Closing old issues

Generated at Mon Dec 11 00:17:59 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.