• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Do Java 5 Annotations make sense for creating Plugins?

 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43045
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic