You are viewing a plain text version of this content. The canonical link for it is here.
Posted to graffito-dev@incubator.apache.org by Dan Connelly <ds...@adelphia.net> on 2006/09/02 09:50:38 UTC

ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

I want to use a custom collectionConverter, MyCollectionConverterImpl.

That collectionConverter can decide what to do with "unsupported" 
collections from my *given* object model.   (Object model cannot be 
changed.)    In particular, MyCollectionConverterImpl will wrap  an 
unsupported collection as a ManageableCollection and delegate its work 
to a standard collection converter.  

The collection type is discovered by reflection in the objectConverter, 
so it cannot be coerced in the ocm mapping.

Unfortunately, the default objectConverter invokes its own wrapping 
tool, ManageableCollectionUtil, just before the call to insertCollection 
in the custom collectionConverter.     ManageableCollectionUtil will 
throw an exception before the custom collectionConverter gets its chance 
to wrap the unsupported collection type.     The call to 
insertCollection in the custom collectionConverter is never invoked.

A workaround would be to over-ride method insertCollectionFields using a 
custom objectConverter.   However, this method  is private in the 
standard objectConverter.  Thus the method work cannot be delegated.   
Code would need to be copied into the custom objectConverter.   Not 
good.   But even if this method was public and code copying was not 
needed, the object converter is not the right place for collection 
conversions.

Why not make the collectionConverters responsible for throwing an 
exception on (truly) unsupported collection types?  

Don't throw this exception from ManageableCollectionUtil.   Just leave 
an "unsupported" collection type alone there and let the 
collectionConverter deal with any unsupported collection type that may 
be given to it.

       -- Dan



Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
https://issues.apache.org/jira/browse/GRFT-99

Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Christophe Lombart <ch...@gmail.com>.
On 9/4/06, Dan Connelly <ds...@adelphia.net> wrote:
> Christophe:
>
> Please excuse me.   I really am creating too many red herrings, however
> interesting!    This problem is not at all as difficult as I am making it.
>
> There is an extremely general fix for the "unsupported" problem in
> ManageableCollectionUtil.
>
> As I should have considered, EList is a  java.util.Collection.   (And so
> it java.util.List.)  So its all very general.    The problem is that the
> *object* converter method in ManageableCollectionUtil applies a very
> restrictive test:  object.getClass().equals(Collection.class)
>
> I think this can be generalized so it will almost never throw unsupported.
>
> Why not add a general "catchall" test such as this, at the end of the
> other tests in the *object* getManageableCollection method:
>
>             if (object instanceof Collection) {
>                 return new ManageableCollectionImpl((Collection)object);
>             }
>
> where ManageableCollectionImpl is a simple delegating wrapper for *any*
> Collection (or is a ManageableArrayList when the no-arg constructor is
> used)?
>

Why not let me thinking about that. Can you create a JIRA issue ? Thanks



> A similar fix for the *class* converter method is a bit trickier since
> all superinterfaces of the presented class need to be examined for the
> most specific fit (to avoid the delegation if possible).
>
>        -- Dan
>


-- 
Best regards,

Christophe

Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
Christophe:

Please excuse me.   I really am creating too many red herrings, however 
interesting!    This problem is not at all as difficult as I am making it.

There is an extremely general fix for the "unsupported" problem in 
ManageableCollectionUtil.

As I should have considered, EList is a  java.util.Collection.   (And so 
it java.util.List.)  So its all very general.    The problem is that the 
*object* converter method in ManageableCollectionUtil applies a very 
restrictive test:  object.getClass().equals(Collection.class)

I think this can be generalized so it will almost never throw unsupported.

Why not add a general "catchall" test such as this, at the end of the 
other tests in the *object* getManageableCollection method:

            if (object instanceof Collection) {
                return new ManageableCollectionImpl((Collection)object);
            }

where ManageableCollectionImpl is a simple delegating wrapper for *any* 
Collection (or is a ManageableArrayList when the no-arg constructor is 
used)?

A similar fix for the *class* converter method is a bit trickier since 
all superinterfaces of the presented class need to be examined for the 
most specific fit (to avoid the delegation if possible).

       -- Dan

Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
Christophe

Okay, there is a solution along these lines, now that I think about 
it.   Thanks for forcing a re-think.

My requirement is that all my model code must be generated by Eclipse 
EMF.    I have to work with the code as produced by the standard tooling 
there, without alterations.    The usual generative process gives 
collections the EList interface.    EList is not "well-known".

However, there is also a standard tooling for an EMF coercion into SDO 
(Service Data Objects).     SDO is well-known (in certain circles, at 
least).    Even better, the SDO coercion uses the standard List 
interface for its collections.     So this should work with your 
ManageableCollectionUtil as is (but I haven't tried yet).

For SDO, see Apache Incubator project Tuscany.    
http://incubator.apache.org/projects/tuscany.html

See also JSR-235.   http://www.jcp.org/en/jsr/detail?id=235

An SDO DataObject is quite similar to a JCR Node.    The SDO->JCR 
mapping is well worth pursuing.   It imposes only a slight restriction 
on my generative process..

I will give it a try and report back.    I will start a new thread for 
the SDO outcome (or problems).

       -- Dan



Christophe Lombart wrote:

> Dan,
>
> I'm sorry but I don't understand what you are doing.
> If you need to support another kind of collection (or Map), there are
> 2 alternatives :
> 1/ Build your own ManageableCollection and reference this class in the
> mapping file.
> 2/ or promote this class into the ManageableCollectionUtil (if this is
> a generic/well know collection or map).
>
> Please, let me know why it is not possible to create a simple
> ManageableCollection ?
> In therory, you should know modify the code managing the collections
> inside the framework.
>
> Thanks,
> Christophe
>
>
> On 9/4/06, Alexandru Popescu <th...@gmail.com> wrote:
>
>> On 9/4/06, Dan Connelly <ds...@adelphia.net> wrote:
>> > What I ended up doing for this problem, to avoid the exception, was to
>> > make a local modification in ManageableCollectionUtil.    It still
>> > throws the exception (if needed) but my specialized list collection
>> > class is now easily coerced to a ManageableCollection with my
>> > replacement code.
>> >
>> > This is a hack, but a much smaller hack than trying to specialize 
>> either
>> > the objectConverter or the collectionConverter to do the wrapping.
>> >
>> > I would like to see the CollectionConverter interface extended with a
>> > method:
>> >  private  ManageableCollectionFactory  
>> getManageableCollectionFactory()
>> >  such that the ManageableCollectionFactory class would be used in much
>> > the same way that ManageableCollectionUtil is ued.
>> >
>> > The ManageableCollectionFactory would continue to throw the
>> > "unsupported" JcrMapping exception (if needed), but presumably would
>> > wrap all of the application's collection classes correctly.
>> >
>> >
>>
>> I haven't liked the fact that the framework is using this factory like
>> class to handle collections, but haven't got the time and energy nor
>> the time to refactor it. A good refactoring patch would be pretty
>> welcome.
>>
>> ./alex
>> -- 
>> .w( the_mindstorm )p.
>>
>> >
>> > Dan Connelly wrote:
>> >
>> > > I want to use a custom collectionConverter, 
>> MyCollectionConverterImpl.
>> > >
>> > > That collectionConverter can decide what to do with "unsupported"
>> > > collections from my *given* object model.   (Object model cannot be
>> > > changed.)    In particular, MyCollectionConverterImpl will wrap  an
>> > > unsupported collection as a ManageableCollection and delegate its 
>> work
>> > > to a standard collection converter.
>> > > The collection type is discovered by reflection in the
>> > > objectConverter, so it cannot be coerced in the ocm mapping.
>> > >
>> > > Unfortunately, the default objectConverter invokes its own wrapping
>> > > tool, ManageableCollectionUtil, just before the call to
>> > > insertCollection in the custom collectionConverter.
>> > > ManageableCollectionUtil will throw an exception before the custom
>> > > collectionConverter gets its chance to wrap the unsupported 
>> collection
>> > > type.     The call to insertCollection in the custom
>> > > collectionConverter is never invoked.
>> > >
>> > > A workaround would be to over-ride method insertCollectionFields 
>> using
>> > > a custom objectConverter.   However, this method  is private in the
>> > > standard objectConverter.  Thus the method work cannot be delegated.
>> > > Code would need to be copied into the custom objectConverter.   Not
>> > > good.   But even if this method was public and code copying was not
>> > > needed, the object converter is not the right place for collection
>> > > conversions.
>> > >
>> > > Why not make the collectionConverters responsible for throwing an
>> > > exception on (truly) unsupported collection types?
>> > > Don't throw this exception from ManageableCollectionUtil.   Just 
>> leave
>> > > an "unsupported" collection type alone there and let the
>> > > collectionConverter deal with any unsupported collection type 
>> that may
>> > > be given to it.
>> > >
>> > >       -- Dan
>> > >
>> > >
>> > >
>> >
>> >
>>
>
>


Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Christophe Lombart <ch...@gmail.com>.
Dan,

I'm sorry but I don't understand what you are doing.
If you need to support another kind of collection (or Map), there are
2 alternatives :
1/ Build your own ManageableCollection and reference this class in the
mapping file.
2/ or promote this class into the ManageableCollectionUtil (if this is
a generic/well know collection or map).

Please, let me know why it is not possible to create a simple
ManageableCollection ?
In therory, you should know modify the code managing the collections
inside the framework.

Thanks,
Christophe


On 9/4/06, Alexandru Popescu <th...@gmail.com> wrote:
> On 9/4/06, Dan Connelly <ds...@adelphia.net> wrote:
> > What I ended up doing for this problem, to avoid the exception, was to
> > make a local modification in ManageableCollectionUtil.    It still
> > throws the exception (if needed) but my specialized list collection
> > class is now easily coerced to a ManageableCollection with my
> > replacement code.
> >
> > This is a hack, but a much smaller hack than trying to specialize either
> > the objectConverter or the collectionConverter to do the wrapping.
> >
> > I would like to see the CollectionConverter interface extended with a
> > method:
> >  private  ManageableCollectionFactory  getManageableCollectionFactory()
> >  such that the ManageableCollectionFactory class would be used in much
> > the same way that ManageableCollectionUtil is ued.
> >
> > The ManageableCollectionFactory would continue to throw the
> > "unsupported" JcrMapping exception (if needed), but presumably would
> > wrap all of the application's collection classes correctly.
> >
> >
>
> I haven't liked the fact that the framework is using this factory like
> class to handle collections, but haven't got the time and energy nor
> the time to refactor it. A good refactoring patch would be pretty
> welcome.
>
> ./alex
> --
> .w( the_mindstorm )p.
>
> >
> > Dan Connelly wrote:
> >
> > > I want to use a custom collectionConverter, MyCollectionConverterImpl.
> > >
> > > That collectionConverter can decide what to do with "unsupported"
> > > collections from my *given* object model.   (Object model cannot be
> > > changed.)    In particular, MyCollectionConverterImpl will wrap  an
> > > unsupported collection as a ManageableCollection and delegate its work
> > > to a standard collection converter.
> > > The collection type is discovered by reflection in the
> > > objectConverter, so it cannot be coerced in the ocm mapping.
> > >
> > > Unfortunately, the default objectConverter invokes its own wrapping
> > > tool, ManageableCollectionUtil, just before the call to
> > > insertCollection in the custom collectionConverter.
> > > ManageableCollectionUtil will throw an exception before the custom
> > > collectionConverter gets its chance to wrap the unsupported collection
> > > type.     The call to insertCollection in the custom
> > > collectionConverter is never invoked.
> > >
> > > A workaround would be to over-ride method insertCollectionFields using
> > > a custom objectConverter.   However, this method  is private in the
> > > standard objectConverter.  Thus the method work cannot be delegated.
> > > Code would need to be copied into the custom objectConverter.   Not
> > > good.   But even if this method was public and code copying was not
> > > needed, the object converter is not the right place for collection
> > > conversions.
> > >
> > > Why not make the collectionConverters responsible for throwing an
> > > exception on (truly) unsupported collection types?
> > > Don't throw this exception from ManageableCollectionUtil.   Just leave
> > > an "unsupported" collection type alone there and let the
> > > collectionConverter deal with any unsupported collection type that may
> > > be given to it.
> > >
> > >       -- Dan
> > >
> > >
> > >
> >
> >
>


-- 
Best regards,

Christophe

Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Alexandru Popescu <th...@gmail.com>.
On 9/4/06, Dan Connelly <ds...@adelphia.net> wrote:
> What I ended up doing for this problem, to avoid the exception, was to
> make a local modification in ManageableCollectionUtil.    It still
> throws the exception (if needed) but my specialized list collection
> class is now easily coerced to a ManageableCollection with my
> replacement code.
>
> This is a hack, but a much smaller hack than trying to specialize either
> the objectConverter or the collectionConverter to do the wrapping.
>
> I would like to see the CollectionConverter interface extended with a
> method:
>  private  ManageableCollectionFactory  getManageableCollectionFactory()
>  such that the ManageableCollectionFactory class would be used in much
> the same way that ManageableCollectionUtil is ued.
>
> The ManageableCollectionFactory would continue to throw the
> "unsupported" JcrMapping exception (if needed), but presumably would
> wrap all of the application's collection classes correctly.
>
>

I haven't liked the fact that the framework is using this factory like
class to handle collections, but haven't got the time and energy nor
the time to refactor it. A good refactoring patch would be pretty
welcome.

./alex
--
.w( the_mindstorm )p.

>
> Dan Connelly wrote:
>
> > I want to use a custom collectionConverter, MyCollectionConverterImpl.
> >
> > That collectionConverter can decide what to do with "unsupported"
> > collections from my *given* object model.   (Object model cannot be
> > changed.)    In particular, MyCollectionConverterImpl will wrap  an
> > unsupported collection as a ManageableCollection and delegate its work
> > to a standard collection converter.
> > The collection type is discovered by reflection in the
> > objectConverter, so it cannot be coerced in the ocm mapping.
> >
> > Unfortunately, the default objectConverter invokes its own wrapping
> > tool, ManageableCollectionUtil, just before the call to
> > insertCollection in the custom collectionConverter.
> > ManageableCollectionUtil will throw an exception before the custom
> > collectionConverter gets its chance to wrap the unsupported collection
> > type.     The call to insertCollection in the custom
> > collectionConverter is never invoked.
> >
> > A workaround would be to over-ride method insertCollectionFields using
> > a custom objectConverter.   However, this method  is private in the
> > standard objectConverter.  Thus the method work cannot be delegated.
> > Code would need to be copied into the custom objectConverter.   Not
> > good.   But even if this method was public and code copying was not
> > needed, the object converter is not the right place for collection
> > conversions.
> >
> > Why not make the collectionConverters responsible for throwing an
> > exception on (truly) unsupported collection types?
> > Don't throw this exception from ManageableCollectionUtil.   Just leave
> > an "unsupported" collection type alone there and let the
> > collectionConverter deal with any unsupported collection type that may
> > be given to it.
> >
> >       -- Dan
> >
> >
> >
>
>

Re: ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
What I ended up doing for this problem, to avoid the exception, was to 
make a local modification in ManageableCollectionUtil.    It still 
throws the exception (if needed) but my specialized list collection 
class is now easily coerced to a ManageableCollection with my 
replacement code.

This is a hack, but a much smaller hack than trying to specialize either 
the objectConverter or the collectionConverter to do the wrapping.

I would like to see the CollectionConverter interface extended with a 
method:
 private  ManageableCollectionFactory  getManageableCollectionFactory()
 such that the ManageableCollectionFactory class would be used in much 
the same way that ManageableCollectionUtil is ued.

The ManageableCollectionFactory would continue to throw the 
"unsupported" JcrMapping exception (if needed), but presumably would 
wrap all of the application's collection classes correctly.



Dan Connelly wrote:

> I want to use a custom collectionConverter, MyCollectionConverterImpl.
>
> That collectionConverter can decide what to do with "unsupported" 
> collections from my *given* object model.   (Object model cannot be 
> changed.)    In particular, MyCollectionConverterImpl will wrap  an 
> unsupported collection as a ManageableCollection and delegate its work 
> to a standard collection converter. 
> The collection type is discovered by reflection in the 
> objectConverter, so it cannot be coerced in the ocm mapping.
>
> Unfortunately, the default objectConverter invokes its own wrapping 
> tool, ManageableCollectionUtil, just before the call to 
> insertCollection in the custom collectionConverter.     
> ManageableCollectionUtil will throw an exception before the custom 
> collectionConverter gets its chance to wrap the unsupported collection 
> type.     The call to insertCollection in the custom 
> collectionConverter is never invoked.
>
> A workaround would be to over-ride method insertCollectionFields using 
> a custom objectConverter.   However, this method  is private in the 
> standard objectConverter.  Thus the method work cannot be delegated.   
> Code would need to be copied into the custom objectConverter.   Not 
> good.   But even if this method was public and code copying was not 
> needed, the object converter is not the right place for collection 
> conversions.
>
> Why not make the collectionConverters responsible for throwing an 
> exception on (truly) unsupported collection types? 
> Don't throw this exception from ManageableCollectionUtil.   Just leave 
> an "unsupported" collection type alone there and let the 
> collectionConverter deal with any unsupported collection type that may 
> be given to it.
>
>       -- Dan
>
>
>


Re: DON'T IGNORE ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
Hmmm.   That didn't work either.   There really is no good way to do 
this except to copy code from ObjectConverterImpl into 
MyObjectConverterImpl where I can hack my ManageableCollection wrapper 
for collection types I need to support.    I also needed to make 2 
methods public in ObjectConverterImpl.   Ugh.    


Dan Connelly wrote:

> Oops.   This is problem is solved fairly easily by over-riding the 
> getCollection method.    (But, it is a bit tricky there to search the 
> type hierarchy of the Class collectionFieldClass to determine the 
> wrapper to use.)
>
> Sorry for posting half-baked my problems and solutions.   (But my 
> fumbling is a case-study on why the "Advanced Mapping Strategy" pages 
> need to be completed.)
>
>
> Dan Connelly wrote:
>
>> I want to use a custom collectionConverter, MyCollectionConverterImpl.
>>
>> That collectionConverter can decide what to do with "unsupported" 
>> collections from my *given* object model.   (Object model cannot be 
>> changed.)    In particular, MyCollectionConverterImpl will wrap  an 
>> unsupported collection as a ManageableCollection and delegate its 
>> work to a standard collection converter. The collection type is 
>> discovered by reflection in the objectConverter, so it cannot be 
>> coerced in the ocm mapping.
>>
>> Unfortunately, the default objectConverter invokes its own wrapping 
>> tool, ManageableCollectionUtil, just before the call to 
>> insertCollection in the custom collectionConverter.     
>> ManageableCollectionUtil will throw an exception before the custom 
>> collectionConverter gets its chance to wrap the unsupported 
>> collection type.     The call to insertCollection in the custom 
>> collectionConverter is never invoked.
>>
>> A workaround would be to over-ride method insertCollectionFields 
>> using a custom objectConverter.   However, this method  is private in 
>> the standard objectConverter.  Thus the method work cannot be 
>> delegated.   Code would need to be copied into the custom 
>> objectConverter.   Not good.   But even if this method was public and 
>> code copying was not needed, the object converter is not the right 
>> place for collection conversions.
>>
>> Why not make the collectionConverters responsible for throwing an 
>> exception on (truly) unsupported collection types? Don't throw this 
>> exception from ManageableCollectionUtil.   Just leave an 
>> "unsupported" collection type alone there and let the 
>> collectionConverter deal with any unsupported collection type that 
>> may be given to it.
>>
>>       -- Dan
>>
>>
>>
>
>


Re: IGNORE ManageableCollectionUtil should not throw "unsupported" JcrMapping exception.

Posted by Dan Connelly <ds...@adelphia.net>.
Oops.   This is problem is solved fairly easily by over-riding the 
getCollection method.    (But, it is a bit tricky there to search the 
type hierarchy of the Class collectionFieldClass to determine the 
wrapper to use.)

Sorry for posting half-baked my problems and solutions.   (But my 
fumbling is a case-study on why the "Advanced Mapping Strategy" pages 
need to be completed.)


Dan Connelly wrote:

> I want to use a custom collectionConverter, MyCollectionConverterImpl.
>
> That collectionConverter can decide what to do with "unsupported" 
> collections from my *given* object model.   (Object model cannot be 
> changed.)    In particular, MyCollectionConverterImpl will wrap  an 
> unsupported collection as a ManageableCollection and delegate its work 
> to a standard collection converter. 
> The collection type is discovered by reflection in the 
> objectConverter, so it cannot be coerced in the ocm mapping.
>
> Unfortunately, the default objectConverter invokes its own wrapping 
> tool, ManageableCollectionUtil, just before the call to 
> insertCollection in the custom collectionConverter.     
> ManageableCollectionUtil will throw an exception before the custom 
> collectionConverter gets its chance to wrap the unsupported collection 
> type.     The call to insertCollection in the custom 
> collectionConverter is never invoked.
>
> A workaround would be to over-ride method insertCollectionFields using 
> a custom objectConverter.   However, this method  is private in the 
> standard objectConverter.  Thus the method work cannot be delegated.   
> Code would need to be copied into the custom objectConverter.   Not 
> good.   But even if this method was public and code copying was not 
> needed, the object converter is not the right place for collection 
> conversions.
>
> Why not make the collectionConverters responsible for throwing an 
> exception on (truly) unsupported collection types? 
> Don't throw this exception from ManageableCollectionUtil.   Just leave 
> an "unsupported" collection type alone there and let the 
> collectionConverter deal with any unsupported collection type that may 
> be given to it.
>
>       -- Dan
>
>
>