Category Archives: cdi

17 Mai

“CDI für Rich Clients” in Eclipse Magazin

I am very happy to announce that the current issue (4.2012) of the german Eclipse Magazin (http://eclipse-magazin.de) includes my article “CDI für Richt Clients”, which is about the integration of Apache OpenWebBeans into Eclipse RCP.

After publishing my blog entry Apache OpenWebBeans meets Eclipse RCP, I was contacted by Claudia Fröhling asking if I wanted to write about this topic for the Eclipse Magazin. I was very glad to get this offer and, of course, agreed to write the article. Authoring such an article was a quite new experience for me, and I really enjoyed it. Hopefully it will not be the last one.

You can obtain a copy of the current Eclipse Magazin here or you can download the iPad app of the magazine.

09 Mrz

Apache OpenWebBeans meets Eclipse RCP

Last year I had to do a project at university using Eclipse RCP. Frankly, the Eclipse framework kinda sucked. Thus I tried to pimp Eclipse RCP a little bit, which means I wanted to use OWB and CODI.

After some time I figured out how to combine OWB and Eclipse RCP thanks to the excellent plugin system of OWB. Now I finally found some time to put the relevant classes online. You can find the project at apache-extras: http://code.google.com/a/apache-extras.org/p/openwebbeans-eclipse-rcp/

Please note: Although this is a maven project, I was not able to really build it with maven, b/c I couldn’t find a way to get all the relevant eclipse jars into a maven repo. If you want to use it, the best way is to copy the source files directly into your Eclipse RCP project.

If anyone is interested in getting this stuff running in his/her Eclipse RCP project, just ping me and I can help you with the pitfalls.

26 Sep

create annotation instances at runtime

Yesterday I stumbled upon an easy way to create annotation instances at runtime: javax.enterprise.util.AnnotationLiteral

This util class from CDI (JSR-299) implements all standard methods (toString(), equals(), hashCode(), annotationType()) just like an annotation instance created by Java would. Thus there is no real difference between subclasses from this class and the annotations created by the JRE.

Here you can find the source code of AnnotationLiteral from Apache Geronimo Specs: AnnotationLiteral.java

Example

For example you have the following annotation (which is also a CDI qualifier):

@Target({PARAMETER, FIELD, METHOD, CONSTRUCTOR, TYPE})
@Retention(RUNTIME)
@Documented

@Qualifier
public @interface ConversationQualifier1
{
    String value();
}

If you want to create an instance of it with a certain value at runtime, just create the following class:

public class MyConversationQualifier1
    extends AnnotationLiteral<ConversationQualifier1>
    implements ConversationQualifier1
{

    public String value()
    {
        return "my assigned value";
    }
}

Now you just need to create an instance of it and you can use it like any other annotation instance created by Java.

Annotation a = new MyConversationQualifier1();