org.loom.mapping
Class Event

java.lang.Object
  extended by org.loom.mapping.Event
All Implemented Interfaces:
ButtonDecorator, FormDecorator, LinkDecorator

public class Event
extends java.lang.Object
implements LinkDecorator, FormDecorator, ButtonDecorator

This class holds the internal data associated to an event. Events are public methods in Action classes that return Resolution and receive no arguments.


Constructor Summary
Event(ActionMapping mapping, java.lang.reflect.Method method)
           
 
Method Summary
 void addEventParameter(EventParameter parameter)
           
 void addInterceptor(Interceptor interceptor)
           
 void addMethod(HttpMethod method)
          Add an allowed http method to this event.
 void addValidator(PropertyValidator validator)
          Adds a new parameter or attribute Validator.
 void assertNoOverlapping(Event other)
           
 void decorate(Button button)
          Modify button attributes based on the interceptors bound to this event.
 void decorate(Form form)
          Modify form attributes based on the interceptors bound to this event.
 void decorate(Link link)
          Modify link attributes based on the interceptors bound to this event.
 ActionMapping getActionMapping()
           
 Converter getConverter(java.lang.String normalizedPropertyPath)
           
 java.util.List<EventParameter> getEventParameters()
           
 java.util.Set<HttpMethod> getHttpMethods()
           
 InterceptorProxy getInterceptors()
           
 java.lang.reflect.Method getJavaMethod()
           
 java.lang.String getName()
           
 java.lang.String getPrintName()
           
 java.lang.Class<?> getPropertyClass(java.lang.String normalizedPropertyPath)
          Return the property class of a normalized property path.
 java.util.Set<java.lang.String> getUriParameterNames()
           
 UriParser getUriParser()
           
 java.util.Collection<PropertyValidator> getValidators()
          Deprecated. this method will be removed with no replacement
 java.util.Set<PropertyValidator> getValidatorsFor(java.lang.String propertyPath)
           
 boolean isDefault()
           
<T extends java.lang.annotation.Annotation>
boolean
matches(T annotation)
          Return true if this event matches the "on", "except" clauses of the provided annotation instance
 java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String uri, LoomServletRequest request)
          If this event is a match, return the list of parameter values extracted from the uri.
 void setInterceptorList(InterceptorProxy interceptorList)
           
 void setUriParser(UriParser uriParser)
           
 boolean supports(HttpMethod httpMethod)
           
 java.lang.String toString()
           
 java.lang.StringBuilder toUrl(com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)
          Prepare the string representatuion of this method with the provided params.
 void validate(ParsedAction action)
          Applies all the configured validations to this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Event

public Event(ActionMapping mapping,
             java.lang.reflect.Method method)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getPropertyClass

public java.lang.Class<?> getPropertyClass(java.lang.String normalizedPropertyPath)
Return the property class of a normalized property path. Handles transparently if the property is nested inside a method arguyment or is an action attribute.

Parameters:
normalizedPropertyPath - the entire property path

getConverter

public Converter getConverter(java.lang.String normalizedPropertyPath)
Returns:
the converter for the provided normalizedPropertyPath, null if none

parse

public java.util.Map<java.lang.String,java.lang.String> parse(java.lang.String uri,
                                                              LoomServletRequest request)
If this event is a match, return the list of parameter values extracted from the uri. If the URI is not a match or the HTTP method is not included in the list of allowed methods, return null.

Parameters:
uri - the URI to be parsed, without the action handle.
request - the request object
Returns:
the Map of parameters extracted from the uri, null if it's not a match.

getName

public java.lang.String getName()
Returns:
the event name. This is the same as the method name.

getPrintName

public java.lang.String getPrintName()
Returns:
the print (full) event name for error messages. This is the action short name followed by the event name.

addValidator

public void addValidator(PropertyValidator validator)
Adds a new parameter or attribute Validator. Allows validation overriding. If this property already has a validation of the same type, override it with the new one (for example, override the validation in fooAction.barField using annotations in fooAction).

Parameters:
validator -

validate

public void validate(ParsedAction action)
              throws MalformedPropertyPathException
Applies all the configured validations to this object

Parameters:
action - the action and list of error messages
Throws:
MalformedPropertyPathException

assertNoOverlapping

public void assertNoOverlapping(Event other)
Throws:
ConfigException - if this Event is mapped to a URL that overlaps with another event for the same HTTP method

toUrl

public java.lang.StringBuilder toUrl(com.google.common.collect.ListMultimap<java.lang.String,java.lang.String> params)
Prepare the string representatuion of this method with the provided params.

Parameters:
params - the list of parameters to include in the URL.
Returns:
the String representation of this event object

getUriParameterNames

public java.util.Set<java.lang.String> getUriParameterNames()
Returns:
a list of the parameter names that are used to build the uri

addInterceptor

public void addInterceptor(Interceptor interceptor)

getJavaMethod

public java.lang.reflect.Method getJavaMethod()

getInterceptors

public InterceptorProxy getInterceptors()

setInterceptorList

public void setInterceptorList(InterceptorProxy interceptorList)

getValidators

public java.util.Collection<PropertyValidator> getValidators()
Deprecated. this method will be removed with no replacement

Used only to inspect the list of validators while in development (actionDetails.jsp). This method should not be used for any other purpose, as it exposes some class internals.


getValidatorsFor

public java.util.Set<PropertyValidator> getValidatorsFor(java.lang.String propertyPath)
Parameters:
propertyPath - the property path to retrieve validators
Returns:
Validators registered with the provided propertyName

getActionMapping

public ActionMapping getActionMapping()

isDefault

public boolean isDefault()
Returns:
true if this is the default event

decorate

public void decorate(Link link)
Modify link attributes based on the interceptors bound to this event.

Specified by:
decorate in interface LinkDecorator

decorate

public void decorate(Form form)
Modify form attributes based on the interceptors bound to this event.

Specified by:
decorate in interface FormDecorator

decorate

public void decorate(Button button)
Modify button attributes based on the interceptors bound to this event.

Specified by:
decorate in interface ButtonDecorator

supports

public boolean supports(HttpMethod httpMethod)
Returns:
true if this method supports (can be invoked with) the provided HTTP method

addMethod

public void addMethod(HttpMethod method)
Add an allowed http method to this event. By default, GET and POST are allowed unless otherwise specified.

Parameters:
method - the method that should be allowed

getUriParser

public UriParser getUriParser()

setUriParser

public void setUriParser(UriParser uriParser)

getHttpMethods

public java.util.Set<HttpMethod> getHttpMethods()

getEventParameters

public java.util.List<EventParameter> getEventParameters()

addEventParameter

public void addEventParameter(EventParameter parameter)

matches

public <T extends java.lang.annotation.Annotation> boolean matches(T annotation)
Return true if this event matches the "on", "except" clauses of the provided annotation instance