Skip to content

Introduction Extension Developers

Dr. Jawa edited this page Nov 6, 2013 · 28 revisions

You are a Cartridge Extension Developer if...

  • You are a cartridge developer and at the same time you want to offer all other cartridge developers a way to extend your cartridge. For example you are doing a JPA cartridge and you want to offer to all other cartridge developers to extend your JPA cartridge by adding JPA provider - Hibernate, OpenJPA or EclipseLink - specific extensions.

What are your steps to create extensions for a cartrige in KissMDA?

  • KissMDA Core offers an Event Bus running as singleton already instantiated in the core framework (CoreModule).
  • To be able to offer extensions you just simply add an Event to your cartridge, trigger this in the right place and publish it to the Event Bus.
  • As a Cartridge Extension Developer you just need to register some handlers to the Event Bus which will be called if the corresponding events are triggered.
  • Important to remember Extension is just a normal KissMDA Cartridge. You will be able to write your own cartridge and the same time:
    • offer some extensions for other cartridges (= Events published) or
    • handles and reacts to some events which are published by other cartridges (= Events handled).
  • To use them in your application is a matter of configuring the KissMDA Maven plugin:
    • The order is important, you have to register the handlers before the events are triggered. In this example below we register ExtensionExamplesTransformer (number == 1) first, since it will register some handlers which react to the events triggered by the second Cartridge SimpleJavaTransformer (number == 2).
...
<configuration>
  <transformerNameWithOrders>
    <!-- You put the transformers with order -->
    <transformerNameWithOrder>
      1:de.crowdcode.kissmda.cartridges.extensions.ExtensionExamplesTransformer
    </transformerNameWithOrder>
    <transformerNameWithOrder>
      2:de.crowdcode.kissmda.cartridges.simplejava.SimpleJavaTransformer
    </transformerNameWithOrder>
  </transformerNameWithOrders>
  <modelFile>src/main/resources/model/emf/test-uml.uml</modelFile>
  <loggingLevel>SEVERE</loggingLevel>
</configuration>
...

Do we have an example of extensions which powered by KissMDA?

public class TypesExtensionHandler {
    @Inject
    private DataTypeUtils datatypeUtils;

    @Subscribe
    public void onJavaTypeCodesCreated(JavaTypeCodesCreatedEvent event) {
        Map<String, String> javaTypeCodes = event.getJavaTypeCodes();
        javaTypeCodes.put("test", "de.test.Test");
        // Now check the real content of datatypeUtils
        // This must be the same as the javaTypeCodes above!
        logger.log(Level.SEVERE, "Java types real content " + datatypeUtils.getJavaTypes());
    }
}

...

public class ExtensionExamplesTransformer implements Transformer {
    @Inject
    private EventBus eventBus;
    @Inject
    private TypesExtensionHandler typesExtensionHandler;
...
    private void registerHandlers() {
        eventBus.register(typesExtensionHandler);
    }

    public void transform(Context context) throws TransformerException {
        // Register event handlers
        registerHandlers();
    }
}
...
    @Inject
    private EventBus eventBus;

...
        // Publish an event to the bus
        eventBus.post(new JavaTypeCodesCreatedEvent(javaTypes));
...
  • Here is the application which uses the extensions: kissmda-app-test. Take a look at the pom.xml file which is already explained above.