views:

111

answers:

2

I am working on an existing Java project with a typical services - dao setup for which only a webapplication was available. My job is to add webservices on top of the services layer, but the webservices have their own functional analysis and datamodel. The functional analyses ofcource focuses on what is possible in the different service methods.

As good practice demands, we used the WSDL first strategy and generated JAXB bound Java classes and a SEI for the webservices. After having implemented the webservices partially, we noticed a 70% match between the datamodel. This resulted in writing converters which take the webservice JAXB classes and map them with the service layer classes.

Customer customer = new Customer();
customer.setName(wsCustomer.getName());
customer.setFirstName(wsCustomer.getFirstName();
..

This is a very obvious example, some other mappings where little more complicated. Can anyone give his best practices, experiences, solutions to this kind of situations?

Are any of these frameworks usefull? http://transmorph.sourceforge.net/wiki/index.php/Main_Page http://ezmorph.sourceforge.net/

Please don't start a discussion about WSDL first vs code first.

A: 

I think the real question is... how much of the code generators do you want to use in the future, and can you get them to generate what you're doing now. Converting everything to your current data model is a good idea, if you don't care about the code generation capabilities of your tools, or they can adapt to what you want.

Jim Barrows
+1  A: 

I am experiencing the same issue on my project. I created a factory for the generated objects and use it for creating objects.

Customer customer = factory.createCustomer(wsCustomer);

Which isolates the construction code, w/o altering the generated code.

jon077
Good point, we have these factories with create methods for both directions
Jurgen H