Pergunta

I'm using XMLBeans to generate Java client code from two very similar XSDs. The XMLBeans-generated classes go into two parallel packages. I then retrieve data from a database to interact with the generated classes to produce two (again, nearly identical) XML output files. Even though the XSDs are about 95% the same, there's no defined relationship between them - no inheritance or anything. Unfortunately, these legacy XSDs have been in use for years and I'm not permitted to modify them.

My problem is this: even though the majority of the data and structures are exactly the same between the two XML files, I can't figure out how to avoid tons of duplicate code to pour the data into two independent sets of XMLBeans-generated classes. I can create a common set of business objects to go between the DAOs and the XML structures. But I'd still have to map each of those objects to both corresponding generated XML types, and that seems incredibly tedious and inefficient.

I don't want to modify the generated XMLBeans Java code (e.g., to implement a shared Interface), and I can't change the XSDs. I've looked at patterns like Adapter and Bridge but I don't think they get me there in terms of avoiding the duplicate code/effort. Is there an elegant design solution that I'm missing?

Foi útil?

Solução

Perhaps you could use XmlCursor to generically add content to similar nodes, see How to add a node to XML with XMLBeans XmlObject

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top