public static Format getFormat ( String className ) { assert className != null ; if ( className . isEmpty ( ) ) { return null ; } ThreadLocal < Format > tlsFormatter = classFormatters . get ( className ) ; if ( tlsFormatter == null ) { try { // append formatter class name to cache only if exists and is of right type Classes . forName ( className ) ; tlsFormatter = new ThreadLocal < Format > ( ) ; classFormatters . put ( className , tlsFormatter ) ; } catch ( NoSuchBeingException e ) { log . error ( "Formatter class |%s| not found." , className ) ; return null ; } catch ( ClassCastException e ) { log . error ( "Invalid formatter class |%s|. It should inherit from |%s|." , className , Format . class ) ; return null ; } } Format formatter = tlsFormatter . get ( ) ; if ( formatter == null ) { formatter = createFormatter ( className ) ; if ( formatter == null ) { // formatter can be invalid only if miss proper constructor and this is for sure a flaw in logic throw new BugError ( "Invalid formatter class |%s|. Proper constructor not found." , className ) ; } tlsFormatter . set ( formatter ) ; } return formatter ; }
Return format instance usable to requested class .