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

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

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

mojavelinux
Administrator
Abel,

You can perform this check without creating an instance using the isAssignableFrom method, explained pretty well in this stackoverflow post.

http://stackoverflow.com/questions/3504870/how-to-test-if-one-java-class-extends-another-at-runtime

You can then pass the class object (not instance) to the registry. That's the ideal scenario.

I'm definitely looking forward to this addition! It will definitely open up a world of possibilities for the Maven community.

Cheers,

-Dan

On Tue, Jan 27, 2015 at 3:10 PM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
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 :%



To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

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

abelsromero
Dan, you keep amazing me everyday. How you get to make feel like a fool, but at the same time I feel so compelled to thank you for it?
Reply | Threaded
Open this post in threaded view
|

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

mojavelinux
Administrator
I aim to inspire everyday. That's my only goal :) Never feel like a fool, or else we can be fools together...which is fun too ;)

-Dan

On Wed, Jan 28, 2015 at 2:27 AM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Dan, you keep amazing me everyday. How you get to make feel like a fool, but at the same time I feel so compelled to thank you for it?


To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--