Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Discovering subclasses or implementations of an interface (http://www.velocityreviews.com/forums/t484375-discovering-subclasses-or-implementations-of-an-interface.html)

Chris 03-15-2007 12:01 AM

Discovering subclasses or implementations of an interface
 
We've got an app that has connectors to external systems. We allow our
customers to subclass our main Connector class to implement their own
connector. If a customer puts a Connector implementation on the
classpath, is it possible for our app to discover it automatically?

What I want to do is show the full list of all available connectors in
the user interface of our app, without forcing the customer to manually
add the connector. I'd like to avoid adding yet another configuration file.

It's possible for us to have the customer implement an interface rather
than subclass a main class, if necessary.

Joshua Cranmer 03-15-2007 12:28 AM

Re: Discovering subclasses or implementations of an interface
 
Chris wrote:
> We've got an app that has connectors to external systems. We allow our
> customers to subclass our main Connector class to implement their own
> connector. If a customer puts a Connector implementation on the
> classpath, is it possible for our app to discover it automatically?
>
> What I want to do is show the full list of all available connectors in
> the user interface of our app, without forcing the customer to manually
> add the connector. I'd like to avoid adding yet another configuration file.
>
> It's possible for us to have the customer implement an interface rather
> than subclass a main class, if necessary.


java.util.ServiceProvider sounds like what you want. If not, you'll have
to do some ugly messing around with class loaders to detect classes that
subclass Connector.

Chris 03-15-2007 06:42 PM

Re: Discovering subclasses or implementations of an interface
 
Joshua Cranmer wrote:
> Chris wrote:
>> We've got an app that has connectors to external systems. We allow our
>> customers to subclass our main Connector class to implement their own
>> connector. If a customer puts a Connector implementation on the
>> classpath, is it possible for our app to discover it automatically?
>>
>> What I want to do is show the full list of all available connectors in
>> the user interface of our app, without forcing the customer to
>> manually add the connector. I'd like to avoid adding yet another
>> configuration file.
>>
>> It's possible for us to have the customer implement an interface
>> rather than subclass a main class, if necessary.

>
> java.util.ServiceProvider sounds like what you want. If not, you'll have
> to do some ugly messing around with class loaders to detect classes that
> subclass Connector.


I did not find that class, but I did find this:

http://weblogs.java.net/blog/enichol...ng_a_serv.html

Looks like there's enough here to get started.


All times are GMT. The time now is 10:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.