Improved component naming
* Setting a component information record's name to null will lead to an anonymous component, while setting it to an empty string will lead to an component whose name is that of its class. * New Anonymous annotation to indicate that a component is meant to be anonymous (conflicts with ParametricComponent or valued Component annotations).
This commit is contained in:
parent
36887ae759
commit
0c23f613d6
6 changed files with 158 additions and 27 deletions
src/main/java/info/ebenoit/ebul/cmp
21
src/main/java/info/ebenoit/ebul/cmp/Anonymous.java
Normal file
21
src/main/java/info/ebenoit/ebul/cmp/Anonymous.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package info.ebenoit.ebul.cmp;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Annotation indicating that a component will not have a name.
|
||||
*
|
||||
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
|
||||
*/
|
||||
@Retention( RetentionPolicy.RUNTIME )
|
||||
@Target( ElementType.TYPE )
|
||||
public @interface Anonymous
|
||||
{
|
||||
// EMPTY
|
||||
}
|
|
@ -84,7 +84,7 @@ public final class ComponentState
|
|||
name = ( (ParametricComponent) component ).getComponentName( );
|
||||
} else {
|
||||
name = ci.getName( );
|
||||
if ( name == null ) {
|
||||
if ( "".equals( name ) ) {
|
||||
name = component.getClass( ).getSimpleName( );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,15 +75,22 @@ public final class NewComponentInfo< T >
|
|||
|
||||
// Sets the new component's name
|
||||
final Component aComp = klass.getAnnotation( Component.class );
|
||||
if ( aComp != null && !"".equals( aComp.value( ) ) ) {
|
||||
final boolean isAnon = klass.isAnnotationPresent( Anonymous.class );
|
||||
if ( isAnon ) {
|
||||
if ( ParametricComponent.class.isAssignableFrom( klass ) ) {
|
||||
throw new ComponentDefinitionException( "parametric component can't be anonymous" );
|
||||
}
|
||||
if ( aComp != null && !"".equals( aComp.value( ) ) ) {
|
||||
throw new ComponentDefinitionException( "named component can't be anonymous" );
|
||||
}
|
||||
info.setName( null );
|
||||
} else if ( aComp != null ) {
|
||||
if ( !"".equals( aComp.value( ) ) && ParametricComponent.class.isAssignableFrom( klass ) ) {
|
||||
throw new ComponentDefinitionException( "parametric component can't be named" );
|
||||
}
|
||||
info.setName( aComp.value( ) );
|
||||
} else if ( !ParametricComponent.class.isAssignableFrom( klass ) ) {
|
||||
info.setName( klass.getSimpleName( ) );
|
||||
} else {
|
||||
info.setName( null );
|
||||
info.setName( "" );
|
||||
}
|
||||
|
||||
// Autostart flag
|
||||
|
@ -365,7 +372,8 @@ public final class NewComponentInfo< T >
|
|||
* Sets the new component's name
|
||||
*
|
||||
* @param name
|
||||
* the new component's name
|
||||
* the new component's name. May be <code>null</code> for an anonymous component or {@code ""} for a
|
||||
* component whose class name will serve as its name.
|
||||
* @return the current object
|
||||
*/
|
||||
public NewComponentInfo< T > setName( final String name )
|
||||
|
@ -376,7 +384,8 @@ public final class NewComponentInfo< T >
|
|||
|
||||
|
||||
/**
|
||||
* @return the name of the new component
|
||||
* @return the name of the new component. May be <code>null</code> for an anonymous component or {@code ""} for a
|
||||
* component whose class name will serve as its name.
|
||||
*/
|
||||
public String getName( )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue