View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-3-2 上午08:53:31
4    */
5   package gboat2.serviceflow;
6   
7   import org.drools.util.ServiceRegistry;
8   import org.osgi.framework.Bundle;
9   import org.osgi.framework.BundleActivator;
10  import org.osgi.framework.BundleContext;
11  import org.osgi.framework.ServiceReference;
12  import org.osgi.util.tracker.ServiceTracker;
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  /**
17   * 
18   * @author lysming
19   * @since jdk1.6
20   * @date 2012-3-2
21   *  
22   */
23  
24  public class Activator implements BundleActivator {
25  
26  	private Logger logger = LoggerFactory.getLogger(Activator.class);
27  	private ServiceTracker tracker;
28  	public static Bundle LOCAL_BUNDLE;
29  	
30  	/** 
31  	  * (non-Javadoc)    
32  	  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)   
33  	  */
34  	/** 
35  	  * (non-Javadoc)    
36  	  * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)   
37  	  * @param bundleContext bundle上下文
38  	  */
39  	public void start(BundleContext bundleContext) {
40  		LOCAL_BUNDLE = bundleContext.getBundle();
41  		logger.debug("starting gboat2.serviceflow ......");
42  
43  		tracker = new ServiceTracker(bundleContext,ServiceRegistry.class.getName(),null){
44  			public Object addingService(ServiceReference reference){
45  				ServiceRegistry registry = (ServiceRegistry)context.getService(reference);
46  				JBPMHelper.setServiceRegistry(registry);
47  				return super.addingService(reference);
48  			}
49  		};
50  		tracker.open();
51  
52  	}
53  
54  	/** 
55  	  * (non-Javadoc)    
56  	  * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)   
57  	  * @param context bundle上下文
58  	  */
59  	public void stop(BundleContext context) {
60  		tracker.close();
61  	}
62  
63  }