0

Does anyone know a quick way to reverse-engineer an in-memory object graph in Java? What I need is a way to traverse an in-memory object graph and create Java instantiation/setter calls to re-create the original graph.

That's needed as a tool for an integration project with a half-baked web services developed by ivory tower architects. So I ended up getting a massive XSD doc and a bunch of sample XML instances confirming to it... Now need to bridge it somehow with our domain code...

Here is a sequence diagram of how it might look like. I just need to add another check if the user exists in the remote service. The problem is that this call would be large 500+ lines of code to even generate the request. I am trying to find a way to automate this instantiation.

Add User Integration Flow

Thanks in advance.

Nick G.
  • 557
  • 9
  • 18
  • Can you give some more details about what exactly you are trying to do? – nakosspy May 21 '13 at 23:35
  • Thanks for taking a look, Nakosspy! I am building an integration layer between an existing web app and a yet-to-be-developed web services. The WSs have large domain model (8+MBs of XSDs alone), which, when reverse engineered gives in JAXB a very complex and hard to use Java model (i.e. just to build the request would take 500+ lines of code, and there are dozens of requests). I am looking for a way to ease this... – Nick G. May 22 '13 at 13:40
  • You are trying to throw away the classes generated by JAXB from XSD and do something else? Or just searching a way to automate the creation of the objects that belong to the JAXB classes? – nakosspy May 22 '13 at 14:10
  • Right. Creation automation would be a good solution. Other alternatives would work too, like say, a template-based approach (XSLT or Velocity), where the XML messages are generated using a template. – Nick G. May 22 '13 at 14:34
  • Your idea to create the input document with some template engine sounds like a good idea, if it finally proves feasible in your case. Where does the reverse engineering of an object graph fit in that? – nakosspy May 22 '13 at 20:09
  • I think it's more of an alternative solution. If there are templates involved, then object graph is not needed at all. – Nick G. – nakosspy May 22 '13 at 20:09
  • I deleted the answer and moved the comments here. I intended to add comment not an answer. – nakosspy May 22 '13 at 20:10
  • The template engine approach looks attracting. The approach related to your answer some kind of reverse engineering an object graph needs more clarification. At this stage it looks to me a rather complicated approach. – nakosspy May 22 '13 at 20:12

1 Answers1

0

After searching through a bunch of different utils (commons, pojobuilder, quick-baked recursive translations), I ended up back-tracing to the origins and creating Velocity templates for generating messages and relying onto JXPath for quick retrieval of values from the generated model...

As Nakosspy pointed out (many thanks for taking a look at this post!), it doesn't relate to reverse-engineering an object graph, although seems to help me getting though with this implementation.

Nick G.
  • 557
  • 9
  • 18