Jody:
The Java compiler will not allow you to instantiate an abstract class, so
Castor cannot help you there. If the only difference between Command,
Response, and your other Message classes is a 'type', with no logic or data
storage differences, then perhaps, you should consider making Message a
concrete 'final' class, that contains a 'Type' property (that must be one of
a set of enumerated values).
Your XML could be represented as follows:
<Root>
<Message id="1" type="Command"/>
<Message id="2" type="Response"/>
</Root>
You could still feed Castor XML that looks like this:
<Root>
<Command id="1"/>
<Response id="2"/>
</Root>
But to do that, and still have only a single Message class, you'd need to
provide some descriptor classes.
Of course, another way to do achieve the same result would be to transform
the incoming XML (via XSLT or something similiar), from the external form
into the form required by Castor.
Good Luck,
Tom Drake
[EMAIL PROTECTED]
----- Original Message -----
From: "TERRILL,JODY (HP-Boise,ex1)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 17, 2001 1:28 PM
Subject: [castor-dev] Un/Marshalling abstract objects
| Hello,
|
| I am looking at using Castor as a marshalling framework and have some
| questions regarding how this might work with abstract java objects. I
have
| a java object model that allows a root object to contain one to many
| abstract message objects. I'll try to simplify and summarize this
below...
|
| public class Root{
| private java.util.ArrayList _messageList; // holds Message objects
| }
|
| public abstract class Message;
| public class Command extends Message;
| public class Response extends Message;
|
| The XML instance can look like ...
|
| <Root>
| <Command ID="3"/>
| </Root>
| or
| <Root>
| <Response ID="3"/>
| </Root>
|
| I would like the Root class to only hold the abstract base class Message
| (not Command and Response). Actually, in my problem there are potentially
| >50 Message types.
|
| I think I can do the unmarshalling if I add an XMLFieldDescriptorImpl for
| each possible Message type. What I think I would like is to write some
code
| that would generically create the object based upon it reflected name
(e.g.
| Command) and then checks to see if it is an instanceof Message. If it is,
I
| can add it to the _messagelist. This would allow others to extend the
| framework without having to change the Root marshalling.
|
| For marshalling, what I think I need is a way for the framework to find
the
| proper descriptor to call instead of the abstract classes descriptor (e.g.
| CommandDescriptor instead of MessageDescriptor). Is there a way for this
to
| happen or a way for the MessageDescriptor to figure the inheritance
| heirarchy out and call the correct descriptor?
|
| I have primarily been working with the compile-time Descriptors. I
briefly
| looked at the mapping behaviour but I didn't see how it would help in this
| situation and I would like the performance of the compile-time behaviour.
|
| Any insight into how this might be solved with Castor is appreciated.
|
| Thanks in advance,
| Jody Terrill
| Hewlett-Packard
|
| -----------------------------------------------------------
| 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