Title: RE: RE : No query engine found

Hi Ole,

This is an interesting problem. I am not sure what kind of reordering you need to do, but here is a chunk of code that swaps two elements of the array, hopefully it will be useful:

 

FooType[] array = t.getFooArray(); // array.length == 4

FooType f = (FooType) array[3].copy(); // you need to do a copy here, otherwise the next statement will obliterate array[3]

t.setFooArray(3, array[1]);

t.setFooArray(1, f);

 

You do need to make three copies, but at least you do not need to “disturb” the other elements in the array.

In any case, experiment with setArray() and insertNew() to minimize the number of objects that will get invalidated. There are no generated methods targeted specifically at changing the order of elements in an array.

 

Radu

 

-----Original Message-----
From: Ole Matzura [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 11, 2005 12:18 PM
To: [email protected]
Subject: Reordering array problem

 

Hi all!

 

I'm trying to change the order of the items in an array generated for an unbounded element of a complex type in my schema... ie my schema contains

 

<sequence>

<element name="Foo" type="tns:FooType" minOccurs="0" maxOccurs="unbounded"/>

</sequence>

 

and the XmlBeans object for the containing complex type thus has the standard setFooArray methods..

 

My problem arises when I want to reorder the array without loosing the existing FooType instances in the array; if I first get the entire array using getFooArray(), reorder it, and then try to set the array with setFooArray( FooType[] ), XmlBeans seems to create a new array of FooType objects which are copies of the ones specified.. my problem arises from the fact that I have bound POJOS to the existing FooType objects, which are suddenly invalidated as "their" FooType objects are no longer valid..

 

I've tries using the XmlCuror.moveXml methods instead; they correctly reorder the underlying xml, but the FooType objects bound to the xml elements are not moved in the array and become invalidated as well..

 

So my only option seems to be to recreate my pojos with the new xmlobjects generated when setting the new array as described above.. maybe/hopefully there is a better way though? anybody?

 

any help is greatly appreciated!

 

regards!

 

/Ole


 

Reply via email to