Title: JDO: Abstract class and inheritance

if you knew that the Unmarshaller.unmarshal would unmarshall to a particular base class (or interface) you could :

 

com.enron.shred.everything.CastorBaseClass Obj obj = (com.enron.shred.everything.CastorBaseClass) Unmarshaller.unmarshal(Class.forName(className), reader);

 

this would either work or throw a ClassCastException

 

Conor

-----Original Message-----
From: Mielnicki, Steven J [mailto:[EMAIL PROTECTED]]
Sent
:
05 February 2003 20:41
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] JDO: Abstract class and inheritance

 

 

Thanks for the reply Conor

 

I know I can get type Object via Unmarshal via:

 

Object unmarshalled = Unmarshaller.unmarshal

 

But I suppose the question is then how do I then cast it to the proper type so I can access the get() methods?

 

In my example, com.enron.shred.everything.BrandNewCastorObj represents a future yet-to-be-seen, brand new instance of a Castor-generated XML schema.

 

I wanted to know if I can re-cast Object unmarshalled somehow to type com.enron.shred.everything.BrandNewCastorObj

 

Or is that asking for too much from the Java lang?

 

-----Original Message-----
From: Conor Allen [mailto:[EMAIL PROTECTED]]
Sent:
Wednesday, February 05, 2003 9:19 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] JDO: Abstract class and inheritance

 

Steven

 

I've done something similar with the static marshall and unmarshall methods on the Marshaller and Unmarshaller classes - as long as the mapping exists then you do not have a problem.

 

StringReader reader = new StringReader(xmlString);

Object unmarshalled = Unmarshaller.unmarshal(Class.forName(className), reader);

 

and

 

StringWriter writer = new StringWriter();

Marshaller.marshal(object ,writer);

 

You do not need a common base class to do this though.

 

Conor

 

-----Original Message-----
From: Mielnicki, Steven J [mailto:[EMAIL PROTECTED]]
Sent:
05 February 2003 13:15
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] JDO: Abstract class and inheritance

 

 

I have a similar question then:

 

Is it possible to create a base class with for abstract Unmarshal and Marshal methods (castor xml) such that I wouldn't have to explicitly cast during class loading?

 

I would like my code to be able to accommodate unknown, future XML schemas that become Castor-ized (as opposed to Pasteruized) into Java objects like this:

BaseClass bc = (BaseClass) Class.forName ( newCastorizedSchemaObject );

 

Without having to explicitly know the type name that could happen in the future, instead of

 

BrandNewCastorObj co = (BrandNewCastorObj) Class.forName ( "com.enron.shred.everything.BrandNewCastorObj" )

 

 

I am new to Castor so I suppose this could be stupid question, but is it possible to create generic Unmarshal code?

 

-          steve

 

 

-----O

riginal Message-----
From: "Legido Mart�nez, Isidoro" [mailto:[EMAIL PROTECTED]]
Sent:
Wednesday, February 05, 2003 4:09 AM
To: [EMAIL PROTECTED]
Subject: [castor-dev] JDO: Abstract class and inheritance

 

Hi,

(Sorry if this question has been posted before but I've found it in the documentation neither the mailing list).

+ Is it possible to define a JDO's mapping for an abstract class.
+ If I've two classes: ImplClass1 and ImplClass2 and both "extends" AbstractClass, Can I perform a query on AbstractClass?

I would expect to get back a collection of ImplClass1 and ImplClass2 's instances together.

Thanks a lot,

Isi,

--

This e-mail is confidential and is intended for the named recipient only. If
you receive it in error please destroy the message and all copies. Kainos
Software Ltd. does not accept liability for damage sustained as a result of
malicious software (e.g. viruses). Kainos does not accept liability for, or
permit, the creation of contracts on its behalf by e-mail, the publication of
any defamatory statement by its employees by e-mail, or changes subsequently
made to the original message. The Company's registered office is located at
4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland, Tel +44 28 9057 1100.

--

This e-mail is confidential and is intended for the named recipient only. If
you receive it in error please destroy the message and all copies. Kainos
Software Ltd. does not accept liability for damage sustained as a result of
malicious software (e.g. viruses). Kainos does not accept liability for, or
permit, the creation of contracts on its behalf by e-mail, the publication of
any defamatory statement by its employees by e-mail, or changes subsequently
made to the original message. The Company's registered office is located at
4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland, Tel +44 28 9057 1100.

Reply via email to