You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jon Scott Stevens <jo...@latchkey.com> on 2002/06/13 02:53:25 UTC

[betwixt] bug: output is in reverse order of input...

Say I have a XML file like this:

<scarab-issues>
  <module>
    <name>
    </name>
  </module>
  <issues>
    <issue>
        <id></id>
    </issue>
  </issues>
</scarab-issues>

If I print the beans out using BeanWriter, I'm getting the output like this:

<scarab-issues>
  <issues>
    <issue>
        <id></id>
    </issue>
  </issues>
  <module>
    <name>
    </name>
  </module>
</scarab-issues>

Clearly not good.

-jon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Jon Scott Stevens" <jo...@latchkey.com>
> on 6/12/02 11:53 PM, "James Strachan" <ja...@yahoo.co.uk> wrote:
>
> > This was done originally by design. The XML introspector decides the
> > ordering of the bean properties. You can configure this order using a
> > BeanInfo. Or you can change this order via a .betwixt file for your
bean.
>
> The output ordering must match the input ordering because generally there
is
> a DTD which defines what the order of the elements is.

Ah you didn't mention the DTD until now. If we have a DTD we can use it for
ordering.


> > The problem with using the input XML document as the decider of the
order of
> > properties, is what happens if lots of different orderings are used in
> > different XML documents (or things are missing)? Which order wins?
>
> I'm sorry. That doesn't make sense to me. You have one input and one
> output...where are you getting this lots of different documents? The
> ordering of the input should match the output exactly

You can have lots of XML documents, each could use different orders for the
properties of your beans. XML is completely free-from without any schema to
restrict it. Without some universal schema you don't know the correct order.
Also note that some schemas don't really care about order of XML anyways.
.
Though now you've mentioned the DTD, we could probably use it to order the
XMLBeanInfo fairly easily.

> > Though I do concur, it might be nice to let the parsing of XML order the
> > XMLBeanInfo automatically as it seems like a common use case. The way
the
> > ordering works right now is not ideal. I've added this issue to the
> > todo.xml.
>
> Thanks...because until this is fixed, I can't use betwixt for anything
> useful.

I understand that preserving the input order would be nice. Also its very
easy to create a little .betwixt file to explicitly set the order to
anything you like. How does this 'automatic preservation of order' stop you
from using betwixt for anything useful?

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Jon Scott Stevens" <jo...@latchkey.com>
> on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> wrote:
>
> > it's hard to see how betwixt could automatically guess the ordering
> > without access to the DTD. it might be necessary to create betwixt file
or
> > an XMLBeanInfo class to correctly order the output.
> >
> > - robert
>
> I'm not sure if it is possible to get this information from reflection,
but
> I would be ok with making the ordering the same as the ordering of the
get()
> methods in the class file.

The ordering by default is the same as the order returned by the BeanInfo
returned by the Introspector in java.beans. Unfortunately this bears no
relation to the order in the class file :-(. It does seem to be constant
though :-) I suspect its some hash-order or something.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by Jon Scott Stevens <jo...@latchkey.com>.
on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> wrote:

> it's hard to see how betwixt could automatically guess the ordering
> without access to the DTD. it might be necessary to create betwixt file or
> an XMLBeanInfo class to correctly order the output.
> 
> - robert

I'm not sure if it is possible to get this information from reflection, but
I would be ok with making the ordering the same as the ordering of the get()
methods in the class file.

-jon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Just a thought...could the Comparator class be used to do the sorting? Why
write your own if one exists?

Stephen

----- Original Message -----
From: "robert burrell donkin" <ro...@mac.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, June 15, 2002 11:40 AM
Subject: Re: [betwixt] bug: output is in reverse order of input...


> in terms of default orderings, though i can only think really of one
> implementation (alphabetic) it's probably better design to use an
> interface and give users the choice.
>
> it might not solve jon's problem, though.
>
> users should be able to set the order of the elements by creating .betwixt
> files or XMLBeanInfo classes. the bit that's going to be tricky about
> taking an order from the xml comes from preserving this functionality
> whilst also allowing the element order to be dynamically determined by the
> order in which they are read from the xml.
>
> anyway, i think that better default ordering is something that betwixt
> should be able to do. i'd think that the best approach would be to create
> a general system (probably along the lines you suggest) and then see
> (later) if we can use it for dynamic reordering (if we have to). if you
> want to see what you come up with, i'll keep out of your way.
>
> - robert
>
> On Saturday, June 15, 2002, at 10:37 AM, Martin van den Bemt wrote:
>
> > I was thinking more in the way of solving this issue by creating a
> > couple of XMLOrdering objects, which can be used in a similar way as the
> > NameMapper. I didn't write a use case yet for it, so it's just a mind
> > spin, but this can give the flexibility for people to choose how they
> > want to order it.. (or even write there own ordering).
> >
> > Mvgr,
> > Martin
> >
> > On Sat, 2002-06-15 at 10:40, robert burrell donkin wrote:
> >>
> >> On Thursday, June 13, 2002, at 09:27 PM, Jon Scott Stevens wrote:
> >>
> >>> on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com>
> >>> wrote:
> >>>
> >>>> am i right in assuming that ordering the element automatically from
> >>>> the
> >>>> parsing would only work if the same XMLIntrospector instance is used
> >>>> to
> >>>> read and write?
> >>>
> >>> That is the case right now for me anyway...
> >>
> >> so this is a possible solution.
> >>
> >> it's probably do-able but will be tricky to write and may have
> >> unfortunate
> >> side effects.
> >>
> >>
> >> i was thinking that maybe we should have betwixt order elements by
> >> default
> >> in alphabetic order. at least that way it's obviously deterministic
> >> (since
> >> bean introspection doesn't seem to be) and people who have control of
> >> their own DTDs know how to write them so that they are compatible with
> >> betwixt's defaults.
> >>
> >> i don't know if this would solve your problem...
> >>
> >> - robert
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.
> >> org>
> >> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.
> >> org>
> >>
> >>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.
> > org>
> > For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.
> > org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by robert burrell donkin <ro...@mac.com>.
in terms of default orderings, though i can only think really of one 
implementation (alphabetic) it's probably better design to use an 
interface and give users the choice.

it might not solve jon's problem, though.

users should be able to set the order of the elements by creating .betwixt 
files or XMLBeanInfo classes. the bit that's going to be tricky about 
taking an order from the xml comes from preserving this functionality 
whilst also allowing the element order to be dynamically determined by the 
order in which they are read from the xml.

anyway, i think that better default ordering is something that betwixt 
should be able to do. i'd think that the best approach would be to create 
a general system (probably along the lines you suggest) and then see 
(later) if we can use it for dynamic reordering (if we have to). if you 
want to see what you come up with, i'll keep out of your way.

- robert

On Saturday, June 15, 2002, at 10:37 AM, Martin van den Bemt wrote:

> I was thinking more in the way of solving this issue by creating a
> couple of XMLOrdering objects, which can be used in a similar way as the
> NameMapper. I didn't write a use case yet for it, so it's just a mind
> spin, but this can give the flexibility for people to choose how they
> want to order it.. (or even write there own ordering).
>
> Mvgr,
> Martin
>
> On Sat, 2002-06-15 at 10:40, robert burrell donkin wrote:
>>
>> On Thursday, June 13, 2002, at 09:27 PM, Jon Scott Stevens wrote:
>>
>>> on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> 
>>> wrote:
>>>
>>>> am i right in assuming that ordering the element automatically from 
>>>> the
>>>> parsing would only work if the same XMLIntrospector instance is used 
>>>> to
>>>> read and write?
>>>
>>> That is the case right now for me anyway...
>>
>> so this is a possible solution.
>>
>> it's probably do-able but will be tricky to write and may have 
>> unfortunate
>> side effects.
>>
>>
>> i was thinking that maybe we should have betwixt order elements by 
>> default
>> in alphabetic order. at least that way it's obviously deterministic 
>> (since
>> bean introspection doesn't seem to be) and people who have control of
>> their own DTDs know how to write them so that they are compatible with
>> betwixt's defaults.
>>
>> i don't know if this would solve your problem...
>>
>> - robert
>>
>>
>> --
>> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
>> org>
>> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
>> org>
>>
>>
>
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by Martin van den Bemt <ml...@mvdb.net>.
I was thinking more in the way of solving this issue by creating a
couple of XMLOrdering objects, which can be used in a similar way as the
NameMapper. I didn't write a use case yet for it, so it's just a mind
spin, but this can give the flexibility for people to choose how they
want to order it.. (or even write there own ordering). 

Mvgr,
Martin

On Sat, 2002-06-15 at 10:40, robert burrell donkin wrote:
> 
> On Thursday, June 13, 2002, at 09:27 PM, Jon Scott Stevens wrote:
> 
> > on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> wrote:
> >
> >> am i right in assuming that ordering the element automatically from the
> >> parsing would only work if the same XMLIntrospector instance is used to
> >> read and write?
> >
> > That is the case right now for me anyway...
> 
> so this is a possible solution.
> 
> it's probably do-able but will be tricky to write and may have unfortunate 
> side effects.
> 
> 
> i was thinking that maybe we should have betwixt order elements by default 
> in alphabetic order. at least that way it's obviously deterministic (since 
> bean introspection doesn't seem to be) and people who have control of 
> their own DTDs know how to write them so that they are compatible with 
> betwixt's defaults.
> 
> i don't know if this would solve your problem...
> 
> - robert
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by robert burrell donkin <ro...@mac.com>.
On Thursday, June 13, 2002, at 09:27 PM, Jon Scott Stevens wrote:

> on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> wrote:
>
>> am i right in assuming that ordering the element automatically from the
>> parsing would only work if the same XMLIntrospector instance is used to
>> read and write?
>
> That is the case right now for me anyway...

so this is a possible solution.

it's probably do-able but will be tricky to write and may have unfortunate 
side effects.


i was thinking that maybe we should have betwixt order elements by default 
in alphabetic order. at least that way it's obviously deterministic (since 
bean introspection doesn't seem to be) and people who have control of 
their own DTDs know how to write them so that they are compatible with 
betwixt's defaults.

i don't know if this would solve your problem...

- robert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by Jon Scott Stevens <jo...@latchkey.com>.
on 6/13/02 11:24 AM, "robert burrell donkin" <ro...@mac.com> wrote:

> am i right in assuming that ordering the element automatically from the
> parsing would only work if the same XMLIntrospector instance is used to
> read and write?

That is the case right now for me anyway...

-jon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by robert burrell donkin <ro...@mac.com>.
On Thursday, June 13, 2002, at 06:45 PM, Jon Scott Stevens wrote:

> on 6/12/02 11:53 PM, "James Strachan" <ja...@yahoo.co.uk> wrote:
>
>> This was done originally by design. The XML introspector decides the
>> ordering of the bean properties. You can configure this order using a
>> BeanInfo. Or you can change this order via a .betwixt file for your bean.
>
> The output ordering must match the input ordering because generally there 
> is
> a DTD which defines what the order of the elements is.
>
>> The problem with using the input XML document as the decider of the 
>> order of
>> properties, is what happens if lots of different orderings are used in
>> different XML documents (or things are missing)? Which order wins?
>
> I'm sorry. That doesn't make sense to me. You have one input and one
> output...where are you getting this lots of different documents? The
> ordering of the input should match the output exactly.

i think that the problem boils down to the fact that betwixt has 
traditionally started from the other perspective - you make an output and 
then want to be able to read back from the generated output. it is 
possible (through configuration) for betwixt to produce different xml as 
output from the same beans. the idea is that with the same configuration, 
betwixt should be able to read back the xml and turn it into beans.

>> Though I do concur, it might be nice to let the parsing of XML order the
>> XMLBeanInfo automatically as it seems like a common use case. The way the
>> ordering works right now is not ideal. I've added this issue to the
>> todo.xml.
>
> Thanks...because until this is fixed, I can't use betwixt for anything
> useful.

am i right in assuming that ordering the element automatically from the 
parsing would only work if the same XMLIntrospector instance is used to 
read and write?

it's hard to see how betwixt could automatically guess the ordering 
without access to the DTD. it might be necessary to create betwixt file or 
an XMLBeanInfo class to correctly order the output.

- robert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by Jon Scott Stevens <jo...@latchkey.com>.
on 6/12/02 11:53 PM, "James Strachan" <ja...@yahoo.co.uk> wrote:

> This was done originally by design. The XML introspector decides the
> ordering of the bean properties. You can configure this order using a
> BeanInfo. Or you can change this order via a .betwixt file for your bean.

The output ordering must match the input ordering because generally there is
a DTD which defines what the order of the elements is.

> The problem with using the input XML document as the decider of the order of
> properties, is what happens if lots of different orderings are used in
> different XML documents (or things are missing)? Which order wins?

I'm sorry. That doesn't make sense to me. You have one input and one
output...where are you getting this lots of different documents? The
ordering of the input should match the output exactly.

> Though I do concur, it might be nice to let the parsing of XML order the
> XMLBeanInfo automatically as it seems like a common use case. The way the
> ordering works right now is not ideal. I've added this issue to the
> todo.xml.

Thanks...because until this is fixed, I can't use betwixt for anything
useful.

-jon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] bug: output is in reverse order of input...

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Jon Scott Stevens" <jo...@latchkey.com>
> Say I have a XML file like this:
>
> <scarab-issues>
>   <module>
>     <name>
>     </name>
>   </module>
>   <issues>
>     <issue>
>         <id></id>
>     </issue>
>   </issues>
> </scarab-issues>
>
> If I print the beans out using BeanWriter, I'm getting the output like
this:
>
> <scarab-issues>
>   <issues>
>     <issue>
>         <id></id>
>     </issue>
>   </issues>
>   <module>
>     <name>
>     </name>
>   </module>
> </scarab-issues>
>
> Clearly not good.

This was done originally by design. The XML introspector decides the
ordering of the bean properties. You can configure this order using a
BeanInfo. Or you can change this order via a .betwixt file for your bean.
The problem with using the input XML document as the decider of the order of
properties, is what happens if lots of different orderings are used in
different XML documents (or things are missing)? Which order wins?

Though I do concur, it might be nice to let the parsing of XML order the
XMLBeanInfo automatically as it seems like a common use case. The way the
ordering works right now is not ideal. I've added this issue to the
todo.xml.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>