Changes between Version 19 and Version 20 of PluginDevelopmentGuide

20.04.2013 17:04:09 (11 years ago)

The service interface


  • PluginDevelopmentGuide

    v19 v20  
    727727A [[DeepaMehtaCoreEvents|list of all DeepaMehta Core events]] is available in the reference section. 
     729=== Providing a service === 
     731Your plugin can make its business logic, that is its service methods, accessible by other plugins (via OSGi) and/or by external applications (via HTTP/REST). 
     733==== The 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 its service interface. 
     737The 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`. 
     739The 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. 
     741As an example look at the //Topicmaps// plugin (part of the DeepaMehta Standard Distribution): 
     746    src/ 
     747        main/ 
     748            java/ 
     749                de/ 
     750                    deepamehta/ 
     751                        plugins/ 
     752                            topicmaps/ 
     753                                service/ 
     757The service interface of the //Topicmaps// plugin is named `TopicmapsService`. The plugin package is `de.deepamehta.plugins.topicmaps`. 
     759The //Topicmaps// service interface looks like this: 
     763package de.deepamehta.plugins.topicmaps.service; 
     765import de.deepamehta.plugins.topicmaps.TopicmapRenderer; 
     766import de.deepamehta.plugins.topicmaps.model.ClusterCoords; 
     767import de.deepamehta.plugins.topicmaps.model.Topicmap; 
     769import de.deepamehta.core.Topic; 
     770import de.deepamehta.core.service.ClientState; 
     771import de.deepamehta.core.service.PluginService; 
     775public interface TopicmapsService extends PluginService { 
     777    Topic createTopicmap(String name,             String topicmapRendererUri, ClientState clientState); 
     778    Topic createTopicmap(String name, String uri, String topicmapRendererUri, ClientState clientState); 
     780    // --- 
     782    Topicmap getTopicmap(long topicmapId, ClientState clientState); 
     784    // --- 
     786    void addTopicToTopicmap(long topicmapId, long topicId, int x, int y); 
     788    void addAssociationToTopicmap(long topicmapId, long assocId); 
     790    void moveTopic(long topicmapId, long topicId, int x, int y); 
     792    void setTopicVisibility(long topicmapId, long topicId, boolean visibility); 
     794    void removeAssociationFromTopicmap(long topicmapId, long assocId); 
     796    void moveCluster(long topicmapId, ClusterCoords coords); 
     798    void setTopicmapTranslation(long topicmapId, int trans_x, int trans_y); 
     800    // --- 
     802    void registerTopicmapRenderer(TopicmapRenderer renderer); 
     806You 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`.