XSL Basic Training 27./28. September 2010 in Böblingen, Germany

May 27th, 2010

This is something mainly for german-speaking people who are interested
in learning about document production with XSLT and XSL-FO. I’ll be
giving a two-day training on the basics of XSLT and XSL-FO during the
27./28. September 2010. The workshop is hosted and organized by Compart
Deutschland GmbH in Böblingen, Germany. More information is available on
their website (in German):
http://www.compart.net/cms/index.php?page=EX-W1030_de

Two days are quite short for that amount of information so the workshop
is quite intensive, but the feedback from past workshops was very
positive.

BTW, I’m happy to give this training (available in German or English) at
a location of your choosing (preferably within Europe). Let me know if
you are interested.

OSGi Declarative Services: Configuring multiple instances of a component

April 22nd, 2010

Declarative Services are a nice way to create services in the OSGi environment, but there are some subtleties that are not always easy to get under control. Imagine you have a component that observes a directory and acts on the presence of new files (a “hotfolder”, much like the Apache Felix FileInstall bundle). You may have multiple such directories which you want to observe, which you want to configure. You could create a ManagedServiceFactory but there’s a simpler way with Declarative Services once you’ve figured out the subtleties.
Let’s first define a very simple service interface:

public interface Greeter {
    void sayHello();
}

Then let’s implement this interface:

public class GreeterImpl implements Greeter {

    private ComponentContext context;

    protected void activate(ComponentContext context) {
        this.context = context;
        System.out.println("Creating new greeter for " + getName()
                + ": " + context.getComponentInstance().toString());
    }

    protected void deactivate(ComponentContext context) {
        System.out.println("Deactivating greeter for " + getName()
                + ": " + context.getComponentInstance().toString());
        this.context = null;
    }

    public void sayHello() {
        System.out.println("Hello, I'm " + getName());
    }

    private String getName() {
        return (String)this.context.getProperties().get("name");
    }

}

Through the activate(ComponentContext) method, we’ll get the component’s configuration once an instance is activated.
Now, we need the component descriptor for our Greeter component (OSGI-INF/component.xml):

<?xml version="1.0" encoding="UTF-8"?>
<component name="demo.scr.componentfactory.greeter">
  <!-- No factory attribute here! -->
  <implementation class="demo.scr.componentfactory.impl.GreeterImpl"/>
  <service>
    <provide interface="demo.scr.componentfactory.Greeter"/>
  </service>
  <property name="service.description"
      value="A nice component that can say hello"/>
</component>

If you know a little bit about Declarative Services, you might at first expect a factory attribute on the component, since we’re going to create multiple instances, but it would really just wrong with the approach I’m showing here. The final missing clue to make this work with multiple configurations lies with the MetaType descriptor we need to build (OSGI-INF/metatype/metatype.xml):

<?xml version="1.0" encoding="UTF-8"?>
<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"
    localization="OSGI-INF/metatype/metatype">
  <metatype:OCD id="demo.scr.componentfactory.greeter"
      name="SCR Component Factory Demo">
    <metatype:AD id="name" type="String"
        name="%name.name" description="%name.desc"/>
  </metatype:OCD>
  <metatype:Designate pid="demo.scr.componentfactory.greeter"
      factoryPid="demo.scr.componentfactory.greeter">
    <metatype:Object ocdref="demo.scr.componentfactory.greeter"/>
  </metatype:Designate>
</metatype:MetaData>

Note especially the “Designate” Element which has both a “pid” and a “factoryPid” attribute. The important part is the “factoryPid” attribute which will enable the desired “factory” functionality.
If you want, a properties file with the translations (OSGI-INF/metatype/metatype.properties):

name.name=Name
name.desc=The name. D'oh!

Just for completeness and illustration, here’s the effective bundle manifest:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DemoScrComponentFactory
Bundle-SymbolicName: demo.scr.componentfactory
Bundle-Version: 1.0.0
Export-Package: demo.scr.componentfactory
Import-Package: org.osgi.framework,
 org.osgi.service.cm,
 org.osgi.service.component,
Service-Component: OSGI-INF/component.xml

If you deploy the resulting bundle in Felix, for example, you should see our new component in the dropdown list of factory configurations on the configuration page of Felix’s WebConsole.
Besides the UI in the WebConsole, you can also use Apache Felix FileInstall’s configuration feature. Just create a properties file (ex. “demo.scr.componentfactory.greeter-C3PO.cfg”) in the directory observed by FileInstall:

name=C3PO, human cyborg relations

Just use the component’s PID followed by a dash and a name of your choosing. You can create as many configuration files as you like. For each one, SCR will create a service for you.

Update, 2010-05-19:
There may be a little problem with the above. If there are no configurations in ConfigurationAdmin, one component instance will still always be activated which may have unwanted side-effects if your component depends on certain values in the configuration. If you experience that, you can switch to the version 1.1 of Declarative Services and use the configuration policy to control this. The following example will require at least one configuration in the ConfigurationAdmin before the component is activated:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
    name="demo.scr.componentfactory.greeter"
    configuration-policy="require">
[..]
</scr:component>

ATM hanging at startup

November 9th, 2009

Seen in Lucerne last Saturday (2009-11-07). It was still like this when I came by again 8 hours later in the evening. I don’t think any comment is necessary. ;-)

ATM running Windows 2000 hangs on startup

Thanks to Jürgen for pointing this out to me!

DocBook is fun!

June 4th, 2009

I’m currently writing a basic XSL training course which I’ll give the first time later this month. I decided to write the training materials using DocBook 5. Lots of XML examples, lots of SVG illustrations painted in Inkscape. I used the DocBook editing capability of my OxygenXML editor. Finally, I’ve customized the DocBook XSL stylesheets a bit, added syntax highlighting using XSLTHL and used Apache FOP (SVN Trunk) to create the PDF.

I must say: it was simply fun to work with this setup. DocBook is well documented. The documentation always had an option for all of my wishes. No wasted time, no crashes, no despair (I pity those who do this with MS Word). I can only recommend to do any larger documentation work like this.

Specifying Classpaths

December 4th, 2008

Java is great. Really. But there are sometimes subtleties that need to be kept in mind as I had to find out in the last few days once more. After looking in all the wrong places, that is. I’m talking about specifying a classpath. Multiple entries on the classpath are delimited by a separator but that separator is not always the same:

  • JVM Classpath on Windows (semicolon): “-cp my1.jar;my2.jar”
  • JVM Classpath on Unix (colon): “-cp my1.jar:my2.jar”
  • Class-Path entry in a JAR manifest (space): “Class-Path: my1.jar my2.jar”
  • OSGi’s Bundle-Classpath entry in a bundle manifest (comma): “Bundle-Classpath: .,META-INF/lib/my1.jar,META-INF/lib/my2.jar”

I’m sure someone will eventually come up with yet another separator for classpath entries.

IBM and Sun launch ODF Toolkit

November 5th, 2008

With pleasure I learned today that IBM and Sun together launched http://odftoolkit.org/. It is at least partly seeded with code from Sun’s OpenOffice (namely the ODF Toolkit project). Initial components include ODFDOM (a low-level ODF API) and an ODF validator. Another very pleasant surprise is the publication of the source code under the liberal Apache License V2.0. Congratulations to the people involved!

This will make especially ODFDOM interesting for Apache FOP.  One of the missing puzzle pieces in FOP surely is an ODF output plug-in to replace the RTF format in the long run. Somehow I’ve got the feeling that we won’t have to wait all too long for that… ;-)

So Mars is now called PDFXML

September 17th, 2008

Matthew Hardy announced a new prerelease of the PDFXML Plug-in für Adobe Acrobat 9. PDFXML used to be called Mars and is a XML-friendly representation of PDF (borrowing heavily on SVG). Now only the project itself is still called Mars. I wonder if this is an indicator that Adobe will put more energy into promoting this new format in the future. I’ve already blogged about it some time ago.

Barcode4J 2.0 released

May 15th, 2008

I let it slide for too long but now, Barcode4J 2.0 is finally available. Since the last alpha release I’ve been able to fix a number of bugs in DataMatrix and PDF417. As a last-minute addition I’ve added support for the USPS Intelligent Mail Barcode of which you can see an example below.

USPS Intelligent Mail Barcode Example

There’s also a detailed list of changes for this release.

5-minute breaks in Balconia

May 8th, 2008

The Clematis on my balcony is in full bloom again. In the background, mount Pilatus still has a little bit of snow. But it’s getting less every day.

My clematis in the foreground in full bloom, mount Pilatus in the background

On days like today, it is really hard after a 5-minute break in Balconia to go back into the home office just because the notebook display isn’t bright enough to work outside. Sigh.

Travelling to ApacheCon – something’s wrong

March 30th, 2008

I’ve been to Amsterdam a number of times and will go there again for ApacheCon EU 2008. I always took the train or night train. So, nine days before departure I look again into the best way to get there and back. But despite all the discussions about CO2 and all that, something is still very wrong with the picture I have to paint…

Read the rest of this entry »