Skip to content

Commit

Permalink
Make setContext implementable
Browse files Browse the repository at this point in the history
Signed-off-by: cies <[email protected]>
  • Loading branch information
cies authored and cies committed Aug 8, 2023
1 parent 1a2edbf commit ebdca2a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
15 changes: 7 additions & 8 deletions framework/src/play/mvc/ActionInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void invoke(Http.Request request, Http.Response response) {
// Check the cache (only for GET or HEAD)
if ((request.method.equals("GET") || request.method.equals("HEAD")) && actionMethod.isAnnotationPresent(CacheFor.class)) {
cacheKey = actionMethod.getAnnotation(CacheFor.class).id();
if ("".equals(cacheKey)) {
if (cacheKey != null && cacheKey.isEmpty()) {
cacheKey = "urlcache:" + request.path + '?' + request.querystring;
}
actionResult = Cache.get(cacheKey);
Expand Down Expand Up @@ -183,9 +183,9 @@ boolean actionNeedsSession(Http.Request request) {
}

private PlayController createController(ActionContext context) {
PlayController controller = Injector.getBeanOfType(context.request.controllerClass);
if (controller instanceof Controller) {
((Controller) controller).setContext(context);
PlayController controller = Play.beanSource.getBeanOfType(context.request.controllerClass);
if (controller instanceof PlayContextController) {
((PlayContextController) controller).setContext(context);
}
return controller;
}
Expand Down Expand Up @@ -403,7 +403,6 @@ static void handleFinallies(Http.Request request, Session session, Throwable cau
}
}

@SuppressWarnings("unchecked")
public static void inferResult(Object o) {
// Return type inference
if (o != null) {
Expand Down Expand Up @@ -439,7 +438,7 @@ static Object invokeControllerMethod(Http.Request request, Session session, Meth

Object methodClassInstance = isStatic ? null :
(method.getDeclaringClass().isAssignableFrom(request.controllerClass)) ? request.controllerInstance :
Injector.getBeanOfType(method.getDeclaringClass());
Play.beanSource.getBeanOfType(method.getDeclaringClass());

return invoke(method, methodClassInstance, args);
}
Expand Down Expand Up @@ -468,8 +467,8 @@ public static Object[] getActionMethod(String fullAction) {
if (!fullAction.startsWith("controllers.")) {
fullAction = "controllers." + fullAction;
}
String controller = fullAction.substring(0, fullAction.lastIndexOf("."));
String action = fullAction.substring(fullAction.lastIndexOf(".") + 1);
String controller = fullAction.substring(0, fullAction.lastIndexOf('.'));
String action = fullAction.substring(fullAction.lastIndexOf('.') + 1);
controllerClass = Play.classes.getClassIgnoreCase(controller);
if (controllerClass == null) {
throw new ActionNotFoundException(fullAction, new Exception("Controller " + controller + " not found"));
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/mvc/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import play.mvc.results.Forbidden;
import play.rebel.View;

public class Controller implements PlayController {
public class Controller implements PlayContextController {
protected ActionContext actionContext;
protected Http.Request request;
protected Http.Response response;
Expand All @@ -15,7 +15,7 @@ public class Controller implements PlayController {
protected Scope.RenderArgs renderArgs;
protected Validation validation;

protected void setContext(ActionContext actionContext) {
public void setContext(ActionContext actionContext) {
this.actionContext = actionContext;
request = actionContext.request;
response = actionContext.response;
Expand Down
12 changes: 12 additions & 0 deletions framework/src/play/mvc/PlayContextController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package play.mvc;

/**
* Interface for play controllers with ActionContext provided to them by the {@link play.mvc.ActionInvoker}.
*
* This class your controllers should implement, when they need access to the {@link play.mvc.ActionContext}.
* In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features
* useful when implementing controllers.
*/
public interface PlayContextController extends PlayController {
void setContext(ActionContext actionContext);
}
4 changes: 2 additions & 2 deletions framework/src/play/mvc/PlayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Marker interface for play controllers
*
* This is the class that your controllers should implement.
* In most cases, you can extend play.mvc.Controller that contains all needed methods for controllers.
* This is the class that your controllers should implement when they need very few capabilities..
* In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features for controllers.
*/
public interface PlayController {
}

0 comments on commit ebdca2a

Please sign in to comment.