Showing posts with label springframework. Show all posts
Showing posts with label springframework. Show all posts

Thursday, November 24, 2011

Why spring beans can not be used in Android

java.beans package again

The Springframework does not work in Android because of its heavy use of classes from java.beans package e.g. PropertyEditorSupport. Android currently only supports a few classes from java.beans package. I already filed feature request to support more classes from java.beans package in the Android bugtracker. Of course one can use classes from libraries of the Springframework in general e.g. org.springframework.core.io.DefaultResourceLoader.

Saturday, April 9, 2011

Spring OSGi - Building extensible and customizable bundles

(work in progess)

Abstract

This artcile shows how to build a domain specific Spring OSGi bundle (dynamic module), which can be customized in projects using fragment bundles. Of course one can use the RCP extension points conecpt etc. to provide customization and extensibility, but in my opinion the Spring way is much more convenient, powerful and dynamic.

The following ideas could be used to inspire a product like application based on a lightweight RCP application framework, wich can be customized and extended in projects to customer needs.

Example case

A bundle provides a view showing data columns of a database table. A project has the requirement to change the columns to be displayed and to change behavior of the view components itself. The view itself is a Spring bean. Lets have a look to the MANIFEST.MF of the host bundle providing the standard view and behavior.

Architecture fundamentals

The following sub chapters describe briefly the fundamental parts of the architecture for dynamic extensible Spring OSGi bundles.

The MANIFEST.MF - Spring application context loading

Manifest-Version: 1.0
Unversioned-Imports: *
Bundle-Name: acme.bundle
Bundle-Vendor: acme
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: acme.CommonFrameWorkBundleActivator
Spring-Context: META-INF/spring/*-init.xml,
META-INF/spring/*.xml,
META-INF/spring-ext/*-init.xml,
META-INF/spring-ext/*.xml

Important is the value of Spring-Context. It defines the order in which the Spring OSGi framework loads the configuration files.

  1. META-INF/spring/*-init.xml - this file is loaded first. Put any bootstrap beans here
  2. META-INF/spring/*.xml - all remaining xml files in META-INF/spring/ are loaded
  3. now META-INF/spring-ext/*-init.xml is loaded. This file is not provided by the host bundle, but later by the fragment bundle, which extends the host bundle
  4. META-INF/spring-ext/*.xml - all other xml files of the fragment are loaded

Bundle Activator

Spring BeanPostProcessors

Spring xml schema extensions

Wednesday, March 23, 2011

Spring OSGi - how to get ApplicationContext for a bundle

Using Spring DM, a Spring ApplicationContext is created for each Spring DM. The ApplicationContext is published as an OSGi service.

The following code can be used to lookup the ApplicationContext in OSGi service registry.


public static ApplicationContext getApplicationContext(final BundleContext bundleContext) {
        final String filter = "(org.springframework.context.service.name=" + bundleContext.getBundle().getSymbolicName() + ")";
        final ServiceReference[] applicationContextRefs;
        final ApplicationContext applicationContext;
       
        try {
            applicationContextRefs = bundleContext.getServiceReferences(ApplicationContext.class.getName(), filter);
        } catch (final InvalidSyntaxException e) {/>
            throw new RuntimeException(e);
        }
       
        if(applicationContextRefs.length != 1) {
            return null;
        }
       
        applicationContext = (ApplicationContext) bundleContext.getService(applicationContextRefs[0]);
       
        return applicationContext;
}


See Application Context Service Publication for details
You should follow me
on twitter