Class EventCartridge
Stores the event handlers. Event handlers can be assigned on a per VelocityEngine instance basis by specifying the class names in the velocity.properties file. Event handlers may also be assigned on a per-page basis by creating a new instance of EventCartridge, adding the event handlers, and then calling attachToContext. For clarity, it's recommended that one approach or the other be followed, as the second method is primarily presented for backwards compatibility.
Note that Event Handlers follow a filter pattern, with multiple event handlers allowed for each event. When the appropriate event occurs, all the appropriate event handlers are called in the sequence they were added to the Event Cartridge. See the javadocs of the specific event handler interfaces for more details.
- Version:
- $Id$
- Author:
- Will Glass-Husain , Geir Magnusson Jr. , Jose Alberto Fernandez
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds an event handler(s) to the Cartridge.void
Add an include event handler to the Cartridge.void
Add an invalid reference event handler to the Cartridge.void
Add a method exception event handler to the Cartridge.void
Add a reference insertion event handler to the Cartridge.final boolean
attachToContext
(Context context) Attached the EventCartridge to the context Final because not something one should mess with lightly :)protected org.slf4j.Logger
getLog()
includeEvent
(Context context, String includeResourcePath, String currentResourcePath, String directiveName) Call include event handlersCall invalid reference handlers for an invalid getterCall invalid reference handlers for an invalid method callboolean
invalidSetMethod
(Context context, String leftreference, String rightreference, Info info) Call invalid reference handlers for an invalid setterCall method exception event handlerreferenceInsert
(InternalContextAdapter context, String reference, Object value) Call reference insertion handlersboolean
Removes an event handler(s) from the Cartridge.void
runtime services setter, called during initialization
-
Field Details
-
rsvc
-
-
Constructor Details
-
EventCartridge
public EventCartridge()
-
-
Method Details
-
getLog
protected org.slf4j.Logger getLog() -
setRuntimeServices
runtime services setter, called during initialization- Parameters:
rs
- runtime services- Since:
- 2.0
-
addEventHandler
Adds an event handler(s) to the Cartridge. This method will find all possible event handler interfaces supported by the passed in object.- Parameters:
ev
- object implementing a valid EventHandler-derived interface- Returns:
- true if a supported interface, false otherwise or if null
-
addReferenceInsertionEventHandler
Add a reference insertion event handler to the Cartridge.- Parameters:
ev
- ReferenceInsertionEventHandler- Since:
- 1.5
-
addMethodExceptionHandler
Add a method exception event handler to the Cartridge.- Parameters:
ev
- MethodExceptionEventHandler- Since:
- 1.5
-
addIncludeEventHandler
Add an include event handler to the Cartridge.- Parameters:
ev
- IncludeEventHandler- Since:
- 1.5
-
addInvalidReferenceEventHandler
Add an invalid reference event handler to the Cartridge.- Parameters:
ev
- InvalidReferenceEventHandler- Since:
- 1.5
-
removeEventHandler
Removes an event handler(s) from the Cartridge. This method will find all possible event handler interfaces supported by the passed in object and remove them.- Parameters:
ev
- object impementing a valid EventHandler-derived interface- Returns:
- true if event handler was previously registered, false if not found
-
referenceInsert
Call reference insertion handlers- Parameters:
context
-reference
-value
-- Returns:
- value returned by handlers
- Since:
- 2.0
-
methodException
public Object methodException(Context context, Class<?> claz, String method, Exception e, Info info) Call method exception event handler- Parameters:
context
-claz
-method
-e
- exceptioninfo
- template name, line and column infos- Returns:
- value returned by handler
- Since:
- 2.0
-
includeEvent
public String includeEvent(Context context, String includeResourcePath, String currentResourcePath, String directiveName) Call include event handlers- Parameters:
context
-includeResourcePath
-currentResourcePath
-directiveName
-- Returns:
- include path
- Since:
- 2.0
-
invalidGetMethod
public Object invalidGetMethod(Context context, String reference, Object object, String property, Info info) Call invalid reference handlers for an invalid getter- Parameters:
context
-reference
-object
-property
-info
-- Returns:
- value returned by handlers
- Since:
- 2.0
-
invalidSetMethod
public boolean invalidSetMethod(Context context, String leftreference, String rightreference, Info info) Call invalid reference handlers for an invalid setter- Parameters:
context
-leftreference
-rightreference
-info
-- Returns:
- whether to stop further chaining in the next cartridge
- Since:
- 2.0
-
invalidMethod
public Object invalidMethod(Context context, String reference, Object object, String method, Info info) Call invalid reference handlers for an invalid method call- Parameters:
context
-reference
-object
-method
-info
-- Returns:
- value returned by handlers
- Since:
- 2.0
-
attachToContext
Attached the EventCartridge to the context Final because not something one should mess with lightly :)- Parameters:
context
- context to attach to- Returns:
- true if successful, false otherwise
-