History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WAFFLE-52
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Michael Ward
Reporter: peter kovac hausel
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Waffle

Allow component registration with the same interface but different implementation

Created: 17/Dec/07 02:56 PM   Updated: 18/Jan/08 10:05 AM
Component/s: Core
Affects Version/s: 1.0-rc-2
Fix Version/s: 1.0

Time Tracking:
Not Specified

File Attachments: 1. Java Source File PicoRegistrar.java (6 kb)


Patch Submitted: Yes


 Description  « Hide
Service class and OtherService are implementing the same interface

register("implementinterface1", Service.class);
register("implementinterface2", OtherService.class);
register("controller", Controller.class, new Object[]{}, new Object[]{"implementinterface1"});
register("othercontroller", OtherController.class, new Object[]{"this controller has a string constant param too"}, new Object[]{"implementinterface2"});
register("constantcontroller", ConstantController.class, new Object[]{"constant param only"});

where the last two Object[] params are the constant param array and the component key array

peter

attached is the implementation of our PicoRegistrar (the interesting stuff is in picoParameter method)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Michael Ward - 19/Dec/07 08:09 AM
The pico parameter support provided by Waffle (request, session and servletContext) was no longer integrated into the code after all the refactoring and functionality improvements. Pico's ConstantParameter was mistakenly the only supported parameter type.

Waffle has been updated to support both Pico's Constant a Component Parameters as well as several custom parameter implementation provided by Waffle (RequestParameter, RequestAttribute, SessionAttribute and ServletContext). These allow for parameter values to be resolved against these contexts.

The dependency on pico is encapsulated within Waffle (allowing for alternate or additional DI frameworks to be integrated with Waffle). In order to satisfy this defect Waffle now has created a Reference object. Implementation include ComponentReference, HttpSessionAttributeReference, RequestAttributeReference, RequestParameterReference and ServletContextReference. Each of these Reference implementation provides a static method that can be statically imported in a Registrar to simplify the registration of components. Example:

class FooComponent {
private String name;
private Long value;
private MyDAO dao;

public FooComponent(String name, Long value, MyDAO dao) { this.name = name; this.value = value; this.dao = dao; }
}

class TheRegistrar .. {

public void request() { register("dao", MyDAOImpl.class); // "Mike" - is a constant // requestParameter("count") - will resolve the value from the request parameter // component("dao") - will resolve against a named component (registered with Waffle) register("foo", FooComponent.class, "Mike", requestParameter("count"), component("dao")); }
}


peter kovac hausel - 14/Jan/08 07:00 PM
i do not think it's working correctly.

http://svn.codehaus.org/waffle/trunk/waffle-core/src/main/java/org/codehaus/waffle/context/pico/PicoContextContainerFactory.java

at the moment PicoRegistrar gets a null instead of an implementation of ParameterResolver (ie DefaultParameterResolver).

i think it should be either Registrar registrar = new PicoRegistrar(delegateContainer, delegateContainer.getComponentInstance(ParamaterResolver.class), picoLifecycleStrategy, registrarMonitor);

or since picoContainer is already there, we could just get ParameterResolver component from pico directly in PicoRegistrar. (http://svn.codehaus.org/waffle/trunk/waffle-core/src/main/java/org/codehaus/waffle/registrar/pico/PicoRegistrar.java)


Michael Ward - 14/Jan/08 10:22 PM
looking into issue

Michael Ward - 14/Jan/08 10:29 PM
when initially refactoring for this fix I accidentally had the PicoContextContainerFactory construct the PicoRegistrar with a 'null' for the ParameterResolver (in the createRegistrar method).

peter kovac hausel - 15/Jan/08 08:44 AM
also, i think this one and providing setter injection are cool features, we should update the doc on the website. (do you need help with that?)

peter kovac hausel - 15/Jan/08 12:38 PM
just realized that my solution is not going to work since we are passing in a session level pico not the app one which has ParameterResolver component.

peter kovac hausel - 15/Jan/08 02:04 PM
my solution was to
1) expose parameterResolver vi ComponentRegistry (getParameterResolver)
2) save servletConext in a procted value in AbstractContextContainerFactory
3) get componentRegestiry from servlet context at createRegistrat i.e.

ComponentRegistry componentRegistry = (ComponentRegistry) servletContext.getAttribute(ComponentRegistry.class.getName());

4) pass along componentRegistry.getParameterResolver()


peter kovac hausel - 15/Jan/08 02:05 PM
left some typos in my previous comment but i hope you get the gist. (too bad i can not edit in this jira version)

peter kovac hausel - 18/Jan/08 09:04 AM
mike's fix solved the issue. thank you

Mauro Talevi - 18/Jan/08 09:37 AM
Renamed issue for better clarity.

Mauro Talevi - 18/Jan/08 10:05 AM
Peter, I've updated the registrar docs to reflect latest changes. Thanks for the heads up.