|
From: Keith D. <kd...@cs...> - 2004-10-22 03:08:10
|
Would the ability to pass dynamic, runtime constructor arguments to a
prototype bean definition be possible?
Here's a case where I felt prototypes usage was inappropriate: =
specifically,
getting a new implementation instance, but adding mutators to the =
returning
interface to support runtime parameterization (that should've been part =
of
the constructor initialization of the implementation.)
Keith
-----Original Message-----
From: Keith Donald [mailto:kd...@cs...]=20
Sent: Thursday, October 21, 2004 11:03 PM
To: 'spr...@li...'
Subject: RE: [Springframework-rcp-dev] Docking window - a few more =
problems
(patch)
Okay I see what you're saying.
After thinking about this, I am against adding post-instantation (one =
time
configuration only) setters to the ApplicationPage interface to support
context-based instantiation of the prototype implementation with a =
default
constructor. This is the Pico in me--I believe such setters should not =
be
part of the public interface.
With that said, I'm willing to compromise. I'll put a default =
constructor
on DefaultApplicationPage. It is protected, but subclasses can extend =
it
with a public variant. DefaultApplicationWindow will then query for the
"applicationPagePrototype" definition and, if it exists, get a new =
instance
and cast it to a DefaultApplicationPage (which has setter mutators.) =
Now,
if you wish not to extend the DefaultApplicationPage class (which you =
must
do to avoid a class cast here), simply override the factory method in
DefaultApplicationWindow to return whatever custom ApplicationPage
implementation you want.
Now if Spring suppors passing dynamic constructor arguments to =
prototypes it
might be a different story. But adding setter mutators to the
ApplicationPage interface is not appropriate--it would be an example of
sacrificing good design for the sake of satisfying the Spring container. =
I
just can't do it. :-(
Keith
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf =
Of
verat
Sent: Friday, October 22, 2004 3:07 AM
To: spr...@li...
Subject: [Springframework-rcp-dev] Docking window - a few more problems
(patch)
Keith,
=A0 I can't implement last changes with ApplicationPage
Problem :
=A0 =A0ApplicationPage haven't empty constructor and I can't add
ApplicationWindow in constructor argument
because 'applicationWindowPrototype' and 'applicationPagePrototype' =
beans
aren't singleton
I define this beans with :
=A0<bean id=3D"applicationWindowPrototype" singleton=3D"false"
=A0
class=3D"org.springframework.richclient.application.support.DefaultApplic=
ation
Window"/>
=A0
=A0<bean id=3D"applicationPagePrototype" singleton=3D"false"
=A0
class=3D"org.springframework.richclient.snpepetclinic.core.IdwApplication=
Page"
/>
createPage method is now :
=A0protected ApplicationPage createPage(ApplicationWindow window,
=A0 =A0 =A0 =A0 =A0 =A0 String pageDescriptorId) {
=A0 =A0 =A0 =A0 ApplicationPageDescriptor descriptor =3D
getPageDescriptor(pageDescriptorId);
=A0 =A0 =A0 =A0 try {
=A0 =A0 =A0 =A0 =A0 =A0 ApplicationPage page =3D
(ApplicationPage)getApplication().getApplicationContext()
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
.getBean(APPLICATION_PAGE_BEAN_ID,
ApplicationPage.class);
=A0 =A0 =A0 =A0 =A0 =A0 page.setApplicationWindow(this);
=A0 =A0 =A0 =A0 =A0 =A0 page.setPageDescriptor(descriptor);
=A0 =A0 =A0 =A0 =A0 =A0 return page;
=A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 catch (NoSuchBeanDefinitionException e) {
=A0 =A0 =A0 =A0 =A0 =A0 return new DefaultApplicationPage(window, =
descriptor);
=A0 =A0 =A0 =A0 }
=A0 =A0 }
I add setApplicationWindow and setPageDescriptor in ApplicationPage
interface and implementation in DefaultApplicationPage
and empty constructor in DefaultApplicationPage
After this inject beans work, but 'create new Window' isn't good because =
I
don't know how I can get current instance active page (or window)
- activeWindow in Application is always first window and I add
windowActivated method in WindowListener for window's control
I need active page instance in OwnerView method when I create form view =
for
double click on owner
I create dynamic view , too and I need method in ApplicationPage
This views can't be defined in xml file because I create view for owner =
with
title - owner name and can't set all owners in xml file
public void showView(String viewName, Icon icon, JComponent component)
This method isn't necessary, but without method I have ugly cast.
In attach are my changes.Please apply=20
Regards
Haris Peco
|