incubator-graffito-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Connelly <>
Subject Re: Why doesn't OjbectConverter getObject call this.newInstance method ?
Date Wed, 13 Sep 2006 00:58:14 GMT

I implemented a simple change in ObjectConverterImpl.   It solves the 
problem I reported.

I added the following method:

    protected Object newInstance(String className) {
        return ReflectionUtils.newInstance(className);

Elsewhere in ObjectConverterImpl, it will now invoke


where previously the invocation had been


Now I can over-ride the newInstance in MyObjectConverterImpl (which 
subclasses ObjectConverterImpl).   This allows me to construct objects 
for my model using its factory class.

I will submit an enhancement Jira tomorrow to get this change into 

         -- Dan

Dan Connelly wrote:

> All:
> I do a on the root of my model objects.   Then I want to fetch 
> the object model back using some code like:
>    RootClass root = (RootClass) pm.getObject("/test.root");
> This fails because my model uses a factory class, not constructors, to 
> instantiate model objects, including instances of the RootClass.
> This pm is constructed using my custom MyObjectConverterImpl, which is 
> a subclass of ObjectConverterImpl.   I expected that this would give 
> me a way to control object creation.    It seems that I was wrong 
> (unless I copy major portions of ObjectConverterImpl).
> ObjectConverterImpl, if I delegate getObject to it, attempts to get a 
> root object using this code:
>       Object root = 
> ReflectionUtils.newInstance(classDescriptor.getClassName());
> That causes the failure.   ReflectionUtils is out of my control.   
> ObjectConverterImpl does not invoke *this.newInstance* so that 
> MyObjectConverterImpl can get control back for the construction in my 
> objects (using my factory class).
> What are the plans, if any, are there to accommodate object models 
> which use a factory class for construction of its objects?
>       -- Dan

View raw message