395620 do not managed inherited life cycle listeners

This commit is contained in:
Greg Wilkins 2013-03-07 11:27:45 +11:00
parent e283d72f25
commit 2a0bfea187
2 changed files with 34 additions and 1 deletions

View File

@ -230,7 +230,12 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
// handle inheritance
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
((Container)b._bean).addBean(listener);
{
if (b._bean instanceof ContainerLifeCycle)
((ContainerLifeCycle)b._bean).addBean(listener, false);
else
((Container)b._bean).addBean(listener);
}
}
}

View File

@ -33,6 +33,7 @@ import org.junit.Test;
public class ContainerLifeCycleTest
{
@Test
public void testStartStopDestroy() throws Exception
{
@ -502,6 +503,33 @@ public class ContainerLifeCycleTest
}
private final class InheritedListenerLifeCycle extends AbstractLifeCycle implements Container.InheritedListener
{
public @Override void beanRemoved(Container p, Object c){}
public @Override void beanAdded(Container p, Object c) {}
public @Override String toString() {return "inherited";}
}
@Test
public void testInheritedListener() throws Exception
{
ContainerLifeCycle c0 = new ContainerLifeCycle() { public @Override String toString() {return "c0";}};
ContainerLifeCycle c00 = new ContainerLifeCycle() { public @Override String toString() {return "c00";}};
ContainerLifeCycle c01 = new ContainerLifeCycle() { public @Override String toString() {return "c01";}};
Container.InheritedListener inherited= new InheritedListenerLifeCycle();
c0.addBean(c00);
c0.start();
c0.addBean(inherited);
c0.addBean(c01);
Assert.assertTrue(c0.isManaged(inherited));
Assert.assertFalse(c00.isManaged(inherited));
Assert.assertFalse(c01.isManaged(inherited));
}
String trim(String s) throws IOException
{
StringBuilder b=new StringBuilder();