• Post Reply Bookmark Topic Watch Topic
  • New Topic

Do Java 5 Annotations make sense for creating Plugins?  RSS feed

 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do Java 5 Annotations make sense for creating Plugins. Or should a simple configuration file (XML or plain) be the way for Plugins.

I wonder whether Annotations can do the job here.

Regards,
Darya
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how an annotation (or a config file, for that matter) can help with creating a plugin. It might help the class find an associated plugin, e.g. if the classname of the plugin was part of the annotation.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I use an XML configuration file for plugin architecture because of the flexibility. Adding a new class that has different initialization requirements does not disturb any of the existing configurations. Its so easy to give every plugin class a method:

configureYourself( org.w3c.dom.Element )

Bill
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use annotations for a plug-in infrastructure.

If I would need a "plugability" for a serious project, I wouldn't go and try to invent my own plug-in architecture. I would use an existing architecture like OSGi (which is used in Eclipse).
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think of Sun's Service Provider Interface (SPI) approach in combination with Annotations for creating plugins?

I don't know why Sun's SPI approach was never described in a blueprint document, at least AFAIK. Sun itself heavily use the SPI approach.

So why not use it similar in our own products or applications. One could write an Annotation Processor Factory and a special Annotation so that the configuration is stored during compile time into some META-INF/service configuration file? Each concrete class would then get such special annotation.

Wouldn't that be more convenient and less error prone than doing it manually?

Regards,
Darya
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's service provider interface is a neat way to be able to plug in services. So you want to use annotations to generate the META-INF/<service> configuration file at compile time instead of writing this file manually.

That sounds like a good idea, but what would happen if you have two classes that implement the same service? Will the META-INF/<service> file be overwritten and will the order in which the classes are compiled determine which one is actually plugged in?
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
That sounds like a good idea, but what would happen if you have two classes that implement the same service? Will the META-INF/<service> file be overwritten and will the order in which the classes are compiled determine which one is actually plugged in?


Actually the configuration file can contain more than two classes. It can contain as many as there are plugins out. The new Annotation is there to add each Plugin to that configuration file just for convenience.

Regards,
Darya
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!