Thats mighty fair.   I expect to do this for 20 or so classes, so I
might not bother writing descriptors. 

Thanks.  

Rick

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 15, 2004 12:57 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-user] [XML] Inheritance and mapping the base class.




Hi Rick,

One workaround, which you could probably implement today, is to write
the ClassDescriptor for your sub classes:

So in this case, if you have a com.acme.Something class , that extends
com.acme.Base class, you can write a com.acme.SomethingDescriptor class
which extends XMLClassDescriptorImpl and returns com.acme.Base.class:

package com.acme;

public class SomethingDescriptor extends XMLClassDescriptorImpl {

  ...

    /**
     * 
     * @return Class
     */
    public java.lang.Class getJavaClass()
    {
        return com.acme.Base.class;
    } //-- java.lang.Class getJavaClass() 

  ...

}


It's a bit of work to write a Descriptor by hand, but it should work.
Usually if I have to write a descriptor by hand, I use an XML Schema and
have Castor generate me a descriptor fairly close to what I'm trying to
write and then I tweak it.

As for writing the enhancement, it won't come right away, as I have some
prior commitments on a few bugs (right Jeremy? :-) that I need to fix
before I even have a chance to look into this further. 

--Keith

Rick Ross wrote:
> 
> That would be magnificent!
> 
> Believe me, I'm very happy with the way Castor handles things by 
> default.  I just ran into a situation where there was no easy way to 
> marshall what I need to.
> 
> So..  Tomorrow?   :-)
> 
> Rick
> 
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 15, 2004 10:38 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-user] [XML] Inheritance and mapping the base 
> class.
> 
> Hi Rick,
> 
> It sounds like we need a new feature in the mapping file, something
> like:
> 
> <class name="Something" extends="com.acme.MyBase">
>   <bind-xml marshalAs="com.acme.MyBase"/>
> 
>   ...
> </class>
> 
> The reason Castor marshals as Something, rather than MyBase today is 
> that it tries as hard as it can to preserve what is being marshalled, 
> so that when you unmarshal you get back an object model similar to 
> that which you started with.
> 
> Also, many base classes are abstract, so saving the concrete class 
> helps to prevent unmarshal errors in the future.
> 
> Based on what you're trying to do, it seems like we simply need a way 
> for one to say a particular class should be "handled" as a instance of

> one of it's base class (or an ancestor class) or interfaces. In a 
> sense, a "virtual" cast.
> 
> --Keith
> 
> Rick Ross wrote:
> >
> > That's correct, except that I would be perfectly happy (ecstatic
> > really) to have the class attribute be set to the base class name as

> > well.
> >
> > R
> >
> > -----Original Message-----
> > From: Jay Goldman [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, July 15, 2004 7:54 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [castor-user] [XML] Inheritance and mapping the base 
> > class.
> >
> > Using transient and/or setting the auto-complete will eliminate any 
> > unwanted properties; however, won't the top level element still be 
> > 'something' or 'some-other-thing'?. I understood Rick's question as 
> > wanting a way to marshall a 'Something' and get xml that has a top 
> > level element of 'base' without a 'class' attribute. Jay
> >
> > -----Original Message-----
> > From: Benoit Maisonny [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, July 14, 2004 3:23 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [castor-user] [XML] Inheritance and mapping the base 
> > class.
> >
> > You can tell Castor to marshall only what you want from your 
> > classes. One way is by setting the transient attribute to true on 
> > the field element in your mapping. Another way is by setting the 
> > auto-complete attribute to false on the class element and specifying

> > each field that
> 
> > you want to marshall. I guess you can do it in yet another way using

> > FieldHandlers. Read the documentation to decide what's best for you.
> >
> > Benoit
> >
> > Rick Ross wrote:
> >
> > > Sure, I recognize that java is behaving as expected.  But surely 
> > > this is not the first time this has come up.
> > >
> > > I would have imagined many people want to do this, and for us, 
> > > we'd rather avoid clone/copy because we expect to do it a lot.
> > >
> > > Thanks.
> > >
> > > R
> > >
> > > -----Original Message----- From: Jay Goldman 
> > > [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 14, 2004 5:46

> > > AM
> > >  To: [EMAIL PROTECTED] Subject: Re: [castor-user] [XML] 
> > > Inheritance and mapping the base class.
> > >
> > >
> > > Since java objects (unlike c++ objects) do not change their type 
> > > when
> >
> > > they are 'cast' the castor behavior is correct. In fact, the cast 
> > > is
> 
> > > essentially meaningless - at runtime you have a Something or a 
> > > SomeOtherThing not simply a Base. You could obviously create a 
> > > Base instance using the object you have (via clone or copy 
> > > constructor on
> > > Base) and then marshall this instance.
> > >
> > > Jay
> > >
> > > -----Original Message----- From: Rick Ross 
> > > [mailto:[EMAIL PROTECTED]
> >
> > > Sent: Wednesday, July 14, 2004 1:11 AM
> > > To: [EMAIL PROTECTED] Subject: [castor-user] [XML] 
> > > Inheritance and mapping the base class.
> > >
> > >
> > >
> > > Hi.  I have some base classes I use for a group of classes. 
> > > Something
> > > like:
> > >
> > > public class Base { // a bunch of bean style getters and setters. 
> > > }
> > >
> > > public class Something extends Base { // different getters and 
> > > setters
> >
> > > }
> > >
> > > public class SomeOtherThing extends Base { // you get the 
> > > picture...
> 
> > > }
> > >
> > > When objects are instantiated, they are always instantiated as 
> > > Something or SomeOtherThing objects.  When I go to marshall them, 
> > > I always cast them into Base objects because that is all I want 
> > > marshalled. However, I always get the fields from Something and 
> > > SomeOtherThing.
> > >
> > > In fact, in the xml output, the class attribute is always the 
> > > fully qualified class name of the instantiated class, not the base

> > > class.
> > >
> > > I have tried a mapping and using the "extends" attribute, but that

> > > did
> >
> > > not work either.  In that case, the output had something like 
> > > some-other-thing as the class name, which I seem to recall is a 
> > > castor
> >
> > > name mangling convention.
> > >
> > > I thought I could do this in the mapping :
> > >
> > > <class name="SomeOtherThing" extends="Base" /> <class name="Base">

> > > ... all of my mapping for the base class fields here. </class>
> > >
> > > Can anyone offer a bit of insight?   Am I just missing the concept
> or
> > >  missing a setting?
> > >
> > > Thanks
> > >
> > > Rick
> > >
> > >
> > >
> > >
> > > ------------------------------------------------------------------
> > > --
> > > --
> > > --
> > >
> > >
> > > ----------------------------------------------------------- If you

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



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

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

Reply via email to