February 26, 2021
Hot Topics:

Create Reusable OSGi Components for Eclipse Equinox

  • By Manish Malhotra, Prasad Siva Sai Choutupalli
  • Send Email »
  • More Articles »

Using the Login Solution Components

The two bundles in the Login Solution (UserLoginUI and UserLoginServices) are modular components. In this section, you'll learn how to can plug these bundles into an application. Your solution provides services for validating and storing user credentials. As mentioned previously, to make use of the services, a developer can import packages individually or import the whole bundle in their applications. A snapshot of the UserLoginUI bundle's MANIFEST.MF is shown below in for the scenarios.

Here is the MANIFEST.MF when whole bundle is imported:

Require-Bundle: org.eclipse.ui,

Here it is for cases when specific packages are imported:

Import-Package: com.infy.setl.common.services.activator,

After this, you just add a few lines of code in your application and start using the the Common Services. Before using any service, you need an object of that particular service. The following snippet gets the service object of the cache services provided in the UserLoginServices bundle.

               context = bundle.getBundleContext();    
                  userServiceTracker = new ServiceTracker(context,IContextDataService.class.getName(), null);   
                     // grab the service
                     userSessionService = (IUserSessionService)userServiceTracker.getService();
                        return userSessionService;

When you have the service object, you can invoke the services whenever you need them. Here is the invocation of the cache service.

If( userSessionService != null)  { 
userSessionService.save( creds.getUserId(), creds);

To use the UserLoginUI bundle, a user application needs to import the bundle or import the package exported by the UserLoginUI bundle. Click here to download the sample code.

Further Possibilities with OSGi and Eclipse

The Login Solution has a few other use cases to consider. For example, you could extend it for Eclipse RCP applications for which a developer needs to maintain multiple user credentials for multiple applications. In that use case, many different apps use this service bundle as middleware for login and session management. Wouldn't it be interesting if the whole solution was multi-tenant? Then what modifications would you need to make to meet the requirements? These are open questions for you to ponder as you explore the possibilities of OSGi.

Code Download

  • OSGI_Eclipse_Equinox

    About the Authors

    Prasad Siva Sai Choutupalli is a System Engineer for Infosys Technologies Ltd., India in SETLabs (Software Engineering and Technology Labs), the R&D division of the company. His experience is in building middleware and Eclipse-based applications.

    Manish Malhotra is a Technology Lead with SETLabs (Software Engineering and Technology Labs), the R&D division of Infosys Technologies Ltd. He works in the JEECoe group. Apart from designing and implementing Java- and Java EE-based applications, he has also worked on software engineering and semantic analysis research.

    Page 3 of 3

    This article was originally published on March 18, 2010

  • Enterprise Development Update

    Don't miss an article. Subscribe to our newsletter below.

    Thanks for your registration, follow us on our social networks to keep up-to-date