Changes between Version 20 and Version 21 of PluginDevelopmentGuide


Ignore:
Timestamp:
20.04.2013 18:17:53 (7 years ago)
Author:
jri
Comment:

Implementing the service

Legend:

Unmodified
Added
Removed
Modified
  • PluginDevelopmentGuide

    v20 v21  
    733733==== The service interface ==== 
    734734 
    735 For a plugin to provide a service you must define a //service interface//. The service interface contains all the method signatures that make up the service. When other plugins consume your plugin's service they do so via its service interface. 
     735For a plugin to provide a service you must define a //service interface//. The service interface contains all the method signatures that make up the service. When other plugins consume your plugin's service they do so via the service interface. 
    736736 
    737737The service interface //must// be located in the plugin's `src/main/java/<your plugin package>/service/` directory. By convention the name of the service interface ends with `...Service`. The service interface must be declared `public`. 
     
    739739The service interface is a regular Java interface that extends `de.deepamehta.core.service.PluginService`. PluginService is a common base interface for all plugin services. It's just a marker interface. 
    740740 
    741 As an example look at the //Topicmaps// plugin (part of the DeepaMehta Standard Distribution): 
     741A DeepaMehta plugin can define //one// service interface at most. More than one service interface is not supported. 
     742 
     743As an example see the //Topicmaps// plugin (part of the DeepaMehta Standard Distribution): 
    742744 
    743745{{{ 
     
    805807 
    806808You see the Topicmaps service consist of methods to create topicmaps, retrieve topicmaps, and manipulate topicmaps. As any plugin service the Topicmaps service must be derived from `PluginService`. 
     809 
     810==== Implementing the service ==== 
     811 
     812After defining the plugin's service interface you must implement the actual service methods. Implementation takes place in the plugin main file. 
     813 
     814The plugin main class must declare that it implements the plugin's service interface. (So you need to import the service interface.) Each service method implementation must be `public`. Annotate each service method implementation with `@Override`. 
     815 
     816As an example see the implementation of the //Topicmaps// service: 
     817 
     818{{{ 
     819#!java 
     820package de.deepamehta.plugins.topicmaps; 
     821 
     822import de.deepamehta.plugins.topicmaps.model.Topicmap; 
     823import de.deepamehta.plugins.topicmaps.service.TopicmapsService; 
     824 
     825import de.deepamehta.core.Topic; 
     826import de.deepamehta.core.osgi.PluginActivator; 
     827import de.deepamehta.core.service.ClientState; 
     828 
     829 
     830 
     831public class TopicmapsPlugin extends PluginActivator implements TopicmapsService { 
     832 
     833    // *** TopicmapsService Implementation *** 
     834 
     835    @Override 
     836    public Topic createTopicmap(String name, String topicmapRendererUri, ClientState clientState) { 
     837        ... 
     838    } 
     839 
     840    @Override 
     841    public Topic createTopicmap(String name, String uri, String topicmapRendererUri, ClientState clientState) { 
     842        ... 
     843    } 
     844 
     845    // --- 
     846 
     847    @Override 
     848    public Topicmap getTopicmap(long topicmapId, ClientState clientState) { 
     849        ... 
     850    } 
     851 
     852    // --- 
     853 
     854    @Override 
     855    public void addTopicToTopicmap(long topicmapId, long topicId, int x, int y) { 
     856        ... 
     857    } 
     858 
     859    ... 
     860}}} 
     861 
     862You see, the plugin main class `TopicmapsPlugin` implements the plugin's service interface `TopicmapsService`.