Discussion:
How do I set a property in a class not in my control?
Daniel Hinojosa
2008-05-19 19:13:14 UTC
Permalink
Starting pico container for the first time in a real application. I
just want to set a certain container in a JFrame, but ended up with a
problem in the documentation, getAdapter isn't really a method in a
pico container.
Any idea what the correct method is and why documentation has little
problems here and there?


parent = new PicoBuilder().withCaching().withPropertyApplier().withLifecycle().build();
....
parent.addComponent(JFrame.class);
parent.addComponent("myDesktopPane", DesktopPane.class);
PropertyApplicator pa = (PropertyApplicator) parent.getAdapter(JFrame.class);
pa.setProperty("contentPane", "myDesktopPane");
--
Daniel Hinojosa
Programmer, Instructor, and Consultant

2529 Wisconsin St. NE
Albuquerque, NM 87110
dhinojosa-sRlC7LJHFRkitjMjQMKR8gC/***@public.gmane.org

http://www.evolutionnext.com
http://www.abqjug.org

(505) 363-5832

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Michael Rimov
2008-05-19 19:37:30 UTC
Permalink
Post by Daniel Hinojosa
Starting pico container for the first time in a real application. I
just want to set a certain container in a JFrame, but ended up with a
problem in the documentation, getAdapter isn't really a method in a
pico container.
Any idea what the correct method is and why documentation has little
problems here and there?
Correct Method is : PicoContainer.getComponentAdapter(Object key);
Post by Daniel Hinojosa
parent = new
PicoBuilder().withCaching().withPropertyApplier().withLifecycle().build();
....
parent.addComponent(JFrame.class);
parent.addComponent("myDesktopPane", DesktopPane.class);
PropertyApplicator pa = (PropertyApplicator)
parent.getAdapter(JFrame.class);
pa.setProperty("contentPane", "myDesktopPane");
I think we're guilty of assuming that since we renamed getComponentInstance()
from Pico 1 to getComponent() our brains told us that getComponentAdapter() was
now getAdapter(). [Paul, was this reverted after a while or is the change fully
in my head?]

As to why the documentation has problems, well, I think the resounding answer is
that we're human and make mistakes. Since we don't unit test the documentation,
sometimes it lags behind.

The end result is that any and all mistakes that you find, please post them here
(or better yet in jira). Please let us know the URL you found these errors or if
you're feeling brave, check out
https://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/distribution/ with
subversion (html pages are in src/site/content) and post a patch to jira.

[I did a global search for ".getAdapter(" in the documentation and found 3
references all within behaviors.html and have checked in the fix giving you
credit in SVN. The fixes will appear with the next Pico release. Did you find
any other references to this function?]

-Mike


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Daniel Hinojosa
2008-05-19 20:10:20 UTC
Permalink
Post by Michael Rimov
Post by Daniel Hinojosa
Starting pico container for the first time in a real application. I
just want to set a certain container in a JFrame, but ended up with a
problem in the documentation, getAdapter isn't really a method in a
pico container.
Any idea what the correct method is and why documentation has little
problems here and there?
Correct Method is : PicoContainer.getComponentAdapter(Object key);
awesome, thanks
Post by Michael Rimov
Post by Daniel Hinojosa
parent = new
PicoBuilder().withCaching().withPropertyApplier().withLifecycle().build();
....
parent.addComponent(JFrame.class);
parent.addComponent("myDesktopPane", DesktopPane.class);
PropertyApplicator pa = (PropertyApplicator)
parent.getAdapter(JFrame.class);
pa.setProperty("contentPane", "myDesktopPane");
I think we're guilty of assuming that since we renamed getComponentInstance()
from Pico 1 to getComponent() our brains told us that getComponentAdapter() was
now getAdapter(). [Paul, was this reverted after a while or is the change fully
in my head?]
As to why the documentation has problems, well, I think the resounding answer is
that we're human and make mistakes. Since we don't unit test the documentation,
sometimes it lags behind.
ah, no problem. I can help with that with JIRAs and updates. ;)
Post by Michael Rimov
The end result is that any and all mistakes that you find, please post them here
(or better yet in jira). Please let us know the URL you found these errors or if
you're feeling brave, check out
https://svn.codehaus.org/picocontainer/java/2.x/trunk/pico/distribution/ with
subversion (html pages are in src/site/content) and post a patch to jira.
[I did a global search for ".getAdapter(" in the documentation and found 3
references all within behaviors.html and have checked in the fix giving you
credit in SVN. The fixes will appear with the next Pico release. Did you find
any other references to this function?]
I didn't specifically look for all instances of that method. But in
doing this, I can probably find some more issues with documentation
since that is what I rely on. ; )


Here is the other issue. I was afraid that it was going to be
component adapter, when doing so I got this...
java.lang.ClassCastException: org.picocontainer.behaviors.Cached
cannot be cast to org.picocontainer.behaviors.PropertyApplicator

My Container is Cached and is a PropertyApplicator assuming I get that
with builder. Hmmm.
--
Daniel Hinojosa
Programmer, Instructor, and Consultant

2529 Wisconsin St. NE
Albuquerque, NM 87110
dhinojosa-sRlC7LJHFRkitjMjQMKR8gC/***@public.gmane.org

http://www.evolutionnext.com
http://www.abqjug.org

(505) 363-5832

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Michael Rimov
2008-05-19 20:27:56 UTC
Permalink
Post by Daniel Hinojosa
Here is the other issue. I was afraid that it was going to be
component adapter, when doing so I got this...
java.lang.ClassCastException: org.picocontainer.behaviors.Cached
cannot be cast to org.picocontainer.behaviors.PropertyApplicator
My Container is Cached and is a PropertyApplicator assuming I get that
with builder. Hmmm.
Ahhhh, yes. Here's what you do:

ComponentAdapter adapterChain = pico.getComponentAdapter(MyObject.class)
assert adapterChain != nul : "Key not found";
PropertyApplication app = adapterChain
.findAdapterOfType(PropertyApplicator.class);
assert app != null : "Property Application Adapter Not Found";

The problem is that Cached is mainly the outermost adapter in the chain of
ComponentAdapters. (Makes sense if you think about it, you don't want to
re-apply properties to the exact same instance of an object)

[Your problem is a good one to add to documentation]

HTH!

-Mike


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...