Sorry, I'm having real trouble mapping this class structure. I have pasted the source
for the
class file at the end of my reply.
It seems that with no mapping file at all (default un/marshall), the class instance
can be
marshalled, but has problems being unmarshalled...
"org.xml.sax.SAXException: The class for the root element 'person' could not be found."
When a mapping file is provided, everything works fine if there are no cyclic
references in the
object graph. When there are cyclic references, I just can't seem to get the instance
marshalled/unmarshalled. Ideally, I would like the "best-friend" and "friend" elements
to be
idrefs if they need to be references or ids if this is the first time the object has
been
encountered.
import java.util.List;
import java.util.ArrayList;
public class Person
{
protected String firstName = null;
protected String lastName = null;
protected Person bestFriend = null;
protected List friends = null;
public Person()
{
super();
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getFirstName()
{
return this.firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getLastName()
{
return this.lastName;
}
public void setBestFriend(Person bestFriend)
{
this.bestFriend = bestFriend;
}
public Person getBestFriend()
{
return this.bestFriend;
}
public void setFriends(List friends)
{
this.friends = friends;
}
public void addFriend(Person friend)
{
if (this.friends == null)
{
this.friends = new ArrayList();
}
this.friends.add(friend);
}
public void addFriends(List friends)
{
if (this.friends == null)
{
this.friends = new ArrayList(friends);
}
else
{
this.friends.addAll(friends);
}
}
public List getFriends()
{
return this.friends;
}
}
--- Keith Visco <[EMAIL PROTECTED]> wrote:
>
> Castor can't handle the case when you want only 1 of the fields to be an
> idref but all the other ones to be full elements.
>
> The following should work to get your idref to be output, but all
> friends will be output as IDREF.
>
> <class name="Person" identity="id">
> <field name="friend" type="Person" reference="true">
> <bind-xml location="friend" name="idref" node="attribute"/>
> </field>
> </class>
>
> --Keith
>
>
> Spam Cut wrote:
> >
> > Is there anyway to currently deal with cyclic object graphs within Castor XML? For
> > example...
> >
> > ...
> > Person person = new Person();
> > person.addFriend(otherPerson1);
> > person.addFriend(otherPerson2);
> >
> > // And I'm my own friend...
> > person.addFriend(person);
> > ...
> >
> > <person id="1">
> > <friend id="2">
> > ...
> > </friend>
> > <friend id="3">
> > ...
> > </friend>
> > <friend idref="1"/>
> > </person>
> >
> > =====
> > [EMAIL PROTECTED]
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
> > http://calendar.yahoo.com
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
=====
[EMAIL PROTECTED]
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev