/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.view;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import com.eventrouter.DispatchContext;
import com.eventrouter.SubscriptionRegistry;
import com.eventrouter.annotation.AnnotationProcessor;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
@Configurable
public abstract class BaseApplication extends Application implements HttpServletRequestListener {
private static final InheritableThreadLocal threadApp = new InheritableThreadLocal();
@Autowired
private DispatchContext dispatchContext;
public final DispatchContext getDispatchContext() {
return dispatchContext;
}
public BaseApplication() {
threadApp.set(this);
}
@PostConstruct
private void postConstruct() {
SubscriptionRegistry subscriptionRegistry = dispatchContext.getSubscriptionRegistry();
AnnotationProcessor processor = new AnnotationProcessor(subscriptionRegistry);
processor.process(this);
}
//--------------------------------------------------------------------------
@Override
public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
threadApp.set(this);
}
@Override
public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
threadApp.remove();
}
public static BaseApplication getInstance() {
return threadApp.get();
}
}