[AsciidoctorJ Question] Difference between registering an extesion with a className or an instance

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[AsciidoctorJ Question] Difference between registering an extesion with a className or an instance

abelsromero
While testing the Processors SPI I stumbled upon this doubt. In order to offer a simple front-end to register extensions I create an instance from a string and then check its class with instanceof....not elegant, but it's what Java offers.

        Preprocessor processorInstance = (Processor) Class.forName(processorClassName).newInstance();
        if (processorInstance instanceof DocinfoProcessor) {
            javaExtensionRegistry.docinfoProcessor((DocinfoProcessor) processorInstance);
        } else if (processorInstance instanceof Preprocessor) {
            javaExtensionRegistry.preprocessor((Preprocessor) processorInstance);
        } else if (processorInstance instanceof Postprocessor) {
           . . .
So, my doubt is, if is there any recomendation regarding how to register the extension, should I use pass the newly created instance or the name?

Maybe it's a silly question since I can look into the code, but I coundn't figure out how some things are done between Java and Ruby :%