Details
-
Task
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
org.apache.felix.dependencymanager-r13
-
None
Description
Since dm-r13, the Component interface is now taking a generic parameter so it make it easier to define extended components like adapters.
So, with this new model, it looks like the following:
public interface Component<T extends Component<T>> { T setInterface(String service, Dictionary properties) T setImplementation(Object ob); ... } public interface AdapterComponent extends Component<AdapterComponent> { AdapterComponent setAdaptee(Class<?> service, String filter); AdapterComponent setAdapteeCallbacks(String add, String change, String remove, String swap); ... }
and you can now do something like this:
Component adapter = createAdapterComponent() .setAdaptee(Adaptee.class, "(foo=bar)") .setAdapteeCallbacks("setAdaptee", "changeAdaptee", null, null) .setImplementation(AdapterImpl.class) .setInterface(AdapterService.class, null) .add(createServiceDependency().setService(LogService.class));
now, while using the generic parameter simplify the declaration of component adapters, it has a drawback: the Component now takes a generic parameter, and old code using simple components now generates a compilation warning:
Component adapter = createComponent() .setImplementation(SimpleComponent.class) ...
so, the above example generates a compilation warning, and you now have to declare "?" in order to get rid of the warning:
Component<?> adapter = createComponent() .setImplementation(SimpleComponent.class) ...
that being said, maybe we can refactor in order to get rid of the generic parameter, by copying the top level component methods in sub interfaces, like this:
public interface Component { Component setInterface(String service, Dictionary properties); Component setImplementation(Object ob); ... } public interface AdapterComponent extends Component { // Component methods with specialized signatures AdapterComponent setInterface(String service, Dictionary properties) AdapterComponent setImplementation(Object ob); // AdapterComponent methods AdapterComponent methods AdapterComponent setAdaptee(Class<?> service, String filter); AdapterComponent setAdapteeCallbacks(String add, String change, String remove, String swap); }