summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java
diff options
context:
space:
mode:
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java49
1 files changed, 28 insertions, 21 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java
index 692e6b5..6d0dfc1 100644
--- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java
+++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOApplication.java
@@ -28,7 +28,6 @@ import jakarta.servlet.http.HttpServletResponse;
import net.wotonomy.foundation.NSArray;
import net.wotonomy.foundation.NSDictionary;
import net.wotonomy.foundation.NSMutableDictionary;
-import net.wotonomy.web.util.BrowserLauncher;
/**
* A pure java implementation of WOApplication. <br>
@@ -46,10 +45,12 @@ import net.wotonomy.web.util.BrowserLauncher;
* @version $Revision: 905 $
*/
public class WOApplication extends HttpServlet {
+ private static final long serialVersionUID = 2417528899972745905L;
+
/**
* A tricky way to allow multiple WOApplications in the same servlet container.
*/
- static private ThreadLocal threadLocal;
+ static private ThreadLocal<WOApplication> threadLocal;
// static private WOApplication application;
/**
@@ -61,7 +62,7 @@ public class WOApplication extends HttpServlet {
private String name;
private WORequestHandler defaultRequestHandler;
- private NSMutableDictionary requestHandlers;
+ private NSMutableDictionary<String, WORequestHandler> requestHandlers;
private WOSessionStore sessionStore;
private WOResourceManager resourceManager;
private boolean pageRefreshOnBacktrack;
@@ -81,13 +82,13 @@ public class WOApplication extends HttpServlet {
public WOApplication() {
if (threadLocal == null) {
- threadLocal = new ThreadLocal();
+ threadLocal = new ThreadLocal<>();
}
threadLocal.set(this);
// application = this;
resourceManager = createResourceManager();
- requestHandlers = new NSMutableDictionary();
+ requestHandlers = new NSMutableDictionary<>();
defaultRequestHandler = new WODirectActionRequestHandler();
registerRequestHandler(defaultRequestHandler, directActionRequestHandlerKey());
registerRequestHandler(new WOComponentRequestHandler(), componentRequestHandlerKey());
@@ -107,6 +108,7 @@ public class WOApplication extends HttpServlet {
* sends the response to the appropriate WORequestHandler, and then updates the
* servlet response from the resulting WOResponse.
*/
+ @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException {
threadLocal.set(this);
@@ -121,6 +123,7 @@ public class WOApplication extends HttpServlet {
* gets and posts similarly. Override to handle post requests in a different
* manner.
*/
+ @Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException {
doGet(req, resp);
@@ -298,7 +301,7 @@ public class WOApplication extends HttpServlet {
/**
* Returns the keys under which request handlers are registered.
*/
- public NSArray registeredRequestHandlerKeys() {
+ public NSArray<String> registeredRequestHandlerKeys() {
return requestHandlers.allKeys();
}
@@ -314,9 +317,11 @@ public class WOApplication extends HttpServlet {
* Returns the request handler that would best service the specified request.
*/
public WORequestHandler handlerForRequest(WORequest aRequest) {
- WORequestHandler result = requestHandlerForKey(aRequest.requestHandlerKey());
+ WORequestHandler result;
if (aRequest == null)
result = defaultRequestHandler();
+ // TODO verify it was correct to move this down one
+ result = requestHandlerForKey(aRequest.requestHandlerKey());
return result;
}
@@ -470,7 +475,7 @@ public class WOApplication extends HttpServlet {
WOSession result = null;
try {
// using our class loader, which is hopefully dynamic.
- result = (WOSession) getLocalClass("Session").newInstance();
+ result = (WOSession) getLocalClass("Session").getDeclaredConstructor().newInstance();
} catch (Throwable t) {
// ignore: fall back to WOSession
// t.printStackTrace();
@@ -503,11 +508,11 @@ public class WOApplication extends HttpServlet {
WOComponent result = null;
try {
// using our class loader, which is hopefully dynamic.
- Class c = getLocalClass(aName);
+ Class<? extends WOComponent> c = getLocalClass(aName);
if (c != null) {
// get constructor
- Constructor ctor;
+ Constructor<? extends WOComponent> ctor;
try {
ctor = c.getConstructor(new Class[] { WOContext.class });
} catch (NoSuchMethodException nsme) {
@@ -519,7 +524,7 @@ public class WOApplication extends HttpServlet {
result = (WOComponent) ctor.newInstance(new Object[] { aContext });
} else // call back on default constructor (deprecated)
{
- result = (WOComponent) c.newInstance();
+ result = (WOComponent) c.getDeclaredConstructor().newInstance();
}
}
} catch (Throwable t) {
@@ -544,13 +549,14 @@ public class WOApplication extends HttpServlet {
* that, from the WOApplication package, or finally from the root of the class
* path. Returns null if not found.
*/
- Class getLocalClass(String aName) {
- Class result = null;
+ @SuppressWarnings("unchecked")
+ <C> Class<C> getLocalClass(String aName) {
+ Class<C> result = null;
if (getClass() != WOApplication.class) {
- result = loadLocalClass(getClass(), aName);
+ result = (Class<C>) loadLocalClass(getClass(), aName);
}
if (result == null) {
- result = loadLocalClass(WOApplication.class, aName);
+ result = (Class<C>) loadLocalClass(WOApplication.class, aName);
}
if (result == null) {
result = loadLocalClass(null, aName);
@@ -558,7 +564,8 @@ public class WOApplication extends HttpServlet {
return result;
}
- private static final Class loadLocalClass(Class aClass, String aName) {
+ @SuppressWarnings("unchecked")
+ private static final <C> Class<C> loadLocalClass(Class<C> aClass, String aName) {
ClassLoader loader;
String packageName = "";
if (aClass != null) {
@@ -575,7 +582,7 @@ public class WOApplication extends HttpServlet {
}
try {
- return loader.loadClass(packageName + aName);
+ return (Class<C>) loader.loadClass(packageName + aName);
} catch (ClassNotFoundException e) {
return null;
}
@@ -589,7 +596,7 @@ public class WOApplication extends HttpServlet {
public WOElement dynamicElementWithName(String anElementName, NSDictionary anAssociationMap, WOElement aBodyElement,
List aLanguageList) {
WOElement element = null;
- Class c = null;
+ Class<? extends WODynamicElement> c = null;
try {
c = getLocalClass(anElementName);
if (c == null) {
@@ -599,8 +606,8 @@ public class WOApplication extends HttpServlet {
}
// get constructor
- Class[] params = new Class[] { String.class, NSDictionary.class, WOElement.class };
- Constructor ctor = c.getConstructor(params);
+ Class<?>[] params = new Class[] { String.class, NSDictionary.class, WOElement.class };
+ Constructor<? extends WODynamicElement> ctor = c.getConstructor(params);
// create instance of class
if (ctor != null) {
@@ -886,7 +893,7 @@ public class WOApplication extends HttpServlet {
* Subclasses may call this method to start a self-hosted web server to serve
* themselves directly (for testing).
*/
- public static void main(String[] argv, Class subclass) {
+ public static void main(String[] argv, Class<?> subclass) {
// TODO fix this later
/*try {
int port = 0;