Look, there's a set of rules that aplpy with almost any tools. If your requirements don't follow those rules, there's no easy answer.
Regards Werner jimmi4664 wrote: > ...do you know how handle this kind of problem with castor, or not? > > > jimmi4664 wrote: >> My problem is: >> >> 1. I have a given Java object graph with number of objects with >> relationships between them >> 2. There's no primary keys / unique identifiers in the objects >> 3. I am using "- mapping file driven" "modus operandi" for Castor >> >> How do I generate the mapping file to map the object graph (a few examples >> have been shown in this thread) to XML and back? >> >> >> 2009/11/17 Werner Guttmann <[email protected]> >> >>> Hi >>> >>> jarkko pave wrote: >>>> I have used XML, schemas and namespaces and am reasonably familiar with >>>> those concepts. >>>> >>>> The problem is that all the documentation I have read so far is about >>>> creating this mapping.xml file to describe your mapping. I do not know >>> how >>>> XML schemas can be used to define the mapping. >>> As the Castor XML reference guide suggest, Castor XML can work in >>> various modi operandi: >>> >>> - introspection mode >>> - mapping file driven >>> - working with generated POJO/descriptor classes >>> >>> Internally, all three modes translate to a binding between a Java >>> artefact and an XML artefact, so that Castor XML can perform its XML >>> data binding functions. >>> >>>> I have not seen any >>>> documentation that talks about using schemas for that. >>> I am sure the reference guide has a lot of documentation about the XML >>> source (code) generator, where Java POJOs and their corresponsing >>> descriptor classes are generated from an XML schema. >>> >>>> Hence I don't see how >>>> IDREFs etc are relevant to my problem. >>> Taking into account the duality explained above, it's just another >>> starting point for Castor XML. >>>> For example the mentioned >>>> http://www.castor.org/how-to-use-references-in-xml.html talks about >>> creating >>>> a mapping XML and I cannot see schemas mentioned there. >>>> >>>> Please enlighten me... >>>> >>>> 2009/11/17 Werner Guttmann <[email protected]> >>>> >>>>> Hi, >>>>> >>>>> jarkko pave wrote: >>>>>> Hi, >>>>>> >>>>>> I have looked a bit at schema, ID and IDREFs... >>>>>> >>>>>> how do I "use XML schemas to define your contracts"? Where can I find >>>>>> documentation on this? >>>>> If you are not really familiar with e.g. XML schemas as a construct to >>>>> provide a structure definition for your XML documents, I am not really >>>>> of any help here. >>>>> >>>>> When you want to use Castor XML as a XML data binding framework, some >>>>> knowledge in the areas related (XML, XMl schemas, namespaces, ....) >>> are >>>>> a pre-requisite. >>>>> >>>>> Cheers >>>>> Werner >>>>>> 2009/11/13 Werner Guttmann <[email protected]> >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> jimmi4664 wrote: >>>>>>>> There's no requirements on the XML, other than I want to persist my >>>>>>> objects >>>>>>>> as an XML file, and be able to reconstruct them later. The >>> resulting >>>>> XML >>>>>>> can >>>>>>>> (pretty much) be whatever castor would like it to be. >>>>>>>> >>>>>>>> So, -for example- following XML would be fine: >>>>>>>> >>>>>>>> <person> >>>>>>>> <name>asdfas</name> >>>>>>>> <castor-generated-id>4652</castor-generated-id> >>>>>>>> <cars> >>>>>>>> <car> >>>>>>>> <license-plate>34243</license-plate> >>>>>>>> <owner-castor-generated-id>4652</owner-castor-generated-id > >>>>>>>> </car> >>>>>>>> <car> >>>>>>>> <license-plate>111221</license-plate> >>>>>>>> < owner-castor-generated-id >4652</owner-castor-generated-id >>>>>>>> </car> >>>>>>>> </cars> >>>>>>>> </person> >>>>>>>> >>>>>>>> The fact is that I don't have "id" field in my objects. They are >>> pure >>>>>>> POJOs >>>>>>>> and just have object references to one another. Castor _could_ >>>>>>> theoretically >>>>>>>> cope with this requirement by just using object identity and >>> generating >>>>>>>> correct "id" fields internally. >>>>>>> Yes and no. If you were to use XML schemas to define your contracts, >>>>>>> you'd be using <xsd:ID/> and <xsd:IDREF/> types to denote that you >>> are >>>>>>> dealing with (cyclic) references. Have a look at e.g. the XML Schema >>>>>>> Primer [1] first, and we'll continue our conversation after you have >>>>>>> familiarized yourself with the concepts presented therein. >>>>>>> >>>>>>> Okay ? >>>>>>> >>>>>>> Regards >>>>>>> Werner >>>>>>> >>>>>>> [1] http://www.w3.org/TR/xmlschema-0/ >>>>>>> >>>>>>>> I don't know if this is available, or do I need to create >>> artificial >>> ID >>>>>>>> fields in my POJOs? >>>>>>>> >>>>>>>> Another alternative is to forget about Car.owner in the mapping and >>>>> just >>>>>>> fix >>>>>>>> it manually after unmarshalling the objects. >>>>>>>> >>>>>>>> >>>>>>>> Werner Guttmann-6 wrote: >>>>>>>>> Hi, >>>>>>>>> >>>>>>>>> how does/should your XML actually look like ? >>>>>>>>> >>>>>>>>> Regards >>>>>>>>> Werner >>>>>>>>> >>>>>>>>> jimmi4664 wrote: >>>>>>>>>> That seems to assume I would have a unique identifier in my >>> object. >>>>>>>>>> There's >>>>>>>>>> actually no good field in my example that could be used like >>> that, >>>>> and >>>>>>>>>> what's worse my real world case does not have that either. >>>>>>>>>> >>>>>>>>>> So I believe if I want to make castor set the references >>> correctly, >>> I >>>>>>>>>> need >>>>>>>>>> to add some artificial ID field to my classes? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Ralf Joachim-2 wrote: >>>>>>>>>>> Hi Janne, >>>>>>>>>>> >>>>>>>>>>> when using mapping usage of references as explained in: >>>>>>>>>>> >>>>>>>>>>> http://www.castor.org/how-to-use-references-in-xml.html >>>>>>>>>>> >>>>>>>>>>> may help. If you generate code out of XSD you may need to take a >>>>> look >>>>>>> at >>>>>>>>>>> xs:id and xs:idref to handle this. >>>>>>>>>>> >>>>>>>>>>> Having said that I never used that myself. >>>>>>>>>>> >>>>>>>>>>> Regards >>>>>>>>>>> Ralf >>>>>>>>>>> >>>>>>>>>>> jimmi4664 schrieb: >>>>>>>>>>>> I tried autocreating mapping file for a simple example using >>>>>>>>>>>> MappingTool >>>>>>>>>>>> to >>>>>>>>>>>> maybe give a hint on how to do this: >>>>>>>>>>>> >>>>>>>>>>>> public class Owner { >>>>>>>>>>>> private String name; >>>>>>>>>>>> private ArrayList<Vehicle> vehicles = new >>> ArrayList<Vehicle>(); >>>>>>>>>>>> public String getName() { >>>>>>>>>>>> return name; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public void setName(String name) { >>>>>>>>>>>> this.name = name; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public ArrayList<Vehicle> getVehicles() { >>>>>>>>>>>> return vehicles; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public void setVehicles(ArrayList<Vehicle> vehicles) { >>>>>>>>>>>> this.vehicles = vehicles; >>>>>>>>>>>> } >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public class Vehicle { >>>>>>>>>>>> private String name; >>>>>>>>>>>> private Owner owner; >>>>>>>>>>>> >>>>>>>>>>>> public String getName() { >>>>>>>>>>>> return name; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public void setName(String name) { >>>>>>>>>>>> this.name = name; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public Owner getOwner() { >>>>>>>>>>>> return owner; >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> public void setOwner(Owner owner) { >>>>>>>>>>>> this.owner = owner; >>>>>>>>>>>> } >>>>>>>>>>>> } >>>>>>>>>>>> >>>>>>>>>>>> MappingTool tool = new MappingTool(); >>>>>>>>>>>> tool.setInternalContext(new >>>>>>>>>>>> BackwardCompatibilityContext()); >>>>>>>>>>>> boolean deep = true; >>>>>>>>>>>> File targetFile = new >>> File("generated-mapping.xml"); >>>>>>>>>>>> log.debug("generating mapping file..."); >>>>>>>>>>>> tool.addClass(Owner.class, deep); >>>>>>>>>>>> fw = new FileWriter(targetFile); >>>>>>>>>>>> tool.write(fw); >>>>>>>>>>>> log.debug("...done generating mapping file: " + >>>>>>>>>>>> targetFile); >>>>>>>>>>>> >>>>>>>>>>>> But the end result is: >>>>>>>>>>>> >>>>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?> >>>>>>>>>>>> <mapping xmlns="http://castor.exolab.org/" >>>>>>>>>>>> xmlns:cst="http://castor.exolab.org/"> >>>>>>>>>>>> <description xmlns="">Castor generated mapping >>>>> file</description> >>>>>>>>>>>> <class name="tests.Owner"> >>>>>>>>>>>> <description xmlns="">Default mapping for class >>>>>>>>>>>> tests.Owner</description> >>>>>>>>>>>> <map-to/> >>>>>>>>>>>> <field name="name" type="java.lang.String"> >>>>>>>>>>>> <bind-xml name="name" node="element"/> >>>>>>>>>>>> </field> >>>>>>>>>>>> <field name="vehicles" type="java.lang.Object" >>>>>>>>>>>> collection="arraylist"> >>>>>>>>>>>> <bind-xml name="vehicles" node="element"/> >>>>>>>>>>>> </field> >>>>>>>>>>>> </class> >>>>>>>>>>>> </mapping> >>>>>>>>>>>> >>>>>>>>>>>> So it seems it maps Vehicles in the list as Objects, which does >>> not >>>>>>>>>>>> help >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> >>>>>>>>>>> Syscon Ingenieurbüro für Meß- und Datentechnik GmbH >>>>>>>>>>> Ralf Joachim >>>>>>>>>>> Raiffeisenstraße 11 >>>>>>>>>>> 72127 Kusterdingen >>>>>>>>>>> Germany >>>>>>>>>>> >>>>>>>>>>> Tel. +49 7071 3690 52 >>>>>>>>>>> Mobil: +49 173 9630135 >>>>>>>>>>> Fax +49 7071 3690 98 >>>>>>>>>>> >>>>>>>>>>> Internet: www.syscon.eu >>>>>>>>>>> E-Mail: [email protected] >>>>>>>>>>> >>>>>>>>>>> Sitz der Gesellschaft: D-72127 Kusterdingen >>>>>>>>>>> Registereintrag: Amtsgericht Stuttgart, HRB 382295 >>>>>>>>>>> Geschäftsleitung: Jens Joachim, Ralf Joachim >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>> --------------------------------------------------------------------- >>>>>>>>>>> To unsubscribe from this list, please visit: >>>>>>>>>>> >>>>>>>>>>> http://xircles.codehaus.org/manage_email >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> --------------------------------------------------------------------- >>>>>>>>> To unsubscribe from this list, please visit: >>>>>>>>> >>>>>>>>> http://xircles.codehaus.org/manage_email >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> --------------------------------------------------------------------- >>>>>>> To unsubscribe from this list, please visit: >>>>>>> >>>>>>> http://xircles.codehaus.org/manage_email >>>>>>> >>>>>>> >>>>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe from this list, please visit: >>>>> >>>>> http://xircles.codehaus.org/manage_email >>>>> >>>>> >>>>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >>> >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

