Re: [Simple-support] Loaded element used in Converter for next element
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-07-09 08:37:18
|
Hi,
It is possible, but it does not sound like a good idea. Here is how to do it. You need to implement Strategy interface, this is passed in a "session" Map object, which you can use to collect object instances. Take a look in the test cases for examples of how to use it, its actually very simple, every element read gets a "read" callback to the strategy, every object to write gets a "write" callback to the strategy. At all times, you can set things in to the Map object passed to both the "read" and "write" methods.
Niall
--- On Thu, 7/7/11, Przemysław Kruglej <pk....@gm...> wrote:
From: Przemysław Kruglej <pk....@gm...>
Subject: [Simple-support] Loaded element used in Converter for next element
To: sim...@li...
Received: Thursday, 7 July, 2011, 2:53 PM
Hello,
I have the following problem: assume we have a class:
class Profile {
@Element
ComplexType first;
@Element
DIfferentComplexType second;
}
Now, we have a Converter for DifferentComplexType. However, for deserialization process, this converter needs an object of class ComplexType, and it should be the one loaded for Profile object instance:
public class DIfferentComplexTypeConverter implements Converter<DIfferentComplexType> {
private ComplexType complexType;
public DIfferentComplexTypeConverter(ComplexType complexType) {
this.complexType= complexType;
}
public DIfferentComplexType read(InputNode inputNode) throws Exception {
// some operations which need a ComplexType object to be done
}
public void write(OutputNode outputNode, Texture texture) throws Exception {
// some operations
}
}
Does any of you has any idea how something like this could be achieved? I. e. how to pass just deserialized "first" field of type ComplexType to converter that will be used to deserialize the next field (named "second")? The problem is, that the Registry object is created before deserializing, and so adding DIfferentComplexTypeConverter to it is impossible, because we don't have the ComplexType object yet. I'm starting wondering if this is even possible, and if this is a good idea.
I know I could load these fields separately - have separate serializers, and create each when I have the needed objects for converters. However, I would have to store object's definitions in different XML files and serializing process would not be as nice as with the above approach. Anyways, any ideas?
Take care,
Iskar
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|