Wednesday, June 11, 2008

Mule and IntelliJ IDEA

As some may know, we are working on version 2.0 of our open source Mule IDE based on eclipse. However, with the new schema-based configuration in Mule, IntelliJ IDEA users (including me) get some great features to help them build mule applications quicker too.

In the most recent IntelliJ 7.0.4 EAP release they have fixed the XML editor so the full benefits of the Mule schemas can be realised. I'd like to thank the IntelliJ guys for this fix. It took them less than a month from us reporting the issue to them fixing it and doing a release. I think thats pretty fantastic!

Quick Introduction


Mule 2.0 XML configurations are defined in schemas. For every module and transport in Mule there is a schema that defines the configuration elements that can be used. For example the following defines the Mule schema (default namespace), the VM transport and the Quartz connector:


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.0"
xmlns:quartz="http://www.mulesource.org/schema/mule/quartz/2.0"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/quartz/2.0 http://www.mulesource.org/schema/mule/quartz/2.0/mule-quartz.xsd
http://www.mulesource.org/schema/mule/vm/2.0 http://www.mulesource.org/schema/mule/vm/2.0/mule-vm.xsd
http://www.mulesource.org/schema/mule/core/2.0 http://www.mulesource.org/schema/mule/core/2.0/mule.xsd">

</mule>



Essentially the schemas in Mule 2.0 provide an XML Domain Specific Language (DSL) for constructing integrations and service compositions. The benefits of this approach over the Mule 1.x approach is that:

  • there no longer class names in XML configuration files (unless you are plugging in a custom implementation)

  • all available attributes for a configuration element are provided in the schema and which gives you auto-complete in many Xml editors. Previously, developers had to look at the documentation or JavaDoc to figure out what properties to set

  • required elements and attributes are validated and enforced by the schema

  • attributes are typed making validation more robust



When editing a Mule Xml in IntelliJ IDEA, you will get full code-complete for the modules imported into your XML file:





While you are filling out the details of your connector you can quickly get help about the attribute you are adding by hitting Apple Key+J or Ctrl+J on Windows and you will get context help on that attribute.



The context help also works on configuration elements:



Unfortunately, these features do not currently work with Eclispe unless you are using the Altova Xml Spy Eclipse plugin or Oxygen Xml for Eclipse.

Creating new Mule XML files can be labourious since you need to define the namespaces and schema locations each time. You can greatly simplify this in IntelliJ IDEA by using ‘Live Templates’ (from the Options dialog). Live Templates are code snippets that can be inserted into any editor window simply by typing an abbreviation and hitting the Tab key. I have lots of templates set up but 3 are useful for creating new Mule configurations:

1. Mule Xml Configuration Template [m2]


This can be used in a blank XML document.





1. New Namespace [ns]


Use this to add a new schema namespace. When the template is inserted you just need to type the Mule module name , i.e. ‘jms’ or ‘http’ and then hit the Enter key.



1. New Schema Location [sl]


Use this to add a new schema location. When the template is inserted you just need to type the Mule module name , i.e. ‘jms’ or ‘http’ and then hit the Enter key.

0 comments: