Registry-aware components
The RegistryAware interface can be implemented in order to let the component know of the registry it is being bound to.
This commit is contained in:
parent
f2cff8995b
commit
36887ae759
4 changed files with 50 additions and 1 deletions
1
TODO
1
TODO
|
@ -2,7 +2,6 @@ To Do:
|
||||||
* Implement "DriverFor" support
|
* Implement "DriverFor" support
|
||||||
* Scanning packages for annotated components
|
* Scanning packages for annotated components
|
||||||
* General usage documentation
|
* General usage documentation
|
||||||
* Registry awareness
|
|
||||||
* Easier anonymous components
|
* Easier anonymous components
|
||||||
* Uncouple component-provided names from the library
|
* Uncouple component-provided names from the library
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,9 @@ public final class ComponentState
|
||||||
throw new ComponentCreationException( e.getCause( ) );
|
throw new ComponentCreationException( e.getCause( ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( component instanceof RegistryAware ) {
|
||||||
|
( (RegistryAware) component ).setComponentRegistry( registry );
|
||||||
|
}
|
||||||
this.component = component;
|
this.component = component;
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
|
|
22
src/main/java/info/ebenoit/ebul/cmp/RegistryAware.java
Normal file
22
src/main/java/info/ebenoit/ebul/cmp/RegistryAware.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package info.ebenoit.ebul.cmp;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for registry-aware components
|
||||||
|
* <p>
|
||||||
|
* This interface can be implemented by a component that is aware of the component registry it is bound to.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
|
||||||
|
*/
|
||||||
|
public interface RegistryAware
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the component registry
|
||||||
|
*
|
||||||
|
* @param registry
|
||||||
|
* the registry if the component is being bound, or <code>null</code> if the component is being detached.
|
||||||
|
*/
|
||||||
|
public void setComponentRegistry( ComponentRegistry registry );
|
||||||
|
|
||||||
|
}
|
|
@ -65,6 +65,20 @@ public class TestComponentState
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Class used to test registry-aware components */
|
||||||
|
private static class RACmpTest
|
||||||
|
implements RegistryAware
|
||||||
|
{
|
||||||
|
private ComponentRegistry registry;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setComponentRegistry( ComponentRegistry registry )
|
||||||
|
{
|
||||||
|
this.registry = registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** Class used to test methods that affect the component's lifecycle */
|
/** Class used to test methods that affect the component's lifecycle */
|
||||||
private static class LCATest
|
private static class LCATest
|
||||||
{
|
{
|
||||||
|
@ -187,6 +201,17 @@ public class TestComponentState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Test: initialising a {@link ComponentState} that implements {@link RegistryAware} */
|
||||||
|
@Test
|
||||||
|
public void testInitialiseRegistryAware( )
|
||||||
|
{
|
||||||
|
final RACmpTest object = new RACmpTest( );
|
||||||
|
final NewComponentInfo< Object > ci = new NewComponentInfo< Object >( object );
|
||||||
|
new ComponentState( this.reg , ci );
|
||||||
|
Assert.assertSame( this.reg , object.registry );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Test: {@link ComponentState} copies autostart flag */
|
/** Test: {@link ComponentState} copies autostart flag */
|
||||||
@Test
|
@Test
|
||||||
public void testInitialiseAutostart( )
|
public void testInitialiseAutostart( )
|
||||||
|
|
Loading…
Reference in a new issue