Hi S L, The factory method does not need to be created in the abstract class itself, rather not indeed. But since JiBX needs to bind on some instance of an concrete class, it does need to be able to aquire an instance. This all only applies for binding from XML to Java btw. If you only want to bind from Java to XML, see the 'Direction and tracking' section here: http://jibx.sourceforge.net/tutorial/binding-advanced.html See this link for information about factories: http://en.wikipedia.org/wiki/Factory_method_pattern
Kind regards, Erik On Fri, Nov 16, 2012 at 5:18 AM, S L <jibxu...@yahoo.com> wrote: > Hi Erik, > > I don't understand how this is supposed to work. We have 3 subclasses of > the abstract class ForwardLinkProfileData. If the ForwardLinkProfileData > class is supposed to have a static factory method that creates and returns > an instance of one of the subclasses, how does it know which of the 3 > subclasses to create? I see from the link you provided that the factory > method can take an Object parameter that represents the "owning object", > which in this case would be the VmtData object. Am I supposed to do > reflection on the VmtData object to determine which subclass it contains? > Then I would need to hardcode the name of the getter method for the > ForwardLinkProfileData object and that doesn't seem like good practice - > what if the name of the getter method is changed in the future, or what if > the getter method has a different name in each class that has a reference > to ForwardLinkProfileData? Also, what if the VmtData object were to have 2 > ForwardLinkProfileData objects (potentially 2 different subclasses) - how > would the factory method know which subclass to create? Are there any > examples for how to do this with JiBX? > > Also, I put in a temporary factory method in ForwardLinkProfileData that > just returns a new instance of one of the subclasses - just to see the > resulting xml/xsd/wsdl files that get generated. I did a text search for > the name of the subclass in all the xml/xsd/wsdl files and found nothing. > I don't see how those subclasses will get mapped to XML if they aren't > mentioned in any of the generated files. > > Thanks, > S L > > ------------------------------ > *From:* Erik Mulder <erik.mul...@qsd.nl> > *To:* S L <jibxu...@yahoo.com>; JiBX users < > jibx-users@lists.sourceforge.net> > *Sent:* Thursday, November 15, 2012 3:21 AM > *Subject:* Re: [jibx-users] factory-method needed for abstract type > > Hi S L, > > You do need a factory here, as JiBX asks for. Look at it from the JiBX > point of view: you have an XML file and want to bind to an object of an > abstract type. Hoe can you do that if you cannot instantiate an abstract > class? This is why JiBX asks for a factory to create a new object of the > desired type, so it can call the setters on that object. How the factory > creates the object is up to you, as long as it's a subclass of the > requested abstract class. You say that you already do set objects that are > subclasses of the 'ForwardLinkProfileData' class. So make a factory that > returns an object of a subtype, so JiBX can use that. > See http://jibx.sourceforge.net/details/binding-attributes.html#objectfor > details, good luck. > > Erik > > > On Wed, Nov 14, 2012 at 8:01 PM, S L <jibxu...@yahoo.com> wrote: > > I am getting the following error when I run Jibx2Wsdl: > > Error: factory-method needed for abstract type > 'ems.shared.config.ForwardLinkProfileData'; on structure element at (line > 32, col 91, in config_vmtBinding.xml) > > In config_vmtBinding.xml, it has: > > <mapping abstract="true" type-name="ns4:vmtData" > class="ems.shared.config.vmt.VmtData"> > <!-- other lines removed --> > <!-- this is line 32 --> > <structure map-as="ns1:forwardLinkProfileData" field="fl" > usage="optional" name="fl"/> > > So our VmtData class has a private field named "fl" of type > ForwardLinkProfileData, as well as getFl() and setFl() methods to get and > set the fl field. When we call getFl() and setFl(), we are actually > getting and setting objects that are subclasses of the > ForwardLinkProfileData class. > > I'm not sure how to go about creating a factory method for the > ForwardLinkProfileData class, since you can't create an instance of an > abstract class. Any suggestions on how to resolve this error? > > > > ------------------------------------------------------------------------------ > Monitor your physical, virtual and cloud infrastructure from a single > web console. Get in-depth insight into apps, servers, databases, vmware, > SAP, cloud infrastructure, etc. Download 30-day Free Trial. > Pricing starts from $795 for 25 servers or applications! > http://p.sf.net/sfu/zoho_dev2dev_nov > _______________________________________________ > jibx-users mailing list > jibx-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/jibx-users > > > > > -- > *Erik Mulder* > Principal Consultant > > *m*: +31 6 40 76 45 22 > *@*: erik.mul...@qsd.nl > > > * > QSD B.V. > *Loolaan 89 > 3971 PM Driebergen-Rijsenburg > t: +31 343 76 41 50 > *w*: http://www.qsd.nl/ > *@*: i...@qsd.nl > > Dit bericht is vertrouwelijk en kan geheime informatie bevatten enkel > bestemd voor de geadresseerde. Indien dit bericht niet voor u is bestemd, > verzoeken wij u dit onmiddellijk aan ons te melden en het bericht te > vernietigen. Aangezien de integriteit van het bericht niet veilig gesteld > is middels verzending via internet, kan QSD niet aansprakelijk worden > gehouden voor de inhoud daarvan. Hoewel wij ons inspannen een virusvrij > netwerk te hanteren, geven wij geen enkele garantie dat dit bericht > virusvrij is, noch aanvaarden wij enige aansprakelijkheid voor de mogelijke > aanwezigheid van een virus in dit bericht. Op al onze rechtsverhoudingen, > aanbiedingen en overeenkomsten waaronder QSD goederen en/of diensten levert > zijn met uitsluiting van alle andere voorwaarden de Leveringsvoorwaarden > van QSD van toepassing. Deze worden u op aanvraag direct kosteloos > toegezonden. > > This e-mail and the documents attached are confidential and intended > solely for the addressee; it may also be privileged. If you receive this > e-mail in error, please notify the sender immediately and destroy it. As > its integrity cannot be secured on the Internet, the QSD liability cannot > be triggered for the message content. Although the sender endeavours to > maintain a computer virus-free network, the sender does not warrant that > this transmission is virus-free and will not be liable for any damages > resulting from any virus transmitted. On all offers and agreements under > which QSD supplies goods and/or services of whatever nature, the Terms of > Delivery from QSD exclusively apply. The Terms of Delivery shall be > promptly submitted to you on your request. > > QSD B.V. > KvK Utrecht 53067231 > > > > -- *Erik Mulder* Principal Consultant *m*: +31 6 40 76 45 22 *@*: erik.mul...@qsd.nl * QSD B.V. *Loolaan 89 3971 PM Driebergen-Rijsenburg t: +31 343 76 41 50 *w*: http://www.qsd.nl/ *@*: i...@qsd.nl Dit bericht is vertrouwelijk en kan geheime informatie bevatten enkel bestemd voor de geadresseerde. Indien dit bericht niet voor u is bestemd, verzoeken wij u dit onmiddellijk aan ons te melden en het bericht te vernietigen. Aangezien de integriteit van het bericht niet veilig gesteld is middels verzending via internet, kan QSD niet aansprakelijk worden gehouden voor de inhoud daarvan. Hoewel wij ons inspannen een virusvrij netwerk te hanteren, geven wij geen enkele garantie dat dit bericht virusvrij is, noch aanvaarden wij enige aansprakelijkheid voor de mogelijke aanwezigheid van een virus in dit bericht. Op al onze rechtsverhoudingen, aanbiedingen en overeenkomsten waaronder QSD goederen en/of diensten levert zijn met uitsluiting van alle andere voorwaarden de Leveringsvoorwaarden van QSD van toepassing. Deze worden u op aanvraag direct kosteloos toegezonden. This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the QSD liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. On all offers and agreements under which QSD supplies goods and/or services of whatever nature, the Terms of Delivery from QSD exclusively apply. The Terms of Delivery shall be promptly submitted to you on your request. QSD B.V. KvK Utrecht 53067231
<<QSD-icon-gradient.png>>
------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users