activator.java

来自「OSGI_Opendoc, 基于OSGI框架Equinox的实战讲解」· Java 代码 · 共 49 行

JAVA
49
字号
package org.riawork.opendoc.event;
/*
 * RIAWork.org
 * 
 * OSGI Opendoc Demo
 */
import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
/**
 * desc: 事件处理器
 *
 * @author jerry
 */
public class Activator implements BundleActivator,EventHandler {

	private static final String[] topics=new String[]{"org/riawork/*"};
	
	private ServiceRegistration serviceReg=null;
	
	/* (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		Dictionary props=new Hashtable();
		props.put(EventConstants.EVENT_TOPIC, topics);
		serviceReg=context.registerService(EventHandler.class.getName(), this, props);
	}

	/* (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		if(serviceReg!=null)
			serviceReg.unregister();
	}

	public void handleEvent(Event event) {
		System.out.println("event.getTopic()==="+event.getTopic());
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?