| 728 | |
| 729 | === Providing a service === |
| 730 | |
| 731 | Your 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 | |
| 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. |
| 736 | |
| 737 | The 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 | |
| 739 | The 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 | |
| 741 | As an example look at the //Topicmaps// plugin (part of the DeepaMehta Standard Distribution): |
| 742 | |
| 743 | {{{ |
| 744 | #!txt |
| 745 | dm4-topicmaps/ |
| 746 | src/ |
| 747 | main/ |
| 748 | java/ |
| 749 | de/ |
| 750 | deepamehta/ |
| 751 | plugins/ |
| 752 | topicmaps/ |
| 753 | service/ |
| 754 | TopicmapsService.java |
| 755 | }}} |
| 756 | |
| 757 | The service interface of the //Topicmaps// plugin is named `TopicmapsService`. The plugin package is `de.deepamehta.plugins.topicmaps`. |
| 758 | |
| 759 | The //Topicmaps// service interface looks like this: |
| 760 | |
| 761 | {{{ |
| 762 | #!java |
| 763 | package de.deepamehta.plugins.topicmaps.service; |
| 764 | |
| 765 | import de.deepamehta.plugins.topicmaps.TopicmapRenderer; |
| 766 | import de.deepamehta.plugins.topicmaps.model.ClusterCoords; |
| 767 | import de.deepamehta.plugins.topicmaps.model.Topicmap; |
| 768 | |
| 769 | import de.deepamehta.core.Topic; |
| 770 | import de.deepamehta.core.service.ClientState; |
| 771 | import de.deepamehta.core.service.PluginService; |
| 772 | |
| 773 | |
| 774 | |
| 775 | public 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 | |
| 806 | You 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`. |