Understanding Binding Types
peteroyle.howardmoon.hitcity.com.au Jan 15, 2009 12:02 AMHi,
Does the current ALPHA1 and/or TRUNK versions of the RI support the use of binding annotations? I can't see any code that checks what they are within ManagerImpl.getInstanceByType(...) (apart from sanity checking the types themselves).
To double check I created the following simple web beans:
@Named public class Door { }
@Synchronous @Named public class SynchronousDoor extends Door { }
I then added this method to the existing test class org.jboss.webbeans.test.InstantiationByTypeTest.java:
@Test() @SpecAssertion(section="5.9") public void testBindingTypes() throws Exception { DependentContext.INSTANCE.setActive(true); try { Bean<SynchronousDoor> synchDoorBean = SimpleBean.of(SynchronousDoor.class, manager); manager.addBean(synchDoorBean); Bean<Door> doorBean = SimpleBean.of(Door.class, manager); manager.addBean(doorBean); /* a */ manager.getInstanceByType(Door.class, new CurrentBinding()); /* b */ manager.getInstanceByType(Door.class); // c manager.getInstanceByType(SynchronousDoor.class); // d manager.getInstanceByType(SynchronousDoor.class, new CurrentBinding()); // e manager.getInstanceByType(SynchronousDoor.class, new CurrentBinding(), new AnnotationLiteral<Synchronous>(){}); // f manager.getInstanceByType(Door.class, new CurrentBinding(), new AnnotationLiteral<Synchronous>(){}); } finally { DependentContext.INSTANCE.setActive(false); } }
Only lines a and b pass. The commented out lines c to f all fail with an UnsatisfiedDependencyException - something like:
javax.webbeans.UnsatisfiedDependencyException: Annotated class Class @Named @Synchronous org.jboss.webbeans.test.pete.SynchronousDoor (and probably something silghtly different for line f).
Can anyone please shed some light for me as to why each of the lines above passes or fails?
Greatly appreciated.