Discovering subclasses or implementations of an interface

C

Chris

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.
 
J

Joshua Cranmer

Chris said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top