[ 
http://jira.codehaus.org/browse/JBEHAVE-258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=216595#action_216595
 ] 

Mauro Talevi commented on JBEHAVE-258:
--------------------------------------

Interesting stuff, Bruno.  My only comment is that the annotation route might 
work nicely with converters that have default constructors, but how do we 
handle those that take parameters upon instantiation.   It might get pretty 
messy.  

> Annotation for ParameterConverter
> ---------------------------------
>
>                 Key: JBEHAVE-258
>                 URL: http://jira.codehaus.org/browse/JBEHAVE-258
>             Project: JBehave
>          Issue Type: Improvement
>            Reporter: Bruno Bieth
>
> Simplifying adding ParameterConverter to Steps. Here's an example :
> {code}
> public class DateTimeConverter  implements ParameterConverter {
>       @Override
>       public boolean accept(Type type) {
>               return type.equals( DateTime.class );
>       }
>       @Override
>       public Object convertValue(String value, Type type) {                   
>               return new DateTime( value );
>       }
> }
> {code}
> {code}
> @ParameterConverters(DateTimeConverter.class)
> public class PersonSteps {
>       private Person person;
>       private DateTime currentDate;
>       // ... steps
> }
> {code}
> The ParameterConverters annotation takes an array of TypeConverter :
> {code}
> @Retention(RetentionPolicy.RUNTIME)
> @Target(ElementType.TYPE)
> public @interface ParameterConverters {
>       Class<? extends ParameterConverter>[] value();
> }
> {code}
> Here is a steps factory :
> {code}
> public class ParameterConverterStepsFactory {
>     public CandidateSteps[] createCandidateSteps(Object... stepsInstances) 
> throws InstantiationException, IllegalAccessException {
>         CandidateSteps[] candidateSteps = new 
> CandidateSteps[stepsInstances.length];
>         for (int i = 0; i < stepsInstances.length; i++) {
>               Object stepsInstance = stepsInstances[i];
>               StepsConfiguration configuration;
>               
>               ParameterConverters parameterConverters = 
>                       stepsInstance.getClass().getAnnotation( 
> ParameterConverters.class );
>               
>               if( parameterConverters != null ) {
>                       configuration = createConfiguration( 
> parameterConverters );
>               } else {                
>                       configuration = new StepsConfiguration();
>               }
>               
>             candidateSteps[i] = new Steps(configuration, stepsInstance);
>         }
>         return candidateSteps;
>     }
>       private StepsConfiguration createConfiguration(
>                       ParameterConverters annotation) throws 
> InstantiationException, IllegalAccessException {
>               ParameterConverter[] converters = new ParameterConverter[ 
> annotation.value().length ];
>               for( int i = 0; i < converters.length; i ++ ) {
>                       converters[ i ] = annotation.value()[ i ].newInstance();
>               }
>               org.jbehave.scenario.steps.ParameterConverters 
> converterAggregate = 
>                       new org.jbehave.scenario.steps.ParameterConverters( 
> converters );
>               return new StepsConfiguration( converterAggregate );
>       }
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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

    http://xircles.codehaus.org/manage_email


Reply via email to