This tutorial lets you create a module which defines a way to add a service to the IDE's lookup system using an XML file. In this simple case, the interface that will be provided is java.awt.Shape. The actual objects will be quad curves with parameters defined by the XML file. You will see both how to define the XML format and translate it into a live Java object, and how to register such services.

  1. Create a module JAR and prepare a package for it as described above.
  2. Create a new Templates | NetBeans Extensions | Services API | XML Processor. Give it some name, for example org.yourorg.QuadCurveXMLProcessor.
  3. In this example, you will not need to change anything in the source file for the processor, as it already demos making instances of quad curves. In real usage, replace areas that say CHANGEME and look at other sources too to see if some customization is needed.
  4. Create an XML Layer (Empty) from template and place in your module package. Copy it and then Paste it beneath Layer in your module JAR to add it to the module manifest.
  5. Edit the XML layer as text. Find the example layer contents in the XML processor source and copy them (the part inside the <filesystem> element) into your layer.
  6. Create a new DTD for the XML format and place it in the same folder as the layer. For example, Templates | Other | Text File and choose the name some_description-1_0 in the second panel and the extension dtd in the third. The file name you create should match the url="..." in the layer. Here is a DTD:
    <!ELEMENT quadcurve EMPTY>
    <!ATTLIST quadcurve
              x1    CDATA #REQUIRED
              y1    CDATA #REQUIRED
              x2    CDATA #REQUIRED
              y2    CDATA #REQUIRED
              ctrlx CDATA #REQUIRED
              ctrly CDATA #REQUIRED
    >
    
    (Registering the DTD is not strictly necessary. But if an XML editing module is installed, having the DTD available locally and registered by its public ID will mean that structure editing will be possible on it without making a network connection. So it is always a good habit to keep the IDE's internal entity catalog current this way.)
  7. Check carefully that the instance file under xml/lookups/ is named according to your public ID and the instanceClass points to your processor class. If the ID is mistyped, the processor will never be used.
  8. Now let's register a sample shape using the processor. Any other module could do the same; we will just register one to test the processor. Add the following to the layer (inside the top-level <filesystem> element):
    <folder name="Services">
        <folder name="Hidden">
            <file name="org-yourorg-sample-shape.xml"
                  url="sample-shape.xml"/>
        </folder>
    </folder>
    
    You also need to make the XML file, in this case in the same folder as the layer, and named sample-shape.xml (you can use the text file template again and choose the extension xml - be careful not to add it to the list of general extensions for text files though):
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE quadcurve PUBLIC
        "-//Your Org//DTD Some Description 1.0//EN"
        "http://yourorg.org/dtds/some_description-1_0.dtd">
    <quadcurve x1="0" y1="0" x2="100" y2="100"
               ctrlx=".5" ctrly=".5"/>
    
    It is important that there be a DOCTYPE and that the public ID match what you registered.
  9. The module should be ready. Install it by executing the JAR file. There will be no immediately visible effect (other than a message saying the module was installed).
  10. We will use the API Support to confirm that there is really a quad curve available in lookup. Go to the Runtime tab and on Bean Browser | Lookup results, right-click and select Add Superclass/interface. When prompted for an interface class, type java.awt.Shape (we will look for all shapes registered in lookup). You should see one QuadCurve2D$Float.