public void registerGenerator ( String clazz ) { ResourceGenerator generator = ( ResourceGenerator ) ClassLoaderResourceUtils . buildObjectInstance ( clazz ) ; if ( null == generator . getResolver ( ) ) { throw new IllegalStateException ( "The getResolver() method must return something at " + clazz ) ; } ResourceGeneratorResolver resolver = generator . getResolver ( ) ; // Checks if another generator is already define with the same resolver for ( ResourceGeneratorResolver resourceGeneratorResolver : resolverRegistry ) { if ( resourceGeneratorResolver . isSameAs ( resolver ) ) { String generatorName = generator . getClass ( ) . getName ( ) ; if ( ! clazz . equals ( generatorName ) ) { String errorMsg = "Cannot register the generator of class " + generator . getClass ( ) . getName ( ) + " since the same resolver is being used by " + generatorName + ". Please specify a different resolver in the getResolver() method." ; throw new IllegalStateException ( errorMsg ) ; } } } // Warns the user about if the generator override a built-in generator Set < ResourceGeneratorResolver > commonResolvers = commonGenerators . keySet ( ) ; for ( ResourceGeneratorResolver commonGeneratorResolver : commonResolvers ) { if ( commonGeneratorResolver . isSameAs ( resolver ) ) { String generatorName = generator . getClass ( ) . getName ( ) ; LOGGER . warn ( "The custom generator '" + generatorName + "' override a built-in generator" ) ; } } initGenerator ( generator ) ; }
Register a generator mapping it to the specified prefix .