Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-5996

Remove generic parameter in DM Component interface

    XMLWordPrintableJSON

    Details

      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); 
       }
      

        Attachments

        1. dependencymanager.FELIX-5996.tgz
          1.03 MB
          Pierre De Rop

          Activity

            People

            • Assignee:
              pderop Pierre De Rop
              Reporter:
              pderop Pierre De Rop
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: