Skip to content

The DS Annotation Builder Plug in for Eclipse

wuetherich edited this page Nov 6, 2014 · 2 revisions

To be able to use the DS annotations in Eclipse you have to install a specialised plug-in that analyzes the annotated classes and generates the component description based of the given annotations. The DS Annotation Builder Plug-in is such a plug-in, and it allows you to generate Declarative Service Component descriptions using DS annotations.

E.g., you can write code like this:

  package org.javakontor.ds.example.internal;
  
  import org.javakontor.ds.example.LogService;
  import org.javakontor.ds.example.TranslationService;
  import org.osgi.service.component.annotations.Activate;
  import org.osgi.service.component.annotations.Component;
  import org.osgi.service.component.annotations.Reference;
  
  @Component
  public class TranslationServiceImpl implements TranslationService {
  
    private LogService _logService;

    public String translate(String msg) {
      // ...
      return msg;
    }

    @Activate
    public void activate() {
      _logService.log("TranslationService activated");
    }

    @Reference
    public void setLogService(LogService logService) {
      _logService = logService;
    }
 }

From this code the appropriate Declarative Service component description is generated:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<scr:component activate="activate" 
               name="org.javakontor.ds.example.internal.TranslationServiceImpl"                            
               xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
    <service>
        <provide interface="org.javakontor.ds.example.TranslationService"/>
    </service>
    <reference unbind="unsetLogService" 
               bind="setLogService" 
               interface="org.javakontor.ds.example.LogService" 
               name="LogService"/>
    <implementation 
       class="org.javakontor.ds.example.internal.TranslationServiceImpl"/>
</scr:component>