<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeremias Märki, Software Development and Consulting</title>
	<atom:link href="http://www.jeremias-maerki.ch/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeremias-maerki.ch/wordpress</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 09:30:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>JAX-RS applications in OSGi &#8211; whiteboard style</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2011/08/20/jaxrs-applications-in-osgi-whiteboard-style/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2011/08/20/jaxrs-applications-in-osgi-whiteboard-style/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 10:30:54 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[JAX-RS]]></category>
		<category><![CDATA[Whiteboard Pattern]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/?p=77</guid>
		<description><![CDATA[There are various ways to publish a JAX-RS application when running inside OSGi. Some use Blueprint or Spring, and I&#8217;m sure there are other methods. I&#8217;d like to show how you can publish JAX-RS applications using the whiteboard pattern. The<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2011/08/20/jaxrs-applications-in-osgi-whiteboard-style/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>There are various ways to publish a JAX-RS application when running inside OSGi. Some use Blueprint or Spring, and I&#8217;m sure there are other methods. I&#8217;d like to show how you can publish JAX-RS applications using the <a href="http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf">whiteboard pattern</a>.</p>
<p><span id="more-77"></span>The nice thing about JAX-RS is that it offers the abstract &#8220;Application&#8221; class. So, why not just put your application in the OSGi service registry? That&#8217;s very simple and you don&#8217;t need to know anything about the JAX-RS implementation. Let someone else worry about how to get the JAX-RS application into the web container at the right place. Here&#8217;s how your Application subclass could look like:</p>
<p>&nbsp;</p>
<pre>public class ContentRepositoryApplication extends Application {

    private static final Set&lt;Class&lt;?&gt;&gt; CLASSES
        = new java.util.HashSet&lt;Class&lt;?&gt;&gt;();

    static {
        CLASSES.add(RootResource.class);
        CLASSES.add(DocumentMetadataResource.class);
        CLASSES.add(DocumentResource.class);
        CLASSES.add(RepositoryResource.class);
        CLASSES.add(URIMessageBodyWriter.class);
    }

    @Override
    public Set&lt;Class&lt;?&gt;&gt; getClasses() {
        return CLASSES;
    }
}</pre>
<p>&nbsp;</p>
<p>I&#8217;d like to demonstrate how to do the publishing part with <a href="http://jersey.java.net/">Jersey</a> (the reference implementation). It&#8217;s particularly easy with this one. Actually, I&#8217;ve tried and failed with both <a href="http://cxf.apache.org/docs/restful-services.html">Apache CXF</a> and <a href="http://incubator.apache.org/wink/">Apache Wink (Incubating)</a>, probably mostly for lack of in-depth knowledge on how to build a servlet instance from an Application instance.</p>
<p>What we need is simply a ServiceTracker that tracks Application services in the OSGi registry. Whenever a new Application becomes available, build a servlet for it and register that with the OSGi registry. A whiteboard-capable web container can then pick up the servlet and expose it. The code is quite straight-forward:</p>
<p>&nbsp;</p>
<pre>package ch.jm.rest.jersey;

import java.util.Dictionary;
import java.util.Hashtable;

import javax.servlet.Servlet;
import javax.ws.rs.core.Application;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

import com.sun.jersey.spi.container.servlet.ServletContainer;

/**
 * Bundle activator for the Jersey-based JAX-RS Application deployer. It tracks all JAX-RS
 * {@link Application} services and publishes a servlet for each of them. The "alias" service
 * property is propagated to the servlet service so you can control the endpoint for the JAX-RS
 * service. This follows the whiteboard pattern. Similarly, we publish servlet services
 * in whiteboard style.
 */
public class Activator implements BundleActivator {

    private Log log = LogFactory.getLog(Activator.class);

    private BundleContext context;
    private ServiceTracker tracker;

    /** {@inheritDoc} */
    public void start(BundleContext context) throws Exception {
        this.context = context;

        //Track all JAX-RS Applications
        this.tracker = new ServiceTracker(context,
            Application.class.getName(), new Customizer());
        this.tracker.open();
    }

    /** {@inheritDoc} */
    public void stop(BundleContext context) throws Exception {
        this.tracker.close();
        this.tracker = null;
        this.context = null;
    }

    private class Customizer implements ServiceTrackerCustomizer {

        private Dictionary createProps(ServiceReference reference) {
            String alias = reference.getProperty("alias").toString();
            if (log.isDebugEnabled()) {
                log.debug("Alias: " + alias);
            }

            Dictionary props = new Hashtable();
            props.put("alias", alias);
            return props;
        }

        /** {@inheritDoc} */
        public Object addingService(ServiceReference reference) {
            Application app = (Application)context.getService(reference);
            if (log.isDebugEnabled()) {
                log.debug("Adding JAX-RS application: " + app);
            }

            //For each JAX-RS Application, create a servlet wrapping that Application instance
            ServletContainer servlet = new ServletContainer(app);

            Bundle sourceBundle = reference.getBundle();
            BundleContext sourceContext = sourceBundle.getBundleContext();
            ServiceRegistration reg = sourceContext.registerService(
                    Servlet.class.getName(), servlet, createProps(reference));

            return reg;
        }

        /** {@inheritDoc} */
        public void modifiedService(ServiceReference reference, Object service) {
            ServiceRegistration reg = (ServiceRegistration)service;
            if (log.isDebugEnabled()) {
                log.debug("Modifying JAX-RS application: " + reg);
            }
            reg.setProperties(createProps(reference));
        }

        /** {@inheritDoc} */
        public void removedService(ServiceReference reference, Object service) {
            ServiceRegistration reg = (ServiceRegistration)service;
            if (log.isDebugEnabled()) {
                log.debug("Removing JAX-RS application: " + reg);
            }
            reg.unregister();
            context.ungetService(reference);
        }

    }

}</pre>
<p>&nbsp;</p>
<p>Please note how the servlet service is published under the BundleContext of the bundle that published the Application service. That&#8217;s not really necessary but keeps things in their context.</p>
<p>That&#8217;s all I put in that deployer bundle, just this BundleActivator. That already does the whole job in the Jersey case.</p>
<p>This approach may not work for everyone. Like with the whiteboard approach for servlets, there may be some restrictions of what you can do. But so far it has served me well.</p>
<p>One catch I ran into was multipart support. The old story. I was forced to introduce a hard dependency on Jersey&#8217;s multipart support in one of my JAX-RS applications. Unfortunately, Jersey Core 1.5 exports the JAX-RS API directly instead of in a separate bundle, and hasn&#8217;t assigned versions to exported packages. That would make it difficult to use its multipart support with Apache CXF (it properly imports the JAX-RS API with a version range). Maybe I should look at doing it the other way around (use CXF&#8217;s multipart with Jersey). But to deploy the huge CXF package including dependencies just for getting multipart support (as long as I don&#8217;t manage to create a JAX-RS servlet) is probably not the best of ideas. BTW, the problem with CXF is that I didn&#8217;t find a way to instantiate/configure the servlet without having to rely on web-inf.xml for the initialization parameters. Probably just lack of knowledge. If you have a suggestion, I&#8217;m all ears.</p>
<p>I think it would be cool if all JAX-RS implementations that strive to be OSGi-compatible implemented such a whiteboard support for JAX-RS Applications. All you have to do as a user is register your Application object with the OSGi registry. Ideally, you don&#8217;t have a dependency on any JAX-RS implementation. I&#8217;m still hoping for that multipart support in the next JAX-RS API version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2011/08/20/jaxrs-applications-in-osgi-whiteboard-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OSGi Bundle Utility 1.0 released</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2010/11/18/osgi-bundle-utility-1-0-released/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2010/11/18/osgi-bundle-utility-1-0-released/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 14:02:05 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OSGi]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/?p=73</guid>
		<description><![CDATA[Writing OSGi bundle manifests by hand is nothing anyone wants to do, although some entries will always need to be added explicitely. The most prominent of tools for automatically getting imports and exports right is Peter Kriens&#8217; Bnd. However, I<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2010/11/18/osgi-bundle-utility-1-0-released/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>Writing OSGi bundle manifests by hand is nothing anyone wants to do, although some entries will always need to be added explicitely. The most prominent of tools for automatically getting imports and exports right is <a href="http://www.aqute.biz/Code/Bnd">Peter Kriens&#8217; Bnd</a>. However, I found Bnd difficult to manage and to get to work right with <a href="http://ant.apache.org/">Apache Ant</a>. I wanted something simpler because in most cases, you don&#8217;t need all the flexibility Bnd provides. Finally, I wanted the bundle descriptor to be written in XML. So, I wrote my own tool. It turned out to work quite well, and it was a good way for me to learn more about OSGi. I&#8217;ve finally taken some time to document it and make it available to anyone interested. Please note that it does not aim to handle all possible cases. The idea is to follow the 80:20 rule to ensure ease of use for most use cases.</p>
<p>So, if you produce OSGi bundles using <a href="http://ant.apache.org/">Apache Ant</a> and you&#8217;re not quite happy with Bnd or writing bundle metadata by hand, my <a href="http://www.jeremias-maerki.ch/development/osgi/bundle-utility.html">OSGi Bundle Utility</a> might be something for you. The utility is published under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License v2.0</a>. Source and Binary distributions and documentation is <a href="http://www.jeremias-maerki.ch/development/osgi/bundle-utility.html">available here</a>.</p>
<p>Hopefully, I&#8217;ve followed all the best practice and it is useful to some people. I&#8217;ve been using it for over a year now for dozens of bundles and for converting third-party JARs to OSGi bundles. <a href="mailto:dev@jeremias-maerki.ch">Feedback</a> is welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2010/11/18/osgi-bundle-utility-1-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Years in Open Source</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2010/10/24/10-years-in-open-source/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2010/10/24/10-years-in-open-source/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 05:00:22 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Apache FOP]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/?p=63</guid>
		<description><![CDATA[Sylvain Wallez indirectly reminded me that I, too, have my 10-year anniversary in the Open Source world this year. On October 24, 2000, my first post went to the fop-dev mailing list (Apache FOP developer list), 11 months after the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2010/10/24/10-years-in-open-source/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a href="http://bluxte.net/musings/2010/10/07/10-years-ago-my-first-mail-apache">Sylvain Wallez</a> indirectly reminded me that I, too, have my 10-year anniversary in the Open Source world this year. On October 24, 2000, my first post went to the <a href="http://xmlgraphics.apache.org/fop/">fop-dev mailing list (Apache FOP developer list)</a>, 11 months after the Apache FOP project had started.</p>
<p>I had started a new job back then which began with a project that should format invoices from the health sector to PostScript and print them on large-scale printers including automatic packaging. And for that XSL-FO looked like the right technology, but FOP had to learn how to use fonts other than the base 14 set (Helvetica, Times, Courier, Symbol and ZapfDingbats). Finishing some work started by someone else, my first contribution was initial support for custom Type 1 fonts.</p>
<p>Today, I&#8217;m probably the FOP contributor with the longest <a href="http://apache.markmail.org/search/?q=Jeremias+from%3A%22Jeremias%22+order%3Adate-forward">service record</a> in the project.</p>
<p><a href="http://apache.markmail.org/search/?q=Jeremias+from%3A%22Jeremias%22+order%3Adate-forward"><img src="http://www.jeremias-maerki.ch/blog/wp-content/2010/10/fop-10-year-anniversary-stats.png" alt="Mailing List Stats @MarkMail.org" /></a></p>
<p>I went through the hype phase (2001-2003) as well as the difficult time of the redesign after the famous 0.20.5 release which saw an almost complete exchange of the project team between 2003 and 2005. From 2005 on, we worked towards a stable FOP again that quickly surpassed the old 0.20.5 release for which soon there was almost no expertise around anymore. It&#8217;s unbelievable how many people still use 0.20.5 and say &#8220;we can&#8217;t upgrade&#8221;. Many of the problems they have are simply solved in the current release. Anyway, since this year&#8217;s 1.0 release, FOP finally doesn&#8217;t carry that undeserved taint of an 0.x software anymore. It was just a version number but not an indicator of FOP&#8217;s production readiness. The initial goal of a complete implementation of the XSL 1.0 standard was just unrealistic. There&#8217;s not even one commercial implementation on the market which achieved that goal. Many people came and went during all that time. FOP is what it is today through contributions from all of them.</p>
<p>Lately, AFP is a big topic where FOP took big leaps forward in the last 2-3 years. Color is also becoming more and more important as color printing gets cheaper and <a href="http://en.wikipedia.org/wiki/Transpromotional">transpromo</a> is gaining interest. Even in today&#8217;s world the number of pages printed still increases every year. Apache FOP is well positioned to cover the printed document as well as the electronic document. XSL is an established and accepted technology today. And Apache FOP is often the &#8220;entry drug&#8221; for people who start XSL. Many stay with it producing millions of pages each year. During the stagnation of the redesign phase, some FOP users turned to commercial implementations like RenderX or AntennaHouse. After 2005 I saw many switch back again after the major improvements because some of the commercial implementations couldn&#8217;t offer much more but had a higher TCO depending on the use case or because they offered unsatisfactory support and couldn&#8217;t influence the development direction enough. Apache FOP might face some difficult time ahead since the layout engine (the core) didn&#8217;t see considerable development lately. Some features like table markers, flow maps and auto-table layout would do FOP some good but it won&#8217;t be easy to implement.</p>
<p>Between 2000 and 2003, Apache FOP was part of my job and quickly became a hobby, too. I&#8217;ve developed <a href="http://barcode4j.sf.net">Barcode4J</a> (an open source barcode generator) during that time which plugs nicely into FOP. From 2004 to 2005, FOP was just a hobby as I worked part-time for a small company maintaining a model-driven application framework. In 2005 I went freelance offering commercial support, consulting and development services around Apache FOP. At times, FOP created up to 90% of my income. I did not get rich, of course, but the fun counts, too. It wasn&#8217;t always fun. Heated arguments over mostly non-features nibbled at my motivation which triggered me to reduce my involvement in FOP a bit. This year was dominated by two interesting projects that involved producing full-color PDFs, both Web-to-Print. One is <a href="http://directfactory.post.ch/">Swiss Post&#8217;s DirectFactory</a>, a web plattform where you can design and send postcards (or even chocolate wrappers now). The other was for a company that produces photo books, calendars and other gifts from within the browser. That finally got me back to a user role a bit. Before that I basically just hacked FOP without really using it myself. It&#8217;s interesting how the perspective shifts again when switching back to the user side. This is particularly important to me now that the EUR, GBP and USD are very weak against the CHF. My commercial support business gets increasingly more difficult because most of my clients are located outside Switzerland. And that means I have to shift my main focus to domestic clients but without leaving my past clients in a void.</p>
<p>I&#8217;d like to note something interesting in that context: In all my freelancer time since 2005, I&#8217;ve never picked up the phone to look around for projects. I was lucky that they always found me, often even at the right times. A large part of it, I&#8217;m sure, is my presence on the Apache FOP Users Mailing List. By answering questions, people recognize a recurring name at some point. When some users run into a problem they can&#8217;t solve easily, they often turn to me for a higher service level than is possible on the users mailing list. That said, I believe there is room for a good developer to get challenging tasks as part of a commercial support service for Apache FOP, especially if he&#8217;s not afraid of the complicated topic of paper layout and he&#8217;s not located in Switzerland which is currently just too expensive due to the currency weaknesses. Such an additional resource would be good for FOP.</p>
<p>Last year, I&#8217;ve started to develop an output management server which uses Apache FOP as its main formatter. Although a minimal version is now live working nicely for the DirectFactory, it turned out to be too big an endeavour for a one-man show besides end-user projects and the FOP commercial support. So I&#8217;ll be investing in a smaller product first that hopefully will create a little multiplicator for me which commercial support services simply can&#8217;t provide. To wrap up this admittedly lengthy post, I need to say that Open Source is a very important topic for me. When done right, it is such an effective way to pool resources and to create high-quality software. Getting rich with it (not that I need to be) is difficult, so the right way is probably somewhere in between commercial and open source products. My wish is that more users of Open Source software think about contributing something back to the many products they use. There are various ways to do that. Too often, people treat OSS as freeware which it simply isn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2010/10/24/10-years-in-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSGi Declarative Services: Configuring multiple instances of a component</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2010/04/22/osgi-ds-configuring-multiple-instances-of-a-component/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2010/04/22/osgi-ds-configuring-multiple-instances-of-a-component/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 13:44:30 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[Declarative Services]]></category>
		<category><![CDATA[MetaType]]></category>
		<category><![CDATA[SCR]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/?p=41</guid>
		<description><![CDATA[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<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2010/04/22/osgi-ds-configuring-multiple-instances-of-a-component/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>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 &#8220;hotfolder&#8221;, 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&#8217;s a simpler way with Declarative Services once you&#8217;ve figured out the subtleties.<br />
Let&#8217;s first define a very simple service interface:</p>
<pre>public interface Greeter {
    void sayHello();
}</pre>
<p>Then let&#8217;s implement this interface:</p>
<pre>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");
    }

}</pre>
<p>Through the <code>activate(ComponentContext)</code> method, we&#8217;ll get the component&#8217;s configuration once an instance is activated.<br />
Now, we need the component descriptor for our Greeter component (<code>OSGI-INF/component.xml</code>):</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;component name="demo.scr.componentfactory.greeter"&gt;
  &lt;!-- No factory attribute here! --&gt;
  &lt;implementation class="demo.scr.componentfactory.impl.GreeterImpl"/&gt;
  &lt;service&gt;
    &lt;provide interface="demo.scr.componentfactory.Greeter"/&gt;
  &lt;/service&gt;
  &lt;property name="service.description"
      value="A nice component that can say hello"/&gt;
&lt;/component&gt;</pre>
<p>If you know a little bit about Declarative Services, you might at first expect a factory attribute on the component, since we&#8217;re going to create multiple instances, but it would really just wrong with the approach I&#8217;m showing here. The final missing clue to make this work with multiple configurations lies with the MetaType descriptor we need to build (<code>OSGI-INF/metatype/metatype.xml</code>):</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"
    localization="OSGI-INF/metatype/metatype"&gt;
  &lt;metatype:OCD id="demo.scr.componentfactory.greeter"
      name="SCR Component Factory Demo"&gt;
    &lt;metatype:AD id="name" type="String"
        name="%name.name" description="%name.desc"/&gt;
  &lt;/metatype:OCD&gt;
  &lt;metatype:Designate pid="demo.scr.componentfactory.greeter"
      factoryPid="demo.scr.componentfactory.greeter"&gt;
    &lt;metatype:Object ocdref="demo.scr.componentfactory.greeter"/&gt;
  &lt;/metatype:Designate&gt;
&lt;/metatype:MetaData&gt;</pre>
<p>Note especially the &#8220;Designate&#8221; Element which has both a &#8220;pid&#8221; and a &#8220;factoryPid&#8221; attribute. The important part is the &#8220;factoryPid&#8221; attribute which will enable the desired &#8220;factory&#8221; functionality.<br />
If you want, a properties file with the translations (<code>OSGI-INF/metatype/metatype.properties</code>):</p>
<pre>name.name=Name
name.desc=The name. D'oh!</pre>
<p>Just for completeness and illustration, here&#8217;s the effective bundle manifest:</p>
<pre>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</pre>
<p>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&#8217;s WebConsole.<br />
Besides the UI in the WebConsole, you can also use Apache Felix FileInstall&#8217;s configuration feature. Just create a properties file (ex. &#8220;demo.scr.componentfactory.greeter-C3PO.cfg&#8221;) in the directory observed by FileInstall:</p>
<pre>name=C3PO, human cyborg relations</pre>
<p>Just use the component&#8217;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.</p>
<p><strong>Update, 2010-05-19:</strong><br />
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:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
    name="demo.scr.componentfactory.greeter"
    configuration-policy="require"&gt;
[..]
&lt;/scr:component&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2010/04/22/osgi-ds-configuring-multiple-instances-of-a-component/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ATM hanging at startup</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2009/11/09/atm-hanging-at-startup/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2009/11/09/atm-hanging-at-startup/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 09:17:01 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/?p=31</guid>
		<description><![CDATA[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&#8217;t think any comment is necessary. Thanks to Jürgen for pointing this out to me!]]></description>
				<content:encoded><![CDATA[<p>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&#8217;t think any comment is necessary. <img src='http://www.jeremias-maerki.ch/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://www.jeremias-maerki.ch/wordpress/wp-content/uploads/2009/11/Bankomat%20Windows%202000%20h%C3%A4ngt%201024.JPG"><img class="aligncenter" title="ATM running Windows 2000 hangs on startup" alt="ATM running Windows 2000 hangs on startup" src="http://www.jeremias-maerki.ch/wordpress/wp-content/uploads/2009/11/Bankomat%20Windows%202000%20h%C3%A4ngt%20Thumb.JPG" width="240" height="189" /></a></p>
<p>Thanks to Jürgen for pointing this out to me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2009/11/09/atm-hanging-at-startup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DocBook is fun!</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2009/06/04/docbook-is-fun/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2009/06/04/docbook-is-fun/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 15:57:08 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Apache FOP]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/2009/06/04/docbook-is-fun/</guid>
		<description><![CDATA[I&#8217;m currently writing a basic XSL training course which I&#8217;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<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2009/06/04/docbook-is-fun/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m currently writing a basic XSL training course which I&#8217;ll give the first time later this month. I decided to write the training materials using <a href="http://www.docbook.org/tdg5/en/html/docbook.html" title="DocBook 5 Reference">DocBook 5</a>. Lots of XML examples, lots of SVG illustrations painted in <a href="http://inkscape.org/" title="Inkscape Website">Inkscape</a>. I used the DocBook editing capability of my <a href="http://www.oxygenxml.com/" title="OxygenXML Website">OxygenXML</a> editor. Finally, I&#8217;ve customized the DocBook XSL stylesheets a bit, added syntax highlighting using <a href="http://sourceforge.net/projects/xslthl" title="XSLTHL Project Page at SourceForge">XSLTHL </a>and used <a href="http://xmlgraphics.apache.org/fop/" title="Apache FOP Website">Apache FOP</a> (SVN Trunk) to create the PDF.</p>
<p>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.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2009/06/04/docbook-is-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Specifying Classpaths</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2008/12/04/specifying-classpaths/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2008/12/04/specifying-classpaths/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 08:22:57 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/2008/12/04/specifying-classpaths/</guid>
		<description><![CDATA[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&#8217;m talking<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2008/12/04/specifying-classpaths/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>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&#8217;m talking about specifying a classpath. Multiple entries on the classpath are delimited by a separator but that separator is not always the same:</p>
<ul>
<li>JVM Classpath on Windows (semicolon): &#8220;-cp my1.jar;my2.jar&#8221;</li>
<li>JVM Classpath on Unix (colon): &#8220;-cp my1.jar:my2.jar&#8221;</li>
<li>Class-Path entry in a JAR manifest (space): &#8220;Class-Path: my1.jar my2.jar&#8221;</li>
<li>OSGi&#8217;s Bundle-Classpath entry in a bundle manifest (comma): &#8220;Bundle-Classpath: .,META-INF/lib/my1.jar,META-INF/lib/my2.jar&#8221;</li>
</ul>
<p>I&#8217;m sure someone will eventually come up with yet another separator for classpath entries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2008/12/04/specifying-classpaths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IBM and Sun launch ODF Toolkit</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2008/11/05/ibm-and-sun-launch-odf-toolkit/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2008/11/05/ibm-and-sun-launch-odf-toolkit/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 19:29:09 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Apache FOP]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/2008/11/05/ibm-and-sun-launch-odf-toolkit/</guid>
		<description><![CDATA[With pleasure I learned today that IBM and Sun together launched http://odftoolkit.org/. It is at least partly seeded with code from Sun&#8217;s OpenOffice (namely the ODF Toolkit project). Initial components include ODFDOM (a low-level ODF API) and an ODF validator.<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2008/11/05/ibm-and-sun-launch-odf-toolkit/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>With pleasure I learned today that <a href="http://www.marketwatch.com/news/story/IBM-Sun-Microsystems-Launch-ODF/story.aspx?guid={39DC24F7-9368-4437-92A5-E49FFFDE6AEF}" title="Press release on MarketWatch">IBM and Sun together launched</a> <a href="http://odftoolkit.org/" title="ODF Toolkit website">http://odftoolkit.org/</a>. It is at least partly seeded with code from Sun&#8217;s <a href="http://www.openoffice.org/" title="OpenOffice website">OpenOffice</a> (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 <a href="http://www.apache.org/licenses/LICENSE-2.0.html" title="Apache License V2.0">Apache License V2.0</a>. Congratulations to the people involved!</p>
<p>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&#8217;ve got the feeling that we won&#8217;t have to wait all too long for that&#8230; <img src='http://www.jeremias-maerki.ch/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2008/11/05/ibm-and-sun-launch-odf-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So Mars is now called PDFXML</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2008/09/17/so-mars-is-now-called-pdfxml/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2008/09/17/so-mars-is-now-called-pdfxml/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 13:42:29 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/2008/09/17/so-mars-is-now-called-pdfxml/</guid>
		<description><![CDATA[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.<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2008/09/17/so-mars-is-now-called-pdfxml/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p><a title="PDFXML Plug-in Prerelease" href="http://blogs.adobe.com/mars/2008/09/pdfxml_plugin_prerelease.html">Matthew Hardy announced a new prerelease of the PDFXML Plug-in für Adobe Acrobat 9</a>. 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&#8217;ve already <a title="XMLizing PDF" href="http://www.jeremias-maerki.ch/wordpress/2007/01/05/xmlizing-pdf/">blogged about it</a> some time ago.</p>
<p><!-- ~ --><!-- ~ --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2008/09/17/so-mars-is-now-called-pdfxml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Barcode4J 2.0 released</title>
		<link>http://www.jeremias-maerki.ch/wordpress/2008/05/15/barcode4j-20-released/</link>
		<comments>http://www.jeremias-maerki.ch/wordpress/2008/05/15/barcode4j-20-released/#comments</comments>
		<pubDate>Thu, 15 May 2008 08:44:14 +0000</pubDate>
		<dc:creator>Jeremias Märki</dc:creator>
				<category><![CDATA[Barcodes]]></category>

		<guid isPermaLink="false">http://www.jeremias-maerki.ch/blog/2008/05/15/barcode4j-20-released/</guid>
		<description><![CDATA[I let it slide for too long but now, Barcode4J 2.0 is finally available. Since the last alpha release I&#8217;ve been able to fix a number of bugs in DataMatrix and PDF417. As a last-minute addition I&#8217;ve added support for<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://www.jeremias-maerki.ch/wordpress/2008/05/15/barcode4j-20-released/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I let it slide for too long but now, <a href="http://barcode4j.sourceforge.net" title="Barcode4J website">Barcode4J 2.0</a> is finally available. Since the last alpha release I&#8217;ve been able to fix a number of bugs in DataMatrix and PDF417. As a last-minute addition I&#8217;ve added support for the <a href="http://ribbs.usps.gov/OneCodeSolution/" title="USPS website">USPS Intelligent Mail Barcode</a> of which you can see an example below.</p>
<p><img src="http://barcode4j.sourceforge.net/images/example-usps4cb.png" title="USPS Intelligent Mail Barcode Example" alt="USPS Intelligent Mail Barcode Example" height="20" width="282" /></p>
<p>There&#8217;s also <a href="http://barcode4j.sourceforge.net/changes.html" title="Barcode4J Changes">a detailed list of changes for this release</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeremias-maerki.ch/wordpress/2008/05/15/barcode4j-20-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
