1 package net.sf.openrocket.plugin.framework;
3 import java.util.Collections;
6 import net.sf.openrocket.util.BugException;
9 * An abstract service implementation that returns plugins of type P.
11 * @param <P> the plugin type that this service returns.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public abstract class AbstractService<P> implements Service {
16 private final Class<P> type;
18 protected AbstractService(Class<P> type) {
22 @SuppressWarnings("unchecked")
24 public <E> List<E> getPlugins(Class<E> e, Object... args) {
27 return Collections.emptyList();
30 List<P> plugins = getPlugins(args);
32 // Check list content types to avoid mysterious bugs later on
34 if (!type.isInstance(p)) {
35 throw new BugException("Requesting plugins of type " + type + " but received " +
36 ((p != null) ? p.getClass() : "null"));
40 return (List<E>) plugins;
43 protected abstract List<P> getPlugins(Object... args);