December 22, 2014
Hot Topics:

Create Reusable OSGi Components for Eclipse Equinox

  • March 17, 2010
  • 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,
 org.eclipse.core.runtime,
 org.eclipse.swt,
 org.eclipse.ui.workbench,
 org.eclipse.jface,
 CommonServices;bundle-version="1.0.0"


Here it is for cases when specific packages are imported:

Import-Package: com.infy.setl.common.services.activator,
 com.infy.setl.common.services.genericserviceint,
 com.infy.setl.common.services.usermode,
 com.infy.setl.common.services.usermodelint,
 com.infy.setl.common.services.userserviceint,
 com.infy.setl.common.services.validateservice,
 com.infy.setl.common.services.validateserviceint


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.

if(bundle!=null){
            if(bundle.getState()==Bundle.ACTIVE){
               context = bundle.getBundleContext();    
               if(context!=null){
                  userServiceTracker = new ServiceTracker(context,IContextDataService.class.getName(), null);   
                  if(userServiceTracker!=null){
                     userServiceTracker.open();
                     // grab the service
                     userSessionService = (IUserSessionService)userServiceTracker.getService();
                     if(userSessionService!=null)
                        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



    Comment and Contribute

     


    (Maximum characters: 1200). You have characters left.

     

     


  • Enterprise Development Update

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

    Sitemap | Contact Us

    Rocket Fuel