Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CastorMarshaller to accept more than one mapping file [SWS-88] #248

Closed
gregturn opened this issue Feb 1, 2007 · 1 comment
Closed

Allow CastorMarshaller to accept more than one mapping file [SWS-88] #248

gregturn opened this issue Feb 1, 2007 · 1 comment
Assignees
Milestone

Comments

@gregturn
Copy link
Member

@gregturn gregturn commented Feb 1, 2007

Richard Gundersen opened SWS-88 and commented

Allow CastorMarshaller to accept multiple mapping files, as descibed here: http://forum.springframework.org/showthread.php?t=34258

Castor can accept more than one by calling mapping.loadMapping() multiple times. I modified the code for my purposes like so:

private void createClassDescriptorResolver() throws MappingException, IOException {
    classDescriptorResolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory
            .createClassDescriptorResolver(BindingType.XML);
    if(!Utils.isEmpty(mappingLocations)) {
    	Mapping mapping = new Mapping();
    	for(int i=0; i<mappingLocations.size(); i++) {
    		logger.debug("Trying to load mapping resource: " + (String)mappingLocations.get(i));        		
    		Resource resource = new ClassPathResource((String)mappingLocations.get(i));                
            mapping.loadMapping(new InputSource(resource.getInputStream()));        		
    	}
        MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller();
        MappingLoader mappingLoader = mappingUnmarshaller.getMappingLoader(mapping, BindingType.XML);
        classDescriptorResolver.setMappingLoader(mappingLoader);
        classDescriptorResolver.setClassLoader(mapping.getClassLoader());        		        	
    }
    else if (targetClass != null) {
        classDescriptorResolver.setClassLoader(targetClass.getClassLoader());
    }
}

(mappingLocations is now an ArrayList)

Configuration as follows:

<property name="mappingLocations">
     <list>
          <value>/com/lsb/uk/lasernet/oxm/castor/lasernetEnvelope-mapping.xml</value>
                                                                                                                                                                                                                                                                          <value>/com/lsb/uk/mqs/biz/bos/castor-mapping.xml</value>				
     </list>
</property> 

Does this method need to be private by the way? Could it be protected, so it can be overridden?

Thanks

Richard


Affects: 1.0 M3

1 votes, 0 watchers

@gregturn
Copy link
Member Author

@gregturn gregturn commented May 20, 2007

Arjen Poutsma commented

Closing RC1 issues.

@gregturn gregturn closed this May 20, 2007
@gregturn gregturn added this to the 1.0 RC1 milestone Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.