Peter Kriens of OSGi fame has provided an example of using Vaadin with OSGi.
Part of the code shown below creates new instances of a Vaadin application in V6.
Presumably, the ApplicationServlet should extend from VaadinServlet and a UIProvider should be used to create the instances, but how would this be coded in V7?
Regards
Paul Fraser
/**
- A servlet that acts as the factory for new instances for Vaadin. The
- servlet extends AbstractApplicationServlet as defined by Vaadin. For each
- application, it will request a new instance. If this servlet is closed, all
- created instances will be disposed.
*/
class ApplicationServlet extends AbstractApplicationServlet {
private static final long serialVersionUID = 1L;
final ComponentFactory factory;
final Map<ComponentInstance, Application> instances = new HashMap<ComponentInstance, Application>();
final AtomicBoolean open = new AtomicBoolean(true);
ApplicationServlet(ComponentFactory factory) {
this.factory = factory;
}
@Override
protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
return Application.class;
}
@SuppressWarnings("unchecked")
@Override
protected Application getNewApplication(HttpServletRequest request) throws ServletException {
if (open.get()) {
Hashtable<String, Object> ht = new Hashtable<String, Object>();
for (Enumeration<String> e = request.getAttributeNames(); e.hasMoreElements();) {
String key = e.nextElement();
ht.put(key, request.getAttribute(key));
}
ComponentInstance instance = factory.newInstance(ht);
synchronized (this) {
Application app = (Application) instance.getInstance();
instances.put(instance, app);
return app;
}
} else
throw new IllegalStateException("Application Servlet is closed! " + factory);
}
public void close() {
if (open.getAndSet(false)) {
for (Map.Entry<ComponentInstance, Application> instance : instances.entrySet()) {
instance.getValue().close();
instance.getKey().dispose();
}
instances.clear();
}
}
}