×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Ali Ben Messaoud
Added: Jan 24, 2017 2:21 PM
Views: 7
Tags: no tags
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.soprahr.hub.ds.configuration.hibernate.deault;
  7.  
  8. import com.soprahr.foryou.configuration.ComponentConfiguration;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import org.osgi.framework.BundleContext;
  12. import org.osgi.framework.FrameworkUtil;
  13. import org.osgi.framework.InvalidSyntaxException;
  14. import org.osgi.framework.ServiceEvent;
  15. import org.osgi.framework.ServiceListener;
  16. import org.osgi.framework.ServiceReference;
  17.  
  18. /**
  19.  *
  20.  * @author abenmessaoud
  21.  */
  22. public class ConfigurationServiceListener implements ServiceListener {
  23.  
  24.     private String componentConfigurationInterfaceFullName = "com.soprahr.foryou.configuration.IComponentConfiguration";
  25.     private String componentConfigurationInterfaceFilter = "(&(objectClass=" + componentConfigurationInterfaceFullName + ")(componentId=startyourdaymanager))";
  26.     private BundleContext bundleContext = FrameworkUtil.getBundle(Test.class).getBundleContext();
  27.    
  28.     private String componentId;
  29.     private String componentType;
  30.  
  31.     @Override
  32.     public void serviceChanged(ServiceEvent event) {
  33.         ServiceReference sr = event.getServiceReference();
  34.         switch (event.getType()) {
  35.             case ServiceEvent.REGISTERED: {
  36.                 try {
  37.                     ServiceReference[] serviceReferences = bundleContext.getServiceReferences(null, componentConfigurationInterfaceFilter);
  38.                     for (ServiceReference serviceReference : serviceReferences) {
  39.                         ComponentConfiguration ic = (ComponentConfiguration) bundleContext.getService(serviceReference);
  40.                         System.out.println("componentConfiguration : " + ic.getConfiguration());
  41.                     }
  42.                 } catch (InvalidSyntaxException ex) {
  43.                     Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
  44.                 }
  45.             }
  46.             break;
  47.             default:
  48.                 break;
  49.         }
  50.     }
  51.  
  52.     public String getComponentId() {
  53.         return componentId;
  54.     }
  55.  
  56.     public void setComponentId(String componentId) {
  57.         this.componentId = componentId;
  58.     }
  59.  
  60.     public String getComponentType() {
  61.         return componentType;
  62.     }
  63.  
  64.     public void setComponentType(String componentType) {
  65.         this.componentType = componentType;
  66.     }    
  67.  
  68. }
  69.