📄 activator.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -