Re: [Simple-support] Problem with override
Brought to you by:
niallg
|
From: saurabh s. <sau...@ya...> - 2009-03-03 10:52:37
|
Hi,
Here is a sample how JAXB does it...
public class Root{ @XmlElementRefs
(
@XmlElementRef(type=Truck.class),
@XmlElementRef(type=Motorcycle.class) { } )}
public abstract class
}Automobile {
public class
}Truck extends Automobile {
public class
}Motorcyle extends Automobile {
List<Automobile> vehicles;
Regards,
Saurabh.
________________________________
From: "Nia...@ub..." <Nia...@ub...>
To: sau...@ya...; gal...@ya...; sim...@li...; gio...@te...
Sent: Tuesday, 3 March, 2009 2:55:09 PM
Subject: RE: [Simple-support] Problem with override
Hi,
This looks like a nice idea, some had raised a similar issue some time ago. Do you know what annotation is used in JAXB to achieve this? I've not seen it before.
Thanks,
Niall
________________________________
From: saurabh sule [mailto:sau...@ya...]
Sent: 02 March 2009 06:41
To: gal...@ya...; sim...@li...; Sacchi Giovanna
Subject: Re: [Simple-support] Problem with override
One way to achieve this is on the same lines of JAXB.
You can have an annotation like this:
@ElementRef(class="<comma-separared list of all the implementing classes>"). Now when you serialize, you can use the name of the actual implementing class itself that is contained within the vairable or use the name from the annotation on that class.
While deserializing, you can match the name of the tag from the xml to a name from the list or their annotations and create an instance of the actual implementing class.
E.g
public
@ElementRef(class="Impl1.class, Impl2.class")
public Iface iface;
}
public class Impl1 implements Iface {
}
public class Impl2 implementsIface {Regards,
}
XML - 1:
<?
<xml version="1.0" encoding="UTF-8"?>root>
<impl1></impl1>root>
</
XML - 2:
<?
<xml version="1.0" encoding="UTF-8"?>root>
<impl2></impl2>root>
</
class Root {
Saurabh.
________________________________
From: Niall Gallagher <gal...@ya...>
To: "sim...@li..." <sim...@li...>; Sacchi Giovanna <gio...@te...>; saurabh sule <sau...@ya...>
Sent: Friday, 27 February, 2009 6:15:31 PM
Subject: Re: [Simple-support] Problem with override
Hi,
Actually, you are right, it will call all instances "reference". Did not see the different types mentioned. Here the problem is how to match the element with the field. If the names do not match, either by field name or by the name attribute on the annotation then there is no real way to match the element or attribute with the field or method.
However, I welcome any proposals for how to do this, either via an extra annotation or some other scheme.
Thanks,
Niall
--- On Thu, 2/26/09, saurabh sule <sau...@ya...> wrote:
From: saurabh sule <sau...@ya...>
Subject: Re: [Simple-support] Problem with override
To: gal...@ya..., "sim...@li..." <sim...@li...>, "Sacchi Giovanna" <gio...@te...>
Date: Thursday, February 26, 2009, 6:12 PM
Hi,
But this solution will always serialize the Formula to "reference", am I right?
What if one wants to have "reference" , "constant" or "function" depending on the actual implementation?
Is this possible?
Regards,
Saurabh.
________________________________
From: Niall Gallagher <gal...@ya...>
To: "sim...@li..." <sim...@li...>; Sacchi Giovanna <gio...@te...>
Sent: Thursday, 26 February, 2009 6:20:32 PM
Subject: Re: [Simple-support] Problem with override
Hi,
Just name the @Element like so.
@Element(name="reference")
Formula formula;
This will serialize the Formula class as "reference".
Hope this helps,
Niall
--- On Thu, 2/26/09, Sacchi Giovanna <gio...@te...> wrote:
From: Sacchi Giovanna <gio...@te...>
Subject: [Simple-support] Problem with override
To: "sim...@li..." <sim...@li...>
Date: Thursday, February 26, 2009, 3:13 AM
Hi,
I’m trying to serialize a class similar to this one:
publicclassBinding {
@Attribute
privateType type;
@Attribute
privateString name;
@Attribute
privateSide side;
@Attribute(required=false)
privateString part;
@Element
privateFormula formula;
...
}
Where Formula is an interface implemented by three classes: Constant, Function and Reference. For instance, I have annotated the Reference class, like that:
publicclassReference implementsFormula {
@Attribute
privateString activity;
@Attribute
privateType type;
@Attribute
privateString name;
@Attribute
privateSide side;
...
}
When the Binding class is serialized the following xml file is produced:
<bindingtype="NORMAL" name="par21" side="IN">
<formulaclass="com.tilab.wemash.model.Reference" activity="webServiceActivity1" type="NORMAL" name="par11" side="OUT"/>
</binding>
I would like to know if it there is any way to produce, instead, the following xml:
<bindingtype="NORMAL" name="par21" side="IN">
<referenceclass="com.tilab.wemash.model.Reference" activity="webServiceActivity1" type="NORMAL" name="par11" side="OUT"/>
</binding>
That is: when the element formula of the Binding is serialized, I want that the name of the class Reference is used as element name instead of the name of the interface implemented by the class Reference.
Regards,
Giovanna
------------------------------------------------------------------
Telecom Italia
Giovanna Sacchi
Information Technology
Innovation, Architecture & Quality
IT Innovation
Via G. Reiss Romoli, 274 - 10148 Torino
+ 39 011 2288040
+ 39 331 6001656
Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle persone indicate. La diffusione, copia o qualsiasi altra azione derivante dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora abbiate ricevuto questo documento per errore siete cortesemente pregati di darne immediata comunicazione al mittente e di provvedere alla sua distruzione, Grazie.
This e-mail and any attachments is confidential and may contain privileged information intended for the addressee(s) only. Dissemination, copying, printing or use by anybody else is unauthorised. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail, Thanks.Rispetta l'ambiente. Non stampare questa mail se non è necessario.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
________________________________
Add more friends to your messenger and enjoy! Invite them now.
________________________________
Add more friends to your messenger and enjoy! Invite them now.
Download prohibited? No problem. CHAT from any browser, without download. Go to http://in.webmessenger.yahoo.com/ |