Discussion:
Ambigous with annotation binding
jduss
2009-07-30 14:06:30 UTC
Permalink
Hi guys!

I just implemented testcase which doesn't work as I expected according to
http://www.nabble.com/patches-for-*full*-binding-annotation-capability-td13986483.html
patches-for-*full*-binding-annotation-capability post.

I think it is quite standart situation but I couldn find any solution :(

Could anyone to say how to create HumanService class?

Regards

--------------------------------------------------------------------------------------
package com.company.performance.pico;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.picocontainer.BindKey;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.annotations.Bind;
import org.picocontainer.injectors.SetterInjection;

import junit.framework.TestCase;

public class AmbiguousDependencyTestCase extends TestCase {

@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD, ElementType.PARAMETER })
@Bind
public static @interface FirstService {
}

@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD, ElementType.PARAMETER })
@Bind
public static @interface SecondService {
}

public static interface Service {
void start();
}

public static abstract class SuperService implements Service {

private Service firstService;
private Service secondService;

public Service getFirstService() {
return firstService;
}

public void setFirstService(@FirstService Service firstService) {
this.firstService = firstService;
}

public Service getSecondService() {
return secondService;
}

public void setSecondService(@SecondService Service secondService) {
this.secondService = secondService;
}

public void start() {
System.out.println(this.getClass().getCanonicalName());
}
}


public static class RightService extends SuperService {

}

public static class LeftService extends SuperService {

}

public static class HumanService extends SuperService {

}

private DefaultPicoContainer mpc;

public void testRussianDollAnnotationInjection() {
mpc = new DefaultPicoContainer(new SetterInjection());
mpc.addComponent(HumanService.class);
mpc.addComponent(BindKey.bindKey(Service.class, FirstService.class),
RightService.class);
mpc.addComponent(BindKey.bindKey(Service.class, SecondService.class),
LeftService.class);
HumanService humanService = mpc.getComponent(HumanService.class);
assertNotNull(humanService);
assertNotNull(humanService.getFirstService());
assertNotNull(humanService.getSecondService());
assertTrue(humanService.getFirstService() instanceof RightService);
assertTrue(humanService.getSecondService() instanceof LeftService);
}
}

--------------------------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/Ambigous-with-annotation-binding-tp24739142p24739142.html
Sent from the NanoContainer - PicoContainer - Users mailing list archive at Nabble.com.


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

http://xircles.codehaus.org/manage_email
Loading...