|
|
deep cloning an object via interfaces?
hi
i'm have a tree of simple beans. this tree should pupoulated from an
xml data source which is VERY different structure, so no xml binding or
xsl would do the trick. i was thinking of creating a tree of adapters which will implement the
same interface as the tree of beans, so externally there should be no
difference. i then thought of using some sort of clone method which will simply go
though each getter and place it in new objetct's setter, the commons
springs copyProperties method almost does this, but it only does shallow copies
of collections (so i have to create a method what willl go through each
item in a collection an use it's clone method as well.
is there some method accepts a collections for each one simply calls it's clone and add's it to the new list?
What is it your trying to do? I know some people don't like it, but you can fall back on serialization for deep copies.
public/jav...deep-copy.html
public/jav...deep-copy.html
javaworld/j...javatip76.html
You can load the xml in it's native format and then use something like to do the bean-to-bean mapping.
you means instead of cloning i'll use dozer?
why won't ppl like serialzation?
oh, btw will this dozer or method actually activiate my getters and setters.
but i was thinking was to have a generic method that based upon a spring advice will get a calling method name (a getter) and use a speffic xpath query onit, this way i can concentrate all xpath queries in one location (maybe an xml file) and based on the method name draw them out.
i thought about using spring advice becouse it can give me the calling method name, but problem is , i may need to change the query's paramters (like putting question marks in the xml and then replace them with actuall values in execution.
is there another way (good way) to get current method name? (besides using exception stack trace).
Any chance we can have more information about the original problem? What is it you are trying to do?
ok here is the Deal:
we have an external prodcut which returns an xml format which cannot be changed.
this xml format should populate java beans with a very different structure, each attribute in a bean may require a length xpath query, for example, and attribute called result, in a root bean, may require the following xpath:
//Result/CaseRisk[@Id=quot;0501quot;, and RiskTypeId=quot;2]/@ResultLevelId
and that's on a good day, i may need several xpath queries to acheive it, so i was thinking to encapsulate all these query in an adapter, a bean which implements the interfaces of our beans, but behind the scenes executes xpath queries.
now i could use these beans as part of the application, but saving them in hiberante may prove complex as they have no fields or actuall data, so deep cloning them into beans with the same interface may prove usfull.
the only problem is, in the adapters i would have littered lost of xpath queries for each getter, can i can't see a way around it, maybe i shouldn't even do that. |
|