[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-users
Subject:    Re: [jibx-users] binding for HashMaps
From:       Dennis Sosnoski <dms () sosnoski ! com>
Date:       2005-06-23 20:58:16
Message-ID: 42BB2268.4070608 () sosnoski ! com
[Download RAW message or body]

The issues with using HashMapperStringToComplex for this case are that 
there's no item count attribute on the root elements, and the values in 
the low-level maps are just strings. These are pretty easy to handle, 
though - the HashMapperStringToComplex code is designed to be used as a 
basis for custom hashmaps, and if you look at what the code is doing you 
should be able to figure out how to change it to skip the item count and 
work with string values. That gives you the basic hashmap handling.

The higher-level hashmap of rows is a little trickier. I'd suggest you 
create a wrapper class for the report row data, like this:

public class ReportRow {
    private String key;
    private Map cells;
    ...
}

Then write another wrapper around the actual hash map that makes it look 
like a collection of these ReportRow instances, implementing add-method, 
size-method, and get-method methods. For the marshalling side you could 
use a pre-get method on this hash map wrapper to actually get the set of 
map entries from the hash map and build an array of ReportRow instances 
- the size-method and get-method can then work with this array.

This may sound complex, but shouldn't actually involve that much code. 
Hope it helps,

  - Dennis

Putrycz, Erik wrote:

> I never used hashmaps with JiBX but one solution would be to define an object \
> reportElem and two subclasses -> reportcolums and reportRows. And in your main \
> Report object you create a collection containing reportElem and you map your \
> subclasses to the elements. I would then transform that into hashmaps in a program. \
> Also have a look at \
> http://jibx.sourceforge.net/api/org/jibx/extras/HashMapperStringToComplex.html 
> Erik.
> -----Original Message-----
> From: jibx-users-admin@lists.sourceforge.net \
>                 [mailto:jibx-users-admin@lists.sourceforge.net] On Behalf Of Andy P
> Sent: June 14, 2005 18:29
> To: jibx-users@lists.sourceforge.net
> Subject: [jibx-users] binding for HashMaps
> 
> 
> Hi,
> 
> I am a newbie trying to come up with a binding file for the following XML snippet. \
> Ideally I would like to store my data in two hashmaps: reportColumns and \
> reportRows. reportRows would contain <key, reportCells> where reportCells is \
> another hashmap with <key,value> pair. 
> I have tried various things using the samples but I end up using Dom4JElementMapper \
> and doing things manually which defeats ther purpose of using Jibx.  
> Any help with the binding will be much appreciated.
> 
> -Andy
> 
> <report>	
> 
> <reportColumns>
> <reportColumn name="objId">Object ID</reportColumn> <reportColumn \
> name="hostType">Type</reportColumn> <reportColumn \
> name="objStatus">Status</reportColumn> <reportColumn \
> name="hostFullName">Appliance</reportColumn> </reportColumns>
> 	
> <reportRows>
> <reportRow key="420">
> <reportCell name="objId">420</reportCell>
> <reportCell name="hostType">BladeCenter</reportCell>
> <reportCell name="objStatus">Critical</reportCell>
> <reportCell name="hostFullName">ataboy</reportCell>
> </reportRow>
> 			
> <reportRow key="304">
> <reportCell name="objId">304</reportCell>
> <reportCell name="hostType">Sunfire1280</reportCell>
> <reportCell name="objStatus">Critical</reportCell>
> <reportCell name="hostFullName">bigdog</reportCell>
> </reportRow>
> 		
> </reportRows>
> </report>
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. \
> Find simple to follow Roadmaps, straightforward articles, informative Webcasts and \
> more! Get everything you need to get up to speed, fast. \
> http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click \
> _______________________________________________ jibx-users mailing list
> jibx-users@lists.sourceforge.net \
> https://lists.sourceforge.net/lists/listinfo/jibx-users 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
> 
> 
> 


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic