Monday, November 16, 2009

Ranking: Popularität von Programmiersprachen

Ein sehr bekanntes Ranking zur Popularität von Programmiersprachen wird von der Firma Tiobe erstellt: http://www.tiobe.com/index.php/tiobe_index

Friday, November 13, 2009

Zurück von der W-JAX 2009

Die W-JAX 2009 in München war wirklich toll! Vielen Dank an die Organisatoren, Speaker und alle Besucher! Bis zum nächsten Jahr...

Monday, February 9, 2009

Implementing the equals() Method

This short article contains the recent facts for implementing the equals() method of a class. If you are interested in the full explanation of the details, please take a look at the article from Angelika Langer: Implementing the equals() Method - Part 1 (german only, sorry).

This is the basic implementation for a class that is directly derived from java.lang.Object:
public boolean equals(final Object object) {
if (this == object) {
return true;
}

if (object == null) {
return false;
}

if (getClass() != object.getClass()) {
return false;
}

// TODO compare all fields of this class
return true;
}
This is the basic implementation for a class that is NOT directly derived from java.lang.Object:
public boolean equals(final Object object) {
if (this == object) {
return true;
}

if (!super.equals(object)) {
return false;
}

// TODO compare all fields of this class
return true;
}

Sunday, January 18, 2009

Tutorial: Export a sample RCP application using Spring, Spring Dynamic Modules for OSGi Service Platforms and AgileRCP

In this article you will learn how to export an RCP application that makes use of Spring, Spring-DM and AgileRCP. The article uses the example from the past tutorial about RCP / Spring / Spring-DM / AgileRCP (see part 1, part 2 and part 3). Please note that the example code has changed slightly, see the downloadable source code archive at the end of this article.

  1. Create a feature that contains all plug-ins:
    • New -> Other... -> Plug-in Development / Feature Project
    • Choose a proper project name, e.g. "org.digitalcure.hellospring.feature"
    • Initialize from the plug-ins list
    • Select the following plugins:
      • org.agilercp.ui
      • org.agilercp.ui.dialog
      • org.agilercp.util
      • org.apache.commons.logging
      • org.digitalcure.hellospring.app
      • org.digitalcure.hellospring.common
      • org.digitalcure.hellospring.service
      • org.springframework.bundle.osgi.core
      • org.springframework.bundle.osgi.extender
      • org.springframework.bundle.osgi.io
      • org.springframework.bundle.spring
    • Finish the wizard. An editor for the file fragment.xml will be opened.
  2. Add the current plug-in versions:
    • Switch to the Plug-ins tab.
    • Select all plug-ins and press the button "Versions...".
    • Select "Copy versions from plug-ins and fragments manifests" and finish the dialog.
    • Save the feature file.
  3. Configure the product to use features:
    • Open the product file (plug-in "org.digitalcure.hellospring.app", file HelloSpringApp.product).
    • Overview tab: The product configuration is based on: features
    • Configuration tab: Press the button "Add..." and select our newly created feature.
    • Press "Add..." once again and add the feature "org.eclipse.rcp".
    • Save the product file.
  4. Export the product (1st try):
    • File -> Export... -> Plug-in Development / Eclipse product
    • Configuration: Press the "Browse..." button, expand the plug-in "org.digitalcure.hellospring.app" and select the file HelloSpringApp.product.
    • Root directory: HelloSpring
    • Synchronize before exporting: yes
    • Destination: Select "Directory" and select a proper folder to export the product to.
    • Finish the dialog. Eclipse should export the product without errors.
  5. Run the exported product.
    • Use a file browser (e.g. Windows Explorer) to navigate to your export directory and run the product (e.g. named "eclipse.exe").
    • The application will be displayed after a short delay, but there is an error message instead of the expected table.
    • First of all: Don't panic! The error is caused by the lazy startup of the plug-ins. Spring-DM is unable to create a proper ApplicationContext and so the application is unable to instrument Spring.
  6. Add a configuration file to the application plug-in:
    • However, the exported product is very useful for us, because it ontains a default configuration file. Copy the file config.ini from the "configuration" folder and paste it into the root folder of the application plug-in.
    • Edit the build properties of the application plug-in and add the file config.ini to the binary build.
    • Open config.ini inside the Eclipse IDE.
    • Edit the line for the property "osgi.bundles" in the following way:

      osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.update.configurator@3:start,org.eclipse.core.runtime@start,org.agilercp.ui@start,org.digitalcure.hellospring.app@start,org.digitalcure.hellospring.common@start,org.digitalcure.hellospring.service@start,org.springframework.bundle.osgi.extender@start

  7. Use the configuration file in the product:
    • Open the product definition file and switch to the Configuration tab. Take a look at the section "Configuration File".
    • Choose the tab for your operating system.
    • Select "Use an existing config.ini file".
    • Press the button "Browse..." and select the newly created configuration file.
    • Save the product definition file.
  8. Export the product (2nd try). Just the same as the 1st try.
  9. Run the exported product:
    • Same procedure as described above.
    • The application will be displayed, including the expected table. That's it!
You may download the source code of the tutorial from here.

Thursday, November 20, 2008

Tutorial: How to create a remote OSGi service

In this article you will learn how to create a remote OSGi service from a "local" OSGi service using R-OSGi. The OSGi service for an user manager is published by the Activator of the service bundle:
public class Activator implements BundleActivator {
public void start(final BundleContext context) throws Exception {
context.registerService(IUserManager.class.getName(), new UserManager(), null);
System.out.println("Service registered.");
}

public void stop(final BundleContext context) throws Exception {}
}
The Activator of the application bundle uses the service:
public class Activator implements BundleActivator {
public void start(final BundleContext context) throws Exception {
final ServiceReference serviceRef = context.getServiceReference(IUserManager.class.getName());
if (serviceRef == null) {
System.out.println("Service not found!");
} else {
final IUserManager userManager = (IUserManager) context.getService(serviceRef);

try {
System.out.println("All user names:");
final List<String> names = userManager.getUserNames();
for (final String name : names) {
System.out.println("Name = " + name);
}
} finally {
context.ungetService(serviceRef);
}
}
}

public void stop(final BundleContext context) throws Exception {}
}
Now you have to verify that R-OSGi is installed on your local Eclipse. Activate the view "Plug-ins" and search for a bundle named ch.ethz.iks.r_osgi.remote. If it is already there, you may skip the following installation procedure.

The easiest way to install R-OSGi into your Eclipse is to install the Eclipse Communication Framework (ECF). Use one of the following update sites:
After the download of the plug-ins, their installation and the restart of the Eclipse IDE the R-OSGi bundle will be available in the "Plug-ins" view.

First, you have to add the bundle ch.ethz.iks.r_osgi.remote to the list of required plug-ins. Do this for both the application and the service bundle. Then you have to mark the published OSGi service as remote service (inside the Activator of the service bundle):
  public void start(final BundleContext context) throws Exception {
final Hashtable properties = new Hashtable();
properties.put(RemoteOSGiService.R_OSGi_REGISTRATION, Boolean.TRUE);
context.registerService(IUserManager.class.getName(), new UserManager(), properties);
System.out.println("Service registered.");
}
That was easy! Using the remote service requires a little bit more code. Instead of getting the user manager service directly from the service registry, you have to get the R-OSGi service from the service registry. Then you have to query the R-OSGi service for the remote user manager services. The code inside the Activator of the application bundle looks like this:
  public void start(final BundleContext context) throws Exception {
final ServiceReference serviceRef = context.getServiceReference(RemoteOSGiService.class.getName());
if (serviceRef == null) {
System.out.println("R-OSGi service not found!");
} else {
final RemoteOSGiService remote = (RemoteOSGiService) context.getService(serviceRef);
try {
remote.connect(new URI("r-osgi://205.207.25.9:9278"));

final RemoteServiceReference[] references = remote.getRemoteServiceReferences(
new URI("r-osgi://205.207.25.9:9278"), IUserManager.class.getName(), null);
if (references == null) {
System.out.println("Service not found!");
} else {
final IUserManager userManager = (IUserManager) remote.getRemoteService(references[0]);

System.out.println("All user names:");
final List<String> names = userManager.getUserNames();
for (final String name : names) {
System.out.println("Name = " + name);
}
}
} finally {
context.ungetService(serviceRef);
}
}
}
Now you should test the remote OSGi service. Create a run configuration for the service and run it. Then create a run configuration for the application and run it. Depending on your user manager implementation you should see something like this (Console of the application):
osgi> All user names:
Name = Charly
Name = Dennis
Name = Ed
You may download the source code from here.