You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Holger Haag <ja...@herr-der-mails.de> on 2006/05/11 14:22:29 UTC

[betwixt] Betwixt mapping of generic lists with instances of an interface

Hi all,

I'm trying to figure out how (or if) it is possible to handle lists
containing instances of an interface.

Sample:

// the interface
public interface MyInterface {
  ..
}

// an implementation
public class MyImpl1 implements MyInterface {
  ..
}

// an implementation
public class MyImpl2 implements MyInterface {
  ..
}

// the list containing instances of MyInterface
public class MyList extends java.util.List<MyInterface> {
  ..
}


A serialized sample should look like the following

<list>
  <!-- serialized instance of MyImpl1 -->
  <impl1>
  </impl1>
  
  <!-- serialized instance of MyImpl2 -->
  <impl2>
  </impl2>
  
  <!-- serialized instance of MyImpl1 -->
  <impl1>
  </impl1>
</list>


I think this is currently not possible via betwixt (pls. correct me if I am
wrong) 
since all list items will be named "myinterface" or so thus loosing the
proper type information.


I could of course build an XML as follows:

<list>
  <item type="myimpl1">
  </item>
  <item type="myimpl2">
  </item>
  <item type="myimpl1">
  </item>
</list>


But this way I have difficulties in defining a nice XSD file for the
generated XML. 
So I'd rather name the nodes properly as outlined in the first XML sample.

So the question boils down to how to setup polymorphic mapping for generic
lists. 
http://jakarta.apache.org/commons/betwixt/guide/reading.html only details
how to do this for a container, but nothing about lists/collections.


Any help is greatly appreciated

-- 
Echte DSL-Flatrate dauerhaft f�r 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [betwixt] Betwixt mapping of generic lists with instances of an interface

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
i've committed a change in the default mapping for lists. please build
from the latest code. i've updated the website with some documentation
but it'll take a while to sync and you may be better looking at the unit
tests. see src/test/org/apache/commons/betwixt/poly/TestPolyList.java.

- robert

On Wed, 2006-05-17 at 22:21 +0100, robert burrell donkin wrote:
> On Thu, 2006-05-11 at 14:22 +0200, Holger Haag wrote:
> > Hi all,
> > 
> > I'm trying to figure out how (or if) it is possible to handle lists
> > containing instances of an interface.
> > 
> > Sample:
> > 
> > // the interface
> > public interface MyInterface {
> >   ..
> > }
> > 
> > // an implementation
> > public class MyImpl1 implements MyInterface {
> >   ..
> > }
> > 
> > // an implementation
> > public class MyImpl2 implements MyInterface {
> >   ..
> > }
> > 
> > // the list containing instances of MyInterface
> > public class MyList extends java.util.List<MyInterface> {
> >   ..
> > }
> > 
> > 
> > A serialized sample should look like the following
> > 
> > <list>
> >   <!-- serialized instance of MyImpl1 -->
> >   <impl1>
> >   </impl1>
> >   
> >   <!-- serialized instance of MyImpl2 -->
> >   <impl2>
> >   </impl2>
> >   
> >   <!-- serialized instance of MyImpl1 -->
> >   <impl1>
> >   </impl1>
> > </list>
> > 
> > 
> > I think this is currently not possible via betwixt (pls. correct me if I am
> > wrong) 
> > since all list items will be named "myinterface" or so thus loosing the
> > proper type information.
> 
> <snip>
> 
> > So the question boils down to how to setup polymorphic mapping for generic
> > lists. 
> > http://jakarta.apache.org/commons/betwixt/guide/reading.html only details
> > how to do this for a container, but nothing about lists/collections.
> 
> there are two parts to this problem: the first is configuring
> polymorphic mappings so that the reading works. the second is persuading
> betwixt to write the right names. it's easiest to attack them
> separately.
> 
> the documentation should give a reasonable description about how to
> setup the multi mapping so that the reading works. 
> 
> the second problem is covered in
> http://jakarta.apache.org/commons/betwixt/guide/derived.html. you may
> need to switch mapping derivation to introspection time. 
> 
> the only wrinkle is that it might be difficult to configure a list
> (rather than a container). i'm not ATM whether this will be a problem or
> not. i'll try to find time tomorrow to try this out.
> 
> - robert
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [betwixt] Betwixt mapping of generic lists with instances of an interface

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Thu, 2006-05-11 at 14:22 +0200, Holger Haag wrote:
> Hi all,
> 
> I'm trying to figure out how (or if) it is possible to handle lists
> containing instances of an interface.
> 
> Sample:
> 
> // the interface
> public interface MyInterface {
>   ..
> }
> 
> // an implementation
> public class MyImpl1 implements MyInterface {
>   ..
> }
> 
> // an implementation
> public class MyImpl2 implements MyInterface {
>   ..
> }
> 
> // the list containing instances of MyInterface
> public class MyList extends java.util.List<MyInterface> {
>   ..
> }
> 
> 
> A serialized sample should look like the following
> 
> <list>
>   <!-- serialized instance of MyImpl1 -->
>   <impl1>
>   </impl1>
>   
>   <!-- serialized instance of MyImpl2 -->
>   <impl2>
>   </impl2>
>   
>   <!-- serialized instance of MyImpl1 -->
>   <impl1>
>   </impl1>
> </list>
> 
> 
> I think this is currently not possible via betwixt (pls. correct me if I am
> wrong) 
> since all list items will be named "myinterface" or so thus loosing the
> proper type information.

<snip>

> So the question boils down to how to setup polymorphic mapping for generic
> lists. 
> http://jakarta.apache.org/commons/betwixt/guide/reading.html only details
> how to do this for a container, but nothing about lists/collections.

there are two parts to this problem: the first is configuring
polymorphic mappings so that the reading works. the second is persuading
betwixt to write the right names. it's easiest to attack them
separately.

the documentation should give a reasonable description about how to
setup the multi mapping so that the reading works. 

the second problem is covered in
http://jakarta.apache.org/commons/betwixt/guide/derived.html. you may
need to switch mapping derivation to introspection time. 

the only wrinkle is that it might be difficult to configure a list
(rather than a container). i'm not ATM whether this will be a problem or
not. i'll try to find time tomorrow to try this out.

- robert



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org