Open in new window

back

Setting Up a Custom POJO Renderer

In order to set up a custom POJO renderer, we first need to create an extension point. An extension point is the mechanism by which one plug-in can add to the functionality of another.

  1. First you have to create a plug-in project.Open the plugin.xml manifest file and switch to the Dependencies page. Here you have to add the dependencies next:

    codeRenderers

  2. Switch to the Extensions page. The page lists all extension points used by this plug-in.
    Press the "Add" button and select the extension "com.exadel.orm2.core.codeRenderers"

    codeRenderers

  3. You should now see the com.exadel.orm2.core.codeRenderers extension point listed in your Extensions page.
    Right-click on it and select New->code_renderer

    codeRenderers

    Doing so creates an object under the extension with a default name like com.exadel.orm2.sample.code_renderer2

    codeRenderers

    Set the name and change the id in the properties for this object.

  4. Select the class property and click the Selection button to bring up the Java Class Selection dialog. Click Finish, and then press Ctrl-S to save.

    codeRenderers

  5. Switch to the Extensions page. You then need to select the package that contains this class.

    codeRenderers

  6. After that you have to deploy this plug-in. Select File-> Export, and then select the "Deployable plug-ins and fragments" item in the Export dialog. You can deploy plug-ins as either .jar or .zip files. Here, we'll deploy both plug-ins in a .zip file. Enter the fully qualified name of the .zip file and unzip that file in the Eclipse distribution directory.

  7. You don't have to implement all interface methods. You can use the default implementation and override only certain methods. To do this just make the generated class a descendant of com.exadel.orm2.core.CodeRendererService and change the generated import:

    Now you can safely delete all methods, that you are not going to override, in fact, you must. Imagine that you want to generate persistent classes to be instances of the Comparable interface. No problem! Here is the code that'll do that task for you:

    The createType method is overridden here to add Comparable to the array of interfaces to implement (only for primary types, but not for inner ones), then the default implementation is invoked by super.createType call. Exadel Studio automatically generates all the necessary method stubs for implemented interfaces.
  8. After that you can use this created extension point for a custom POJO renderer. If you create a new Java project and after that you add "Hibernate Capabilities", you can then select your created class.

    codeRenderers

back