Changes between Version 19 and Version 20 of PluginDevelopmentGuide


Ignore:
Timestamp:
20.04.2013 17:04:09 (7 years ago)
Author:
jri
Comment:

The service interface

Legend:

Unmodified
Added
Removed
Modified
  • PluginDevelopmentGuide

    v19 v20  
    726726 
    727727A [[DeepaMehtaCoreEvents|list of all DeepaMehta Core events]] is available in the reference section. 
     728 
     729=== Providing a service === 
     730 
     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). 
     732 
     733==== The service interface ==== 
     734 
     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. 
     736 
     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`. 
     738 
     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. 
     740 
     741As an example look at the //Topicmaps// plugin (part of the DeepaMehta Standard Distribution): 
     742 
     743{{{ 
     744#!txt 
     745dm4-topicmaps/ 
     746    src/ 
     747        main/ 
     748            java/ 
     749                de/ 
     750                    deepamehta/ 
     751                        plugins/ 
     752                            topicmaps/ 
     753                                service/ 
     754                                    TopicmapsService.java 
     755}}} 
     756 
     757The service interface of the //Topicmaps// plugin is named `TopicmapsService`. The plugin package is `de.deepamehta.plugins.topicmaps`. 
     758 
     759The //Topicmaps// service interface looks like this: 
     760 
     761{{{ 
     762#!java 
     763package de.deepamehta.plugins.topicmaps.service; 
     764 
     765import de.deepamehta.plugins.topicmaps.TopicmapRenderer; 
     766import de.deepamehta.plugins.topicmaps.model.ClusterCoords; 
     767import de.deepamehta.plugins.topicmaps.model.Topicmap; 
     768 
     769import de.deepamehta.core.Topic; 
     770import de.deepamehta.core.service.ClientState; 
     771import de.deepamehta.core.service.PluginService; 
     772 
     773 
     774 
     775public interface TopicmapsService extends PluginService { 
     776 
     777    Topic createTopicmap(String name,             String topicmapRendererUri, ClientState clientState); 
     778    Topic createTopicmap(String name, String uri, String topicmapRendererUri, ClientState clientState); 
     779 
     780    // --- 
     781 
     782    Topicmap getTopicmap(long topicmapId, ClientState clientState); 
     783 
     784    // --- 
     785 
     786    void addTopicToTopicmap(long topicmapId, long topicId, int x, int y); 
     787 
     788    void addAssociationToTopicmap(long topicmapId, long assocId); 
     789 
     790    void moveTopic(long topicmapId, long topicId, int x, int y); 
     791 
     792    void setTopicVisibility(long topicmapId, long topicId, boolean visibility); 
     793 
     794    void removeAssociationFromTopicmap(long topicmapId, long assocId); 
     795 
     796    void moveCluster(long topicmapId, ClusterCoords coords); 
     797 
     798    void setTopicmapTranslation(long topicmapId, int trans_x, int trans_y); 
     799 
     800    // --- 
     801 
     802    void registerTopicmapRenderer(TopicmapRenderer renderer); 
     803} 
     804}}} 
     805 
     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`.