-----Original Message-----
From: Oleksiy Mishchenko [mailto:[EMAIL PROTECTED]]
Sent: 11 December 2002 17:15
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Marshaling heterogeneous collectionsHi Claude,Great thanks for the information.At the moment I use Castor version 0.9.4.I have done everything you suggested me (added auto-naming attribute and updated Engine with setProcessors(Vector processors)), but my new output looks like following:<engine>
<iprocessor><type>processorCPU</type>.......
</iprocessor>
<iprocessor><type>processorIO</type>
.......
</iprocessor>
</engine>
Real classes I use are different of course.It seems to me that Castor explores just the interface IProcessor instead of the real classes. I don't see any attributes and elements which are specific for the real classes.Each real class is defined in the mapping file with an element <map-to> and describes the mapping of all its fields.What could be wrong?CheersAlexei-----Original Message-----
From: Claude Vedovini [mailto:[EMAIL PROTECTED]]
Sent: 11 December 2002 15:51
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Marshaling heterogeneous collectionsHi,
Try with the following mapping:
<mapping>
<class name="Engine">
<map-to xml="engine" />
<field name="processors" type="IProcessor" collection="vector">
<bind-xml auto-naming="deriveByClass" node="element" />
</field>
</class>
<class name="processorCPU">
<map-to xml="cpu"/>
...
</class>
<class name="processorIO">
<map-to xml="pio"/>
...
</class>
<class name="processorVideo">
<map-to xml="pvideo"/>
...
</class>
</mapping>
Where you define specific sub-classes fields in place of the elipsis.
you could even define the mapping to IProcessor and then "extends" the other mappingsEngine should have the following form:
public class Engine {
private Vector processors;
public void setProcessors(Vector processors) {
this.processors = processors;
}
public Vector getProcessors() {
return processors;
}
}NOTE: this will only works with version 0.9.4.x of Castor
Have fun,
Claude
> -----Original Message-----
> From: Oleksiy Mishchenko
> [mailto:[EMAIL PROTECTED]]
> Sent: 11 December 2002 16:05
> To: [EMAIL PROTECTED]
> Subject: [castor-dev] Marshaling heterogeneous collections
>
>
> Hello,
>
> I have been exploring a possibility of using the Castor XML Mapping
> facilities for our needs.
> Everything I have tried works perfect and complies with our
> requirements.
> However, I am confronted with some difficulties concerning marshaling.
> I'm trying to map a Java class containing a collection of
> heterogeneous
> items, which are inherited from the same abstract class, to
> an XML document.
>
> Let me show the details using the Castor' classic example
> taken from the URI
> http://castor.exolab.org/xml-mapping.html#5.-xsi:type .
> Assume we have an architecture following the example but
> gently modified to
> demonstrate our real needs. We added a collection of the
> Vector type that
> should contain heterogeneous processors implementing the interface
> IProcessor:
> public interface IProcessor
> {
> public void process();
> }
> public class processorCPU implements IProcessor {...}
> public class processorIO implements IProcessor {...}
> public class processorVideo implements IProcessor {...}
> ..
> public class Engine
> {
> private Vector processors;
> public void addProcessor(IProcessor processor)
> {
> processors.add(processor);
> }
> public Vector getProcessors()
> {
> return processors;
> }
> }
>
> We would like to see an XML configuration file as following:
>
> <engine>
> <cpu/>
> <pio/>
> <pvideo/>
> </engine>
>
>
> At first I tried to use a mapping file that looks like below:
>
> <mapping>
> <class name="Engine">
> <map-to xml="engine" />
> <field name="processorCPU" type="IProcessor"
> required="false"
> set-method="addProcessor"
> get-method="getProcessors">
> <bind-xml name="cpu" node="element" />
> </field>
> <field name="processorIO" type="IProcessor"
> required="false"
>
> set-method="addProcessor"
> get-method="getProcessors">
> <bind-xml name="pio" node="element" />
> </field>
> <field name="processorVideo" type="IProcessor"
> required="false"
> set-method="addProcessor"
> get-method="getProcessors">
> <bind-xml name="pvideo" node="element" />
> </field>
> </class>
> </mapping>
>
> It works fine in a scope of unmarshaling, because of
> polymorphism and nature
> of the Vector collection. However, it is obvious that the method
> getProcessors() returns a whole collection of the
> heterogeneous elements,
> like: processorCPU, processorIO and processorVideo.
> The problem is that the Castor Mapping framework calls this
> method as many
> times as a number of corresponding fields present in the
> mapping file (in
> described case it is 3). Having not any opportunity to
> identify, which XML
> field Castor requests the data for, during processing a call
> of the method
> getProcessors() I cannot restrict the content of the returned
> Vector in
> order to present the objects of the necessary types only.
>
> I clearly realize that Castor's behavior in this situation is
> absolutely
> right and an actual problem is in the mapping, which has to
> be properly
> specified. It is important to denote that we would like to
> avoid specific
> tricks like using an attribute xsi:type="java:..." because,
> despite the fact
> it works correctly in the Castor framework, the prefix java
> prevents the XML
> document to be validated by other software we apply (e.g. XML Spy).
> Moreover, we want our XML documents would not contain any
> development tool
> or programming language specific features.
>
> The question is: could you please give me any hint how to achieve the
> functionality we need with the Castor API? Should I create
> some specific
> handler in an application implementing something like the FieldHandler
> interface etc. or there is any other way to solve the problem?
>
>
> Your any help is much appreciated.
>
> Alexei
> [EMAIL PROTECTED]
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
__________________________________________________________________________
� This email and any files transmitted with it are CONFIDENTIAL and intended
solely for the use of the individual or entity to which they are addressed.
� Any unauthorized copying, disclosure, or distribution of the material within
this email is strictly forbidden.
� Any views or opinions presented within this e-mail are solely those of the
author and do not necessarily represent those of Odyssey Asset Management
Systems SA unless otherwise specifically stated.
� An electronic message is not binding on its sender. Any message referring to
a binding engagement must be confirmed in writing and duly signed.
� If you have received this email in error, please notify the sender immediately
and delete the original.
Title: RE: [castor-dev] Marshaling heterogeneous collections
Claude,
I have
downloaded Castor-XML version 0.9.4.1 and just tried to use
it.
The
result is the same: Castor maps the content of the heterogeneous
Vector using getters of the interface specified for the
items of this Vector in the mapping file (IProcessor) and nothing
more (does not explore a real class implemented it: e.g. processorIO).
The real classes are definitely defined in the mapping as well,
but...
Is
there any solution?!!
Thanks
Alexei
- Re: [castor-dev] Marshaling heterogeneous collections Oleksiy Mishchenko
- Re: [castor-dev] Marshaling heterogeneous collecti... Arnaud Blandin
- Re: [castor-dev] Marshaling heterogeneous collecti... Keith Visco
- Re: [castor-dev] Marshaling heterogeneous collecti... Oleksiy Mishchenko
