Keith,

Thanks !! That's a great explanation for a potentially confusing issue. I
really appreciate it!

Bob.

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 27, 2001 5:16 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] mapping.dtd question



Hi Robert,

They both could refer to the same thing but they don't have to. It
depends on the "scope". the map-to is used under a few circumstances:

1. If the class is the top-level class 
2. If inheritence is involved.
3. If no field descriptor can be found with a given XML name.

All other cases use the bind-xml at the field level.

If for example, I am unmarshalling the following XML document:

<?xml version="1.0"?>
<foo>
  <bar>...</bar>
</foo>

If using a mapping file Castor will look for a class that has a map-to
element with "foo" as the XML name so that it can Unmarshal the Foo
class. Or if Marshalling, Castor will use the map-to name as the root
element name for the top-level class.

The <bind-xml  name="..."/> is used at the field level, and takes
precedence over the desired map-to name of the class.

If I encounter an element called "bar", the Unmarshaller will first look
for a FieldDescriptor that has an XML name of "bar". If a Field is
found, it used that field. If no such field can be found, Castor will
then look for any classes that have a map-to XML name of "bar". If a
class is found, it looks for a FieldDescriptor whose type is of the same
type as the class.

During Marshalling, if it's a top-level class (ie has no parent class)
Castor uses the map-to name, otherwise it creates the name automatically
from the class name. If it's not a top-level class, it uses the bind-xml
name if present, or automatically creates the name based on the name of
the field.

This gives you the ability at the field level to change the XML name
used for the field.

It would be terrible if all classes had to have the same XML name. Take
java.lang.String for example. I wouldn't want all fields of String type
to have an XML name of "string". It's much more meaningful to be able to
have a name which describes the field as the XML name, regardless of the
type.

Hopefully you understood my ramblings about that...the short
answer...both are needed to provide a sufficient mapping of names during
XML databinding.

Thanks,

--Keith



Robert Ollila wrote:
> 
> Hi all,
> 
> I am confused by some xml references in the mapping.dtd.  There are two
> references to xml bindings:
> 
> The first:
> 
> <!ELEMENT map-to EMPTY>
> <!ATTLIST map-to
>         table NMTOKEN #IMPLIED
>         xml NMTOKEN #IMPLIED        <======right here !!!
>         ns-uri NMTOKEN #IMPLIED
>         ns-prefix NMTOKEN #IMPLIED
>         ldap-dn NMTOKEN #IMPLIED
>         ldap-oc NMTOKEN #IMPLIED
> >
> 
> 
> The second:
> 
> <!ELEMENT bind-xml EMPTY>
> <!ATTLIST bind-xml
>         name NMTOKEN #IMPLIED
>         type NMTOKEN #IMPLIED
>         matches NMTOKEN #IMPLIED
>         node (attribute | element | text) #IMPLIED
> >
> 
> 
> Don't these two references map the same thing ?
> 
> Any help would be appreciated,
> 
> Bob.
> 
> ======================================
> Robert Ollila
> Software Engineer
> Vina Technologies
> 25 Manchester Street
> Merrimack, NH 03054
> 603-589-0669
> ======================================
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to