You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Cheong Chung Onn <ch...@hs-integrating.com> on 2004/01/30 10:21:35 UTC

[Betwixt] Options for doing a roundtrip

Hi all,

I am using Betwixt to do object persistence, I am facing some 
challenges using it. Essentially,  I have to "open up" my class 
Interface in order to achieve the desire behavior from Betwixt? I would 
appreciate any one could direct me to the  right way to this problem. 
Below is my scenario

  I have a class Person which has an attribute "address" type 
AddressIntf. The implementation of AddressIntf is Address.  Address has 
both the getters and setters of all its attributes, but AddressIntf 
only has the getters. When i map the object to xml using Person 
instance, i got the expected output.  However when i try to map it back 
to a Person instance,  i only have an uninitialized address instance. 
Note I've a custom class creator  to create an instance of Address.  In 
order to achieve the desire result i.e. the address instance attributes 
being updated, i would have to "open-up" the AddressIntf  by adding the 
setter methods. Is there any way around this problem?

Any help will be greatly appreciated. Thanks in advance.

chung-onn


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Betwixt] Options for doing a roundtrip

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On 2 Feb 2004, at 03:20, Cheong Chung Onn wrote:

> Thanks robert,
>
> I have learnt that Betwixt is bean centric the hard way over the last 
> few days and i have "opened" all the Interface classes. Even though I 
> have been working round the clock trying to work around Betwixt's  
> bean centric-ism but am defeated, I still find Betwixt very 
> interesting, flexible and powerful.

interesting, flexible, powerful but incomplete would be an apt 
description.

(the following isn't meant to be a rant or a criticism of yourself, i'm 
just trying to let people know how to maximize the changes of people 
being able to help them.)

i would have liked to give you more help but i only have a few hours 
each day to spend on coding betwixt. i try to maximize the progress i 
can make in this time.

people will massively increase their chances of a positive outcome if 
they are willing to contribute good test cases to the ASF demonstrating 
their problems. (it usually takes me longer to understand and create 
good test cases than it does to add the feature or fix the problem.) 
this means posting the code with ASF licenses indicating that they are 
happy to donate the code to the ASF.

with a good test case, i can usually quickly come back with either help 
or a bug fix and so i'll usually find time to do that.

(end of message ;)

> I have only one last struggle with Betwixt, actually i have given up 
> since early this morning, but i wonder if you can help point  me to 
> the right direction. Here's my problem - Betwixt seems to favor xml 
> files that are attribute based, hence any Custom Class Creator 
> (subclass of ChainBeanCreator) can only access the "elements" that are 
>  in the form of "attributes"  via mappingElement.getAttributes(). Is 
> it possible for me to access the child element values during the call 
> back to the CustomCreator class? I don't seems to able to find a 
> solution, i tried navigating the elementDescriptor, the readContext 
> but failed.  I only managed to access the definition of the bean type 
> but not the content. Could you kindly advise me if there is a way to 
> access the contents of the child element - <age> content as shown 
> below during the CustomClass callback?

i'm sad to say that this is actually pretty difficult (i'll give the 
reasons below). i'd say that the easiest way to do something like this 
would be by a custom digester rule (or two).

betwixt is very much SAX-based. the information you want is not 
available until later in the parse. this is fine for bean-centric 
object models but is a PITA when you want to map a sub-graph to a 
single call (whether to a construction or to a method). i do use the 
kind of constructors and method you're having problems with fairly 
regularly and it would be possible to extend betwixt so that it 
supports them but it's not currently high on my list of priorities.

betwixt combines pretty well with digester rules and usually the folks 
who use betwixt have experience of digester so the usual way to solve 
this problem is to get betwixt to ignore the subgraph and add custom 
digester rules to manage it.

once again, my apologies that betwixt hasn't been able to do what you 
need.

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Betwixt] Options for doing a roundtrip

Posted by Cheong Chung Onn <ch...@hs-integrating.com>.
Thanks robert,

I have learnt that Betwixt is bean centric the hard way over the last 
few days and i have "opened" all the Interface classes. Even though I 
have been working round the clock trying to work around Betwixt's  bean 
centric-ism but am defeated, I still find Betwixt very interesting, 
flexible and powerful.

I have only one last struggle with Betwixt, actually i have given up 
since early this morning, but i wonder if you can help point  me to the 
right direction. Here's my problem - Betwixt seems to favor xml files 
that are attribute based, hence any Custom Class Creator (subclass of 
ChainBeanCreator) can only access the "elements" that are  in the form 
of "attributes"  via mappingElement.getAttributes(). Is it possible for 
me to access the child element values during the call back to the 
CustomCreator class? I don't seems to able to find a solution, i tried 
navigating the elementDescriptor, the readContext but failed.  I only 
managed to access the definition of the bean type but not the content. 
Could you kindly advise me if there is a way to access the contents of 
the child element - <age> content as shown below during the CustomClass 
callback?

<person age=21 />  // age can be access via 
mappingElement.getAttributes.getValue("age")

<person>
	<age>21</age>  // Is the content of <age> reachable from 
CustomClassCreator?
</person>

Thanks once again.
Chung-Onn

On 2 Feb 04, at 7:19 AM, robert burrell donkin wrote:

> On 30 Jan 2004, at 09:21, Cheong Chung Onn wrote:
>
>> Hi all,
>>
>> I am using Betwixt to do object persistence, I am facing some 
>> challenges using it. Essentially,  I have to "open up" my class 
>> Interface in order to achieve the desire behavior from Betwixt? I 
>> would appreciate any one could direct me to the  right way to this 
>> problem. Below is my scenario
>>
>>  I have a class Person which has an attribute "address" type 
>> AddressIntf. The implementation of AddressIntf is Address.  Address 
>> has both the getters and setters of all its attributes, but 
>> AddressIntf only has the getters. When i map the object to xml using 
>> Person instance, i got the expected output.  However when i try to 
>> map it back to a Person instance,  i only have an uninitialized 
>> address instance. Note I've a custom class creator  to create an 
>> instance of Address.  In order to achieve the desire result i.e. the 
>> address instance attributes being updated, i would have to "open-up" 
>> the AddressIntf  by adding the setter methods. Is there any way 
>> around this problem?
>
> betwixt is start-from-java and concentrates on java beans so most of 
> the methods are geared around object models composed of java beans. 
> so, it's more difficult to map objects which are not java beans. 
> adding support for designs which are not typical use cases for object 
> models composed of java bean is not a priority for me. (of course, if 
> some developers wanted to step up who were more interested in adding 
> these features then i'd be willing to give help and directions.)
>
> one possibility which others have found useful in the past is to 
> create and register (in the XMLIntrospector.getRegistry) custom 
> XMLBeanInfo's which contain a custom updater (MapEntryAdder is an 
> example of this kind of updater).
>
> - robert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [Betwixt] Options for doing a roundtrip

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On 30 Jan 2004, at 09:21, Cheong Chung Onn wrote:

> Hi all,
>
> I am using Betwixt to do object persistence, I am facing some 
> challenges using it. Essentially,  I have to "open up" my class 
> Interface in order to achieve the desire behavior from Betwixt? I 
> would appreciate any one could direct me to the  right way to this 
> problem. Below is my scenario
>
>  I have a class Person which has an attribute "address" type 
> AddressIntf. The implementation of AddressIntf is Address.  Address 
> has both the getters and setters of all its attributes, but 
> AddressIntf only has the getters. When i map the object to xml using 
> Person instance, i got the expected output.  However when i try to map 
> it back to a Person instance,  i only have an uninitialized address 
> instance. Note I've a custom class creator  to create an instance of 
> Address.  In order to achieve the desire result i.e. the address 
> instance attributes being updated, i would have to "open-up" the 
> AddressIntf  by adding the setter methods. Is there any way around 
> this problem?

betwixt is start-from-java and concentrates on java beans so most of 
the methods are geared around object models composed of java beans. so, 
it's more difficult to map objects which are not java beans. adding 
support for designs which are not typical use cases for object models 
composed of java bean is not a priority for me. (of course, if some 
developers wanted to step up who were more interested in adding these 
features then i'd be willing to give help and directions.)

one possibility which others have found useful in the past is to create 
and register (in the XMLIntrospector.getRegistry) custom XMLBeanInfo's 
which contain a custom updater (MapEntryAdder is an example of this 
kind of updater).

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org