Looking at how class mappings work, it doesn't seem like MapItem will allow me to do what I want.

Inline with what ralf suggested on the irc channel, I'm going to marshall each address object in the Map to an AddressEntry complex type that has a type and address subelement, like so...

<addressEntry>
   <type>...</type>
   <address>...</address>
</addressEntry>

Tada!

Adam

Jessica Perry Hekman wrote:

You've reached the limit of my knowledge -- hopefully someone else can step up here :)

Jessica

On Tue, Dec 20, 2005 at 05:04:02PM -0500, Adam Kramer wrote:
I had been doing something similiar but I had included a type of PostalAddress in the postalAddresses field. This caused the key and value fields to not be output according to their bind-xml name values like type and address. When I used the mapping without the type of PostalAddress in the postalAddresses field you specified below, I get *ALMOST* what I want.

<address type="Secondary">
      <address>
          <street>12424 lane lane</street>
          <state>MI</state>
          <postalCode>12421</postalCode>
          <city>Bobville</city>
          <country>US</country>
      </address>
</address>

So now I have an address tag nested inside an address tag. Is there any way to specify a null tag value for the second address in its bind-xml tag?

Thanks for the help,
Adam

Jessica Perry Hekman wrote:

As Stephen points out in another post, I seem to have learned today how to do this. I am sure someone on the list will correct me if I get it wrong.

I have left out the namespace specifications but you can easily put them back in.

<class name="edu.umich.med.cacr.hb.Person">
<field name="postalAddresses" collection="map">
   <bind-xml name="address" node="element" />
    <class name="org.exolab.castor.mapping.MapItem">
      <field name="key" type="string">
        <bind-xml name="type" node="attribute" />
      </field>
      <field name="value" type="edu.umich.med.cacr.hb.PostalAddress">
        <bind-xml name="address" />
      </field>
    </class>
</field>
</class>

I *think* that should do it!

Jessica


On Tue, Dec 20, 2005 at 03:43:26PM -0500, Adam Kramer wrote:


Hi all,

My first post...

I has a Person class that has a map of postalAddresses. Each postal address has a key of 'type'. I'd like to marshall the addresses into a form where hte key was an attribute and the value was output as <address>:

<person>
  <address type="primary">
       <street>12424 lane lane</street>
        <state>MI</state>
        <postalCode>12421</postalCode>
        <city>Bobville</city>
        <country>US</country>
  </address>
  <address type="secondary">
   ....
  </address>
</person>

Right now, I can only get the mapping output that the default MappingItem class sets which is
<address>
    <key>Primary</key>
    <value>
        <street>12424 lane lane</street>
        <state>MI</state>
        <postalCode>12421</postalCode>
        <city>Bobville</city>
        <country>US</country>
    </value>
</address>

Any help is greatly appreciated.

This is what I currently have for my mapping below:
<class cst:name="edu.umich.med.cacr.hb.Person">
<field cst:name="postalAddresses" cst:type="edu.umich.med.cacr.hb.PostalAddress" collection="map">
   <bind-xml name="address" node="element" />
</field>
</class>

<class cst:name="edu.umich.med.cacr.hb.PostalAddress">
<field cst:name="streetAddressExt" cst:type="java.lang.String">
  <bind-xml name="streetExt" node="element" />
</field>
<field cst:name="streetAddress" cst:type="java.lang.String">
  <bind-xml name="street" node="element" />
</field>
<field cst:name="state" cst:type="java.lang.String">
  <bind-xml name="state" node="element" />
</field>
<field cst:name="postalCode" cst:type="java.lang.String">
  <bind-xml name="postalCode" node="element" />
</field>
<field cst:name="city" cst:type="java.lang.String">
  <bind-xml name="city" node="element" />
</field>
<field cst:name="country" cst:type="java.lang.String">
  <bind-xml name="country" node="element" />
</field>
</class>

Thanks,
Adam Kramer


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------


-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to