@Test public void testGetConverterFor() throws Throwable { FieldConverter<?> actual; ConverterDate convDate; String expected; myLog.debug( "Fetching converter for dateField" ); expected = "yyyy-MM-dd HH:mm:ss"; actual = myClassUnderTest.getConverterFor( "dateField" ); myLog.debug( "Received converter: " + actual ); Assert.assertNotNull( actual ); Assert.assertTrue( actual instanceof ConverterDate ); convDate = (ConverterDate) actual; Assert.assertEquals( expected, convDate.getDatePattern() ); myLog.debug( "Fetching converter for anotherDateField" ); expected = "yyyy-MM-dd"; actual = myClassUnderTest.getConverterFor( "anotherDateField" ); myLog.debug( "Received converter: " + actual ); Assert.assertNotNull( actual ); Assert.assertTrue( actual instanceof ConverterDate ); convDate = (ConverterDate) actual; Assert.assertEquals( expected, convDate.getDatePattern() ); myLog.debug( "Fetching a non declared field converter -> ConverterString" ); actual = myClassUnderTest.getConverterFor( "blabla" ); myLog.debug( "Received converter: " + actual ); Assert.assertNotNull( actual ); Assert.assertTrue( actual instanceof ConverterString ); }
public FieldConverter<?> getConverterFor( String aFieldname ) throws SdiException { if ( !StringUtils.hasText( aFieldname ) ) { throw new SdiException( "Given fieldname is empty!", SdiException.EXIT_CODE_UNKNOWN_ERROR ); } myLog.debug( "Looking up converter for field " + aFieldname ); Environment env = myAppCtxt.getEnvironment(); String converterName = env.getProperty( SdiMainProperties.KEY_PREFIX_CONVERTER + aFieldname ); if ( !StringUtils.hasText( converterName ) ) { return new ConverterString().init( env, aFieldname ); } myLog.debug( "Looking up converter with name " + converterName ); Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation( SdiConverter.class ); myLog.trace( "Found candidates for converter: " + beans.keySet() ); for ( Object bean : beans.values() ) { if ( !( bean instanceof FieldConverter ) ) { throw new SdiException( "Bean annotated with @SdiConverter which is not a FieldConverter, but: " + bean.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR ); } FieldConverter<?> converter = (FieldConverter<?>) bean; SdiConverter annotation = bean.getClass().getAnnotation( SdiConverter.class ); String value = annotation.value(); if ( converterName.equals( value ) ) { return converter.init( env, aFieldname ); } } throw new SdiException( "Converter " + converterName + " for field '" + aFieldname + "' not found", SdiException.EXIT_CODE_CONFIG_ERROR ); }
ConverterFactory { public FieldConverter<?> getConverterFor( String aFieldname ) throws SdiException { if ( !StringUtils.hasText( aFieldname ) ) { throw new SdiException( "Given fieldname is empty!", SdiException.EXIT_CODE_UNKNOWN_ERROR ); } myLog.debug( "Looking up converter for field " + aFieldname ); Environment env = myAppCtxt.getEnvironment(); String converterName = env.getProperty( SdiMainProperties.KEY_PREFIX_CONVERTER + aFieldname ); if ( !StringUtils.hasText( converterName ) ) { return new ConverterString().init( env, aFieldname ); } myLog.debug( "Looking up converter with name " + converterName ); Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation( SdiConverter.class ); myLog.trace( "Found candidates for converter: " + beans.keySet() ); for ( Object bean : beans.values() ) { if ( !( bean instanceof FieldConverter ) ) { throw new SdiException( "Bean annotated with @SdiConverter which is not a FieldConverter, but: " + bean.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR ); } FieldConverter<?> converter = (FieldConverter<?>) bean; SdiConverter annotation = bean.getClass().getAnnotation( SdiConverter.class ); String value = annotation.value(); if ( converterName.equals( value ) ) { return converter.init( env, aFieldname ); } } throw new SdiException( "Converter " + converterName + " for field '" + aFieldname + "' not found", SdiException.EXIT_CODE_CONFIG_ERROR ); } }
ConverterFactory { public FieldConverter<?> getConverterFor( String aFieldname ) throws SdiException { if ( !StringUtils.hasText( aFieldname ) ) { throw new SdiException( "Given fieldname is empty!", SdiException.EXIT_CODE_UNKNOWN_ERROR ); } myLog.debug( "Looking up converter for field " + aFieldname ); Environment env = myAppCtxt.getEnvironment(); String converterName = env.getProperty( SdiMainProperties.KEY_PREFIX_CONVERTER + aFieldname ); if ( !StringUtils.hasText( converterName ) ) { return new ConverterString().init( env, aFieldname ); } myLog.debug( "Looking up converter with name " + converterName ); Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation( SdiConverter.class ); myLog.trace( "Found candidates for converter: " + beans.keySet() ); for ( Object bean : beans.values() ) { if ( !( bean instanceof FieldConverter ) ) { throw new SdiException( "Bean annotated with @SdiConverter which is not a FieldConverter, but: " + bean.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR ); } FieldConverter<?> converter = (FieldConverter<?>) bean; SdiConverter annotation = bean.getClass().getAnnotation( SdiConverter.class ); String value = annotation.value(); if ( converterName.equals( value ) ) { return converter.init( env, aFieldname ); } } throw new SdiException( "Converter " + converterName + " for field '" + aFieldname + "' not found", SdiException.EXIT_CODE_CONFIG_ERROR ); }  }
ConverterFactory { public FieldConverter<?> getConverterFor( String aFieldname ) throws SdiException { if ( !StringUtils.hasText( aFieldname ) ) { throw new SdiException( "Given fieldname is empty!", SdiException.EXIT_CODE_UNKNOWN_ERROR ); } myLog.debug( "Looking up converter for field " + aFieldname ); Environment env = myAppCtxt.getEnvironment(); String converterName = env.getProperty( SdiMainProperties.KEY_PREFIX_CONVERTER + aFieldname ); if ( !StringUtils.hasText( converterName ) ) { return new ConverterString().init( env, aFieldname ); } myLog.debug( "Looking up converter with name " + converterName ); Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation( SdiConverter.class ); myLog.trace( "Found candidates for converter: " + beans.keySet() ); for ( Object bean : beans.values() ) { if ( !( bean instanceof FieldConverter ) ) { throw new SdiException( "Bean annotated with @SdiConverter which is not a FieldConverter, but: " + bean.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR ); } FieldConverter<?> converter = (FieldConverter<?>) bean; SdiConverter annotation = bean.getClass().getAnnotation( SdiConverter.class ); String value = annotation.value(); if ( converterName.equals( value ) ) { return converter.init( env, aFieldname ); } } throw new SdiException( "Converter " + converterName + " for field '" + aFieldname + "' not found", SdiException.EXIT_CODE_CONFIG_ERROR ); }  List<FieldConverter<?>> getFieldConverters( Collection<String> aFieldnames ); FieldConverter<?> getConverterFor( String aFieldname ); }
ConverterFactory { public FieldConverter<?> getConverterFor( String aFieldname ) throws SdiException { if ( !StringUtils.hasText( aFieldname ) ) { throw new SdiException( "Given fieldname is empty!", SdiException.EXIT_CODE_UNKNOWN_ERROR ); } myLog.debug( "Looking up converter for field " + aFieldname ); Environment env = myAppCtxt.getEnvironment(); String converterName = env.getProperty( SdiMainProperties.KEY_PREFIX_CONVERTER + aFieldname ); if ( !StringUtils.hasText( converterName ) ) { return new ConverterString().init( env, aFieldname ); } myLog.debug( "Looking up converter with name " + converterName ); Map<String, Object> beans = myAppCtxt.getBeansWithAnnotation( SdiConverter.class ); myLog.trace( "Found candidates for converter: " + beans.keySet() ); for ( Object bean : beans.values() ) { if ( !( bean instanceof FieldConverter ) ) { throw new SdiException( "Bean annotated with @SdiConverter which is not a FieldConverter, but: " + bean.getClass().getName(), SdiException.EXIT_CODE_CONFIG_ERROR ); } FieldConverter<?> converter = (FieldConverter<?>) bean; SdiConverter annotation = bean.getClass().getAnnotation( SdiConverter.class ); String value = annotation.value(); if ( converterName.equals( value ) ) { return converter.init( env, aFieldname ); } } throw new SdiException( "Converter " + converterName + " for field '" + aFieldname + "' not found", SdiException.EXIT_CODE_CONFIG_ERROR ); }  List<FieldConverter<?>> getFieldConverters( Collection<String> aFieldnames ); FieldConverter<?> getConverterFor( String aFieldname );  }