【发布时间】:2014-04-19 13:29:26
【问题描述】:
我正在开发 OSGI 包。我已经实现了一个 BundleActivator,这是我的代码。
public class Activator implements BundleActivator {
private static final String CONFIG_PID = "ConfigApp";
private ServiceRegistration serviceReg;
public VfsDAO app;
@Override
public void start(BundleContext context) throws Exception {
System.out.println("Hello................ bundle started");
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put(Constants.SERVICE_PID, CONFIG_PID);
serviceReg = context.registerService(ManagedService.class.getName(), new ConfigUpdater() , properties);
}
@Override
public void stop(BundleContext context) throws Exception {
serviceReg.unregister();
}
/**
* Updates the configuration in the application. Of course your class can also directly implement ManagedService but this
* way you can work with pojos
*/
private final class ConfigUpdater implements ManagedService {
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary config) throws ConfigurationException {
if (config == null) {
return;
}
if (app == null) {
app = new VfsDAO();
}
app.setAllowed((String)config.get("title"));
System.out.println("FROM................ bundle ACTIVATOR");
app.refresh();
}
}
}
现在,如果我在任何其他类中创建 VfsDAO() 对象,则不会调用 setAllowed,因此未初始化允许的字符串。当我在任何其他类中创建新的 VfsDAO() 对象时,如何获取该值?或者当我在任何其他允许的类字符串中创建 VfsDAO() 的新对象时,我如何在 VfsDAO 类中调用 (String)config.get("title") 。
【问题讨论】:
标签: osgi osgi-bundle