TagLib documentation

org.alweb.doff.mapping
Class ActionMapping

java.lang.Object
  extended by org.alweb.doff.mapping.Mapping
      extended by org.alweb.doff.mapping.ActionMapping

public final class ActionMapping
extends Mapping

Represents a mapping of an action. An action is a Controller method annotated by Action.

Author:
Alexis Toulotte
See Also:
Action

Constructor Summary
ActionMapping(ControllerMapping controllerMapping, Method method)
          Creates a new ActionMapping instance from its controller mapping and its method.
 
Method Summary
 void checkConflicts(ActionMapping action)
          Checks if this ActionMapping object conflicts with specified action.
 void checkConflicts(Collection<? extends ActionMapping> actions)
          Checks if one of specified actions is in conflict with this ActionMapping object.
 boolean containsPathPattern()
          Determines if this mapping contains at least one path pattern.
 boolean excludes(Class<? extends Filter> filterClass)
          Determines if this action mapping excludes specified filter class.
 ControllerMapping getControllerMapping()
          Returns the controller mapping specified at the constructor.
 String getFullPath(Object... extraInfos)
          Returns the full path of this ActionMapping including the controller path.
 Method getHttpMethod()
          Returns the Method used by this ActionMapping object.
 Method getMethod()
          Returns the method specified at the contructor.
 String getMethodName()
          A convenience helper to retrieve the name of the method.
 String getName()
           Returns the name of this action mapping.
 Collection<ParameterMapping> getParameters()
          Returns all mapped parameters of this action mapping.
 Object[] getParametersValues(Controller controller)
          Returns all parameters values as an object array.
 String getPath()
          Returns the path specified by Action.path() annotation property or null if the Action identified by this ActionMapping is the controller's index.
 Parameter getPathParam(String path, int index)
          Provides a way to retrieve a path param identified thanks to ${string}, ${int} or ${all} patterns.
 int getPathPatternCount()
          Returns the count of path pattern of this ActionMapping object path.
 String getURL(Object... extraInfos)
          Returns the relative URL of this ActionMapping object.
 String getViewPath()
           Returns the location of this ActionMapping view path.
 boolean is(Class<? extends Controller> controllerClass, String methodName)
          Determines if this ActionMapping object is the action identified by specified Controller class and method name.
 boolean isIndex()
          Determines if the action represented by this mapping is the index of its controller.
 boolean matches(ServletParameters parameters)
           Determines if this ActionMapping object matches specified servlet parameters.
 String toString()
          Provides a string representation of this ActionMapping object.
 
Methods inherited from class org.alweb.doff.mapping.Mapping
getAssociatedObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionMapping

public ActionMapping(ControllerMapping controllerMapping,
                     Method method)
Creates a new ActionMapping instance from its controller mapping and its method.

Throws:
MappingException - if specified method hasn't the Action annotation or if method is abstract or takes any undeclared parameter or if the Action annotation's path contains only spaces and/or slashes. A MappingException is also thrown when parameters are malformed into Action annotation or if parameter count isn't equals to method parameters count.
NullPointerException - if one of specified parameters is null.
See Also:
Action.path()
Method Detail

checkConflicts

public void checkConflicts(ActionMapping action)
Checks if this ActionMapping object conflicts with specified action. There is no conflict if specified action is the same as this object.

Parameters:
action - The action to check if conflict exists.
Throws:
MappingException - if Method of both action is the same and if paths are in conflicts.

checkConflicts

public void checkConflicts(Collection<? extends ActionMapping> actions)
Checks if one of specified actions is in conflict with this ActionMapping object.

Parameters:
actions - The actions to check conflicts for.
Throws:
MappingException - if there is at least one of specified action in conflict with this ActionMapping object.
See Also:
checkConflicts(ActionMapping)

containsPathPattern

public boolean containsPathPattern()
Determines if this mapping contains at least one path pattern. A path pattern is ${string}, ${int} or ${all}.


excludes

public boolean excludes(Class<? extends Filter> filterClass)
Determines if this action mapping excludes specified filter class. To exclude a filter of action's execution, add filter's class into Action.exclude() annotation attribute. If you want to exclude all controller's actions of filter execution, add Exclude annotation on you filter and add you controller into value array.

Since:
1.5.2

getControllerMapping

public ControllerMapping getControllerMapping()
Returns the controller mapping specified at the constructor.

See Also:
ActionMapping(ControllerMapping, Method)

getFullPath

public String getFullPath(Object... extraInfos)
Returns the full path of this ActionMapping including the controller path. You can specify any extra info to this method, path params will be replaced by those values. If one of specified info is null, the variable pattern will be kept.

See Also:
getPath(), ControllerMapping.getPath()

getHttpMethod

public Method getHttpMethod()
Returns the Method used by this ActionMapping object.

See Also:
Action.method()

getMethod

public Method getMethod()
Returns the method specified at the contructor.

See Also:
ActionMapping(ControllerMapping, Method), Mapping.getAssociatedObject()

getMethodName

public String getMethodName()
A convenience helper to retrieve the name of the method. It's the same than getMethod().getName()

See Also:
getMethod(), Method.getName()

getName

public String getName()

Returns the name of this action mapping. The name is the controller's name concatened to '#' char and then, the name of the method.

Example: MyController#myAction

See Also:
getMethodName(), ServiceMapping.getName()

getParameters

public Collection<ParameterMapping> getParameters()
Returns all mapped parameters of this action mapping.

Returns:
A unmodifiable collection of parameters.
Since:
1.5
See Also:
Action.params()

getParametersValues

public Object[] getParametersValues(Controller controller)
Returns all parameters values as an object array.

Since:
1.5
See Also:
Action.params(), getParameters()

getPath

public String getPath()
Returns the path specified by Action.path() annotation property or null if the Action identified by this ActionMapping is the controller's index.

See Also:
Action.path(), Action.index(), isIndex()

getPathParam

public Parameter getPathParam(String path,
                              int index)
Provides a way to retrieve a path param identified thanks to ${string}, ${int} or ${all} patterns. If this mapping doesn't match specified path, this method will always returns a Parameter with null as parameter value.

Parameters:
path - The path info of current URL.
index - The index of the param (starts at 0).
See Also:
getPath(), matches(ServletParameters), Action.path()

getPathPatternCount

public int getPathPatternCount()
Returns the count of path pattern of this ActionMapping object path. A pattern can be ${string}, ${int} or ${all} string.

See Also:
containsPathPattern(), getFullPath(Object[])

getURL

public String getURL(Object... extraInfos)
Returns the relative URL of this ActionMapping object.

Parameters:
extraInfos - The extra informations of the action path. First it is path patterns. Each specified extra info will replace ${string}, ${int} or ${all} patterns in the action path. Then, if you specify more extra info than path patterns, your parameters will be added to the query string, one by one (null parameters will not be added).
See Also:
getFullPath(Object[])

getViewPath

public String getViewPath()

Returns the location of this ActionMapping view path. The path is obtained from the current action method name preceded by the controller's name. The returned path always starts with a slash but never ends with a slash. All uppercase letters are preceded by an underscore and converted to lowercase. The name of the controller represents the directory, the name of the action method, the file.

Example: for an action with method list obtained in controller UsersAccounts. The path of the view is: users_accounts/list.

See Also:
PathUtilities.convert(String), Class.getSimpleName(), Method.getName()

is

public boolean is(Class<? extends Controller> controllerClass,
                  String methodName)
Determines if this ActionMapping object is the action identified by specified Controller class and method name.

Parameters:
controllerClass - The class of the controller.
methodName - The name of the action method.
Returns:
true if this ActionMapping object is identified by specified controller class and method name, false otherwise.

isIndex

public boolean isIndex()
Determines if the action represented by this mapping is the index of its controller. An ActionMapping is always an index if method's name is index.

See Also:
Action.index()

matches

public boolean matches(ServletParameters parameters)

Determines if this ActionMapping object matches specified servlet parameters. This method checks if the Method is the same as specified one and checks the path. This method also uses ${string}, ${int} and ${all} patterns. The specified path must contains controller's path.

This method also uses the case-sensitive property of the associated controller mapping (ControllerMapping.isCaseSensitive()).

Parameters:
parameters - The parameters of the current request.
Returns:
true if this mapping matches specified path, false otherwise.
See Also:
ServletParameters.getPathInfo()

toString

public String toString()
Provides a string representation of this ActionMapping object.

Overrides:
toString in class Mapping
Returns:
The name of this ActionMapping object.
See Also:
getName()

TagLib documentation