On Mon, 21 Mar 2005 09:53:50 -0500, Jeremy Haile <[EMAIL PROTECTED]> wrote: > > Is there any way to reference an object by ID, but only have Castor > create the reference for a particular class. > > For example: > > <basketOfApples> > <apple>myFruit</apple> > </basketOfApples> > > <basketOfPears> > <pear>myFruit</pear> > </basketOfPears> > > <apple name="myFruit"/> > <pear name="myFruit"/> > > The subelements in the baskets are mapped as references and the "name" > attributes of the fruit would be mapped as the Castor "id". > > In Castor 0.9.5.3, this would cause a serious problem. Even though it > is obvious to a reader that the basket of apples should be referencing > the <apple> element, Castor treats all IDs as global XML ids. This > means that Castor does not know whether the pear referenced in the > basket of pears is the apple or the pear. It seems like it would be > easy to allow castor to differentiate IDs based on the class type, since > we know what class type the references are referring to. > > In our application, we use Castor to export and import many different > types of objects to and from XML files. A lot of the XML IDs can be > user-entered at runtime. It is impossible (and/or unintuitive) for us > to enforce that two of those identifiers cannot be the same, when they > are two completely separate datatypes/classes. > > If I have an Apple property in my class which is mapped as a Castor > reference "private Apple apple;", it doesn't make any sense for Castor > to try and call setApple( Apple apple ) with an object of type Pear, so > shouldn't the referencing infrastructure take this into account? > > Has any support been added for this? Is any planned? What amount of > effort would be involved in adding this support?
Jeremy, Castor XML supports the use of the ID and IDREF XML Schema types. But remember that XML/XML Schema requires that IDs must be unique within the document: http://www.w3.org/TR/2000/WD-xml-2e-20000814#id So the use of myFruit in your example above is not a valid identifier. Castor XML is simply enforcing the rules set forth by XML and XML Schema. I have actually used the ID/IDREF types with Castor XML and they do work correctly. Bruce -- perl -e 'print unpack("u30","D0G)[EMAIL PROTECTED]&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*" );' The Castor Project http://www.castor.org/ Apache Geronimo http://geronimo.apache.org/ ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev