diff options
author | Artur Signell <artur.signell@itmill.com> | 2010-06-28 09:31:31 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2010-06-28 09:31:31 +0000 |
commit | d39e79c5d5eba986a1836135819aed837a3411ff (patch) | |
tree | 74f2636027649821df94c13debfa1d656dbb9a7d /src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java | |
parent | ba3ffeaa82c939c5c781b04b6f05cf539e4a31df (diff) | |
download | vaadin-framework-d39e79c5d5eba986a1836135819aed837a3411ff.tar.gz vaadin-framework-d39e79c5d5eba986a1836135819aed837a3411ff.zip |
Formatted /src using Vaadin Java Conventions 20071114
svn changeset:13932/svn branch:6.4
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java | 320 |
1 files changed, 160 insertions, 160 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java index 92488ef9ca..e9de68630b 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractWebApplicationContext.java @@ -1,8 +1,8 @@ /* @ITMillApache2LicenseForJavaFiles@ */ -package com.vaadin.terminal.gwt.server;
-
+package com.vaadin.terminal.gwt.server; + import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; @@ -19,178 +19,178 @@ import javax.servlet.http.HttpSessionBindingListener; import com.vaadin.Application; import com.vaadin.service.ApplicationContext; import com.vaadin.terminal.ApplicationResource; -
-/**
- * Base class for web application contexts (including portlet contexts) that
- * handles the common tasks.
- */
-public abstract class AbstractWebApplicationContext implements
- ApplicationContext, HttpSessionBindingListener, Serializable {
-
- protected Collection<TransactionListener> listeners = Collections
- .synchronizedList(new LinkedList<TransactionListener>());
-
- protected final HashSet<Application> applications = new HashSet<Application>();
-
- protected WebBrowser browser = new WebBrowser();
-
- protected HashMap<Application, AbstractCommunicationManager> applicationToAjaxAppMgrMap = new HashMap<Application, AbstractCommunicationManager>();
-
+ +/** + * Base class for web application contexts (including portlet contexts) that + * handles the common tasks. + */ +public abstract class AbstractWebApplicationContext implements + ApplicationContext, HttpSessionBindingListener, Serializable { + + protected Collection<TransactionListener> listeners = Collections + .synchronizedList(new LinkedList<TransactionListener>()); + + protected final HashSet<Application> applications = new HashSet<Application>(); + + protected WebBrowser browser = new WebBrowser(); + + protected HashMap<Application, AbstractCommunicationManager> applicationToAjaxAppMgrMap = new HashMap<Application, AbstractCommunicationManager>(); + public void addTransactionListener(TransactionListener listener) { if (listener != null) { listeners.add(listener); - }
- }
-
- public void removeTransactionListener(TransactionListener listener) {
- listeners.remove(listener);
- }
-
- /**
- * Sends a notification that a transaction is starting.
- *
- * @param application
- * The application associated with the transaction.
- * @param request
- * the HTTP or portlet request that triggered the transaction.
- */
- protected void startTransaction(Application application, Object request) {
- synchronized (listeners) {
- for (TransactionListener listener : listeners) {
- listener.transactionStart(application, request);
- }
- }
- }
-
- /**
- * Sends a notification that a transaction has ended.
- *
- * @param application
- * The application associated with the transaction.
- * @param request
- * the HTTP or portlet request that triggered the transaction.
- */
- protected void endTransaction(Application application, Object request) {
- LinkedList<Exception> exceptions = null;
-
- synchronized (listeners) {
- for (TransactionListener listener : listeners) {
- try {
- listener.transactionEnd(application, request);
- } catch (final RuntimeException t) {
- if (exceptions == null) {
- exceptions = new LinkedList<Exception>();
- }
- exceptions.add(t);
- }
- }
- }
-
+ } + } + + public void removeTransactionListener(TransactionListener listener) { + listeners.remove(listener); + } + + /** + * Sends a notification that a transaction is starting. + * + * @param application + * The application associated with the transaction. + * @param request + * the HTTP or portlet request that triggered the transaction. + */ + protected void startTransaction(Application application, Object request) { + synchronized (listeners) { + for (TransactionListener listener : listeners) { + listener.transactionStart(application, request); + } + } + } + + /** + * Sends a notification that a transaction has ended. + * + * @param application + * The application associated with the transaction. + * @param request + * the HTTP or portlet request that triggered the transaction. + */ + protected void endTransaction(Application application, Object request) { + LinkedList<Exception> exceptions = null; + + synchronized (listeners) { + for (TransactionListener listener : listeners) { + try { + listener.transactionEnd(application, request); + } catch (final RuntimeException t) { + if (exceptions == null) { + exceptions = new LinkedList<Exception>(); + } + exceptions.add(t); + } + } + } + // If any runtime exceptions occurred, throw a combined exception
- if (exceptions != null) {
- final StringBuffer msg = new StringBuffer();
- for (Exception e : exceptions) {
- if (msg.length() == 0) {
- msg.append("\n\n--------------------------\n\n");
- }
- msg.append(e.getMessage() + "\n");
- final StringWriter trace = new StringWriter();
- e.printStackTrace(new PrintWriter(trace, true));
- msg.append(trace.toString());
- }
- throw new RuntimeException(msg.toString());
- }
- }
-
- /**
- * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
- */
- public void valueBound(HttpSessionBindingEvent arg0) {
+ if (exceptions != null) { + final StringBuffer msg = new StringBuffer(); + for (Exception e : exceptions) { + if (msg.length() == 0) { + msg.append("\n\n--------------------------\n\n"); + } + msg.append(e.getMessage() + "\n"); + final StringWriter trace = new StringWriter(); + e.printStackTrace(new PrintWriter(trace, true)); + msg.append(trace.toString()); + } + throw new RuntimeException(msg.toString()); + } + } + + /** + * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent) + */ + public void valueBound(HttpSessionBindingEvent arg0) { // We are not interested in bindings
- }
-
- /**
- * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent)
- */
- public void valueUnbound(HttpSessionBindingEvent event) {
+ } + + /** + * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(HttpSessionBindingEvent) + */ + public void valueUnbound(HttpSessionBindingEvent event) { // If we are going to be unbound from the session, the session must be
// closing
- try {
- while (!applications.isEmpty()) {
- final Application app = applications.iterator().next();
- app.close();
- removeApplication(app);
- }
- } catch (Exception e) {
+ try { + while (!applications.isEmpty()) { + final Application app = applications.iterator().next(); + app.close(); + removeApplication(app); + } + } catch (Exception e) { // This should never happen but is possible with rare
// configurations (e.g. robustness tests). If you have one
// thread doing HTTP socket write and another thread trying to
// remove same application here. Possible if you got e.g. session
// lifetime 1 min but socket write may take longer than 1 min.
// FIXME: Handle exception
- System.err.println("Could not remove application, leaking memory.");
- e.printStackTrace();
- }
- }
-
- /**
- * Get the web browser associated with this application context.
- *
- * Because application context is related to the http session and server
- * maintains one session per browser-instance, each context has exactly one
- * web browser associated with it.
- *
- * @return
- */
- public WebBrowser getBrowser() {
- return browser;
- }
-
- public Collection<Application> getApplications() {
- return Collections.unmodifiableCollection(applications);
- }
-
- protected void removeApplication(Application application) {
- applications.remove(application);
- applicationToAjaxAppMgrMap.remove(application);
- }
-
- public String generateApplicationResourceURL(ApplicationResource resource,
- String mapKey) {
-
- final String filename = resource.getFilename();
- if (filename == null) {
- return "APP/" + mapKey + "/";
- } else {
- return "APP/" + mapKey + "/" + filename;
- }
-
- }
-
- public boolean isApplicationResourceURL(URL context, String relativeUri) {
+ System.err.println("Could not remove application, leaking memory."); + e.printStackTrace(); + } + } + + /** + * Get the web browser associated with this application context. + * + * Because application context is related to the http session and server + * maintains one session per browser-instance, each context has exactly one + * web browser associated with it. + * + * @return + */ + public WebBrowser getBrowser() { + return browser; + } + + public Collection<Application> getApplications() { + return Collections.unmodifiableCollection(applications); + } + + protected void removeApplication(Application application) { + applications.remove(application); + applicationToAjaxAppMgrMap.remove(application); + } + + public String generateApplicationResourceURL(ApplicationResource resource, + String mapKey) { + + final String filename = resource.getFilename(); + if (filename == null) { + return "APP/" + mapKey + "/"; + } else { + return "APP/" + mapKey + "/" + filename; + } + + } + + public boolean isApplicationResourceURL(URL context, String relativeUri) { // If the relative uri is null, we are ready
- if (relativeUri == null) {
- return false;
- }
-
+ if (relativeUri == null) { + return false; + } + // Resolves the prefix
- String prefix = relativeUri;
- final int index = relativeUri.indexOf('/');
- if (index >= 0) {
- prefix = relativeUri.substring(0, index);
- }
-
+ String prefix = relativeUri; + final int index = relativeUri.indexOf('/'); + if (index >= 0) { + prefix = relativeUri.substring(0, index); + } + // Handles the resource requests
- return (prefix.equals("APP"));
- }
-
- public String getURLKey(URL context, String relativeUri) {
- final int index = relativeUri.indexOf('/');
- final int next = relativeUri.indexOf('/', index + 1);
- if (next < 0) {
- return null;
- }
- return relativeUri.substring(index + 1, next);
- }
-
+ return (prefix.equals("APP")); + } + + public String getURLKey(URL context, String relativeUri) { + final int index = relativeUri.indexOf('/'); + final int next = relativeUri.indexOf('/', index + 1); + if (next < 0) { + return null; + } + return relativeUri.substring(index + 1, next); + } + }
\ No newline at end of file |