commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertburrelldon...@blueyonder.co.uk>
Subject Re: [betwixt] Partial bean support?
Date Sun, 02 Apr 2006 20:33:21 GMT
On Fri, 2006-03-31 at 22:27 -0600, Michael Gardner wrote:
> Does betwixt support reading or writing partial beans? I have a large-ish
> hierarchy of beans, and I would like to send only those properties that have
> changed. For example, say I have the following:
> 
> public class Game {
>     public void addPlayer(Player p) {...}
>     public Collection<Player> getPlayers() {...}
>     ...
> }
> 
> I send an instance of Game with two Players through a BeanWriter, which
> writes them out and assigns the Game an id of (say) 42. Later on, I add a
> third Player to the Game, and I would like to re-send the Game with XML to
> the effect of:
> 
> <game idref="42">
>     <players>
>         <player>...</player>
>     </players>
> </game>

am i right in thinking that this wouldn't actually be an IDREF (in the
strict sense laid down in the xml specification which means it must
refer to an other entity within the document) but rather a logical
identifier? 

> When a BeanReader tries to reconstruct this, it would look up with its
> IdStoringStrategy the existing Game for id 42, and then call 'addPlayer' on
> that object with the newly-constructed Player object as the argument.

interesting :-)

> Note that while one of my reasons for wanting to do this is bandwidth usage,
> I have other reasons for wanting betwixt to re-use the existing Game instead
> of constructing a new one.
> 
> Can betwixt do anything like this? (I fear not.)

not out of the box

> If not, how much work would it be for me to add such capabilities myself?

good question

depends on how this would work in detail. 

what would be hard is changes to objects deep in the hierarchy. for
example let's say change an attribute of a player's postal address:

 <game id='42'>
   <players>
        <player id='5'>
		<address>
			<city>New Name</city>
		</address>
	</player>
    </players>
</game>

this is a little tricky to map generically. you have to know how to
traverse the bean hierarchy to get the player who's id is 5 and create
if it does not exist, then get the address object if it exists or create
if it does not. then set the city property to new name.

this kind of stuff would be possible using custom action mapping
strategies. would need to create a MappingAction implementation which
could scan the object graph and create only when there is no map. the
writing stuff would be more tricky but could be done using an xml or
bean diff'er, i suppose.

i can't see how deletions could handled: there seems to be no way to
distinguish between information which is not present because it has not
changed and between data which has been removed.

> Are there any other ways to accomplish this?

i'm sure that there must be some bean and xml diff libraries out there
but no names spring to mind. an interesting problem, though.

- robert


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


Mime
View raw message