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/12 20:09:08 UTC
Why doesn't OjbectConverter getObject call this.newInstance method
?
All:
I do a pm.save 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
Re: Why doesn't OjbectConverter getObject call this.newInstance method ?
Posted by Christophe Lombart <ch...@gmail.com>.
Thanks - I will review it when it will be in Jira.
br
Christophe
On 9/13/06, Dan Connelly <ds...@adelphia.net> wrote:
> All:
>
> 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
>
> this.newInstance(classDescriptor.getClassName());
>
> where previously the invocation had been
>
> ReflectionUtils.newInstance(classDescriptor.getClassName());
>
> 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
> ObjectConvertImpl.
>
> -- Dan
>
>
>
>
>
>
> Dan Connelly wrote:
>
> > All:
> >
> > I do a pm.save 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
> >
> >
> >
> >
>
>
--
Best regards,
Christophe
Re: Why doesn't OjbectConverter getObject call this.newInstance method
?
Posted by Dan Connelly <ds...@adelphia.net>.
All:
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
this.newInstance(classDescriptor.getClassName());
where previously the invocation had been
ReflectionUtils.newInstance(classDescriptor.getClassName());
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
ObjectConvertImpl.
-- Dan
Dan Connelly wrote:
> All:
>
> I do a pm.save 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
>
>
>
>