Changes between Version 6 and Version 7 of AnotherPluginDevelopmentGuide
- Timestamp:
- 09.07.2012 17:01:53 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AnotherPluginDevelopmentGuide
v6 v7 8 8 DeepaMehta provides a framework for the plugin developer which has: 9 9 10 * Access to the DeepaMehta Core service.10 * Access to the [http://www.deepamehta.de/apidocs/deepamehta/4.0.12/de/deepamehta/core/service/DeepaMehtaService.html DeepaMehtaService]. 11 11 * OSGi handling. 12 12 * Migration management. … … 266 266 267 267 Real migrations of existing data can be written in Java, you have fully access 268 to the DeepaMehtaService.268 to the [http://www.deepamehta.de/apidocs/deepamehta/4.0.12/de/deepamehta/core/service/DeepaMehtaService.html DeepaMehtaService]. 269 269 270 270 Programmatic plugin migration example: … … 342 342 var name = prompt('Example name', 'Another Example') 343 343 topic = dm4c.restc.request('POST', '/example/create', { name: name }) 344 dm4c.canvas.add_topic(topic, true) 345 dm4c.do_select_topic(topic.id) 344 dm4c.show_topic(topic, 'show', null, true) 346 345 } 347 346 … … 350 349 var url = '/example/increase/' + dm4c.selected_object.id, 351 350 topic = dm4c.restc.request('GET', url) 352 dm4c.canvas.update_topic(topic, true) 353 dm4c.do_select_topic(topic.id) 351 dm4c.show_topic(topic, 'show', null, true) 354 352 } 355 353 356 354 // define type specific commands and register them 357 dm4c. register_listener('topic_commands', function (topic) {355 dm4c.add_listener('topic_commands', function (topic) { 358 356 return topic.type_uri !== 'dm4.example.type' ? [] : [{ 359 357 context: ['context-menu', 'detail-panel-show'], … … 362 360 }) 363 361 364 // register a additional create command365 dm4c. register_listener("post_refresh_create_menu", function(type_menu) {362 // register an additional create command 363 dm4c.add_listener("post_refresh_create_menu", function(type_menu) { 366 364 type_menu.add_separator() 367 365 type_menu.add_item({ label: "New Example", handler: createAnotherExample }) … … 575 573 == Plugin == #plugin 576 574 577 A Java plugin can interact with predefined hook overwrites and export a OSGi service 578 with optional REST exposure. 579 580 All public methods of the plugin must be described in a service interface: 575 A Java plugin can interact by implementing of listener and export a OSGi service 576 with optional REST exposure. The listener contain topic CRUD (create, retype, update, delete) 577 interaction and plugin lifecycle management, see package 578 [http://www.deepamehta.de/apidocs/deepamehta/4.0.12/de/deepamehta/core/service/listener/package-summary.html de.deepamehta.core.service.listener]. 579 580 All public methods of your plugin service must be described in a service interface that extends 581 [http://www.deepamehta.de/apidocs/deepamehta/4.0.12/de/deepamehta/core/service/PluginService.html PluginService]: 581 582 {{{#!java 582 583 package de.deepamehta.plugins.example.service; … … 596 597 }}} 597 598 598 '''TBD''' rewrite hook calls in favour of listener interface per event 599 600 The plugin itself can expose methods with 601 [http://jersey.java.net/nonav/documentation/latest/jax-rs.html JAX-RS] annotations:599 600 Implementing a plugin requires a derivation of 601 [http://www.deepamehta.de/apidocs/deepamehta/4.0.12/de/deepamehta/core/osgi/PluginActivator.html PluginActivator], 602 the plugin itself can expose methods with [http://jersey.java.net/nonav/documentation/latest/jax-rs.html JAX-RS] annotations: 602 603 {{{#!java 603 604 package de.deepamehta.plugins.example; 604 605 605 606 import java.util.logging.Logger; 606 import javax.ws.rs.*; 607 608 import javax.ws.rs.GET; 609 import javax.ws.rs.HeaderParam; 610 import javax.ws.rs.POST; 611 import javax.ws.rs.Path; 612 import javax.ws.rs.PathParam; 613 import javax.ws.rs.Produces; 614 import javax.ws.rs.WebApplicationException; 607 615 608 616 import de.deepamehta.core.model.TopicModel; 617 import de.deepamehta.core.osgi.PluginActivator; 609 618 import de.deepamehta.core.service.ClientState; 610 import de.deepamehta.core.service. Plugin;619 import de.deepamehta.core.service.listener.PreCreateTopicListener; 611 620 import de.deepamehta.plugins.example.model.Example; 612 621 import de.deepamehta.plugins.example.model.ExampleTopic; … … 615 624 @Path("/example") 616 625 @Produces("application/json") 617 public class ExamplePlugin extends Plugin implements ExampleService { 626 public class ExamplePlugin extends PluginActivator implements ExampleService, 627 PreCreateTopicListener { 618 628 619 629 private Logger log = Logger.getLogger(getClass().getName()); … … 624 634 */ 625 635 @Override 626 public void preCreateHook(TopicModel model, ClientState clientState) { 627 if (model.getTypeUri().equals(ExampleTopic.TYPE)) { 628 log.info("init Example count of " 629 + model.getCompositeValue().getString(ExampleTopic.NAME)); 630 model.getCompositeValue().put(ExampleTopic.COUNT, 0); 636 public void preCreateTopic(TopicModel model, ClientState clientState) { 637 if (model.getTypeUri().equals(ExampleTopic.COUNT)) { 638 log.info("init Example count"); 639 model.setSimpleValue(0); 631 640 } 632 641 } 633 642 634 643 /** 635 * Creates a new <code>Example</code> instance based on 636 * <code>ExampleTopic</code> model.644 * Creates a new <code>Example</code> instance based on the domain specific 645 * REST call with a alternate JSON topic representation. 637 646 */ 638 647 @POST … … 649 658 650 659 /** 651 * Increase the count of a attached <code>Example</code> topic.660 * Increase the count of an attached <code>Example</code> topic. 652 661 */ 653 662 @GET