While tinkering with Parsley I put together a straightforward collection of classes outlining the most useful / straightforward methods within parsley that will serve as a good reference when trying to find a specific way to inject / message etc without looking throughout the entire parsley docs. Attached is the source / project.
Here is a link to the reference
Below is an example of one of the classes. Please take a look at it as a reference.
package com.proving.receiver { import com.proving.event.MessageExtendingFromEventWithPayload; import com.proving.event.MessageExtendingFromObjectWithPayload; import mx.controls.Alert; import mx.events.CloseEvent; import org.spicefactory.parsley.core.messaging.MessageProcessor; public class Receiver { public function Receiver() { } private var processor:MessageProcessor [MessageInterceptor(type="com.proving.event.MessageExtendingFromEventWithPayload")] /** *This metadata allows you to intercept messages of specific types * This happens before any other methods handling this method are invoked * from this you can proceed or rewind * @param processor - MessageProcessor for this message * */ public function interceptEvent (processor:MessageProcessor):void { var message:MessageExtendingFromEventWithPayload = processor.message as MessageExtendingFromEventWithPayload; if(message.type == MessageExtendingFromEventWithPayload.DEFAULT_MESSAGE){ this.processor = processor; Alert.show('Resume event invocations?', 'Alert!', Alert.YES | Alert.NO, null, closeHandler); }else{ processor.proceed() } } [MessageError(type="com.proving.event.MessageExtendingFromEventWithPayload")] /** *With this metadata you can handle messageError's that happen within the lifecycle of a message * This is useful because Errors within parsley are normally swallowed and simply logged leaving it hard to debug * This will handle errors that happen for specific types * please note : per my experience if you have a global message handler, specificly typed ones will not get fired subsequently * @param processor - MessageProcessor for this message * @param error - the error that was thrown in this * */ public function handleMessageErrorBySelector(processor:MessageProcessor, error:Error):void{ trace('For MessageExtendingFromEventWithPayload : ' + error.getStackTrace()); } [MessageError] /** * With this metadata you can handle messageError's that happen within the lifecycle of any message * @param processor - MessageProcessor for this message * @param error - the error that was thrown in this * */ public function handleAllMessageErrors(processor:MessageProcessor, error:Error):void{ trace('For all message errors : ' + error.getStackTrace()); } private function closeHandler(e:CloseEvent):void{ if(e.detail == Alert.YES){ if(processor)processor.proceed(); }else{ if(processor)processor.rewind(); } processor = null; } [MessageHandler] /** *Simple message handler, parsley does type matching to managed events here * This will handle all messages of type MessageExtendingFromEventWithPayload * @param val - incoming message * */ public function handleMessageByClassType(val:MessageExtendingFromEventWithPayload):void{ trace('received all managed messages of class type MessageExtendingFromEventWithPayload') } [MessageHandler(selector="messageExtendingFromEventWithPayload")] /** *This metadata allows you to be more granular with which types of events within a message you will handle * @param val - incoming message * */ public function handleMessageBySelector(val:MessageExtendingFromEventWithPayload):void{ trace('received all managed messages with type MessageExtendingFromEventWithPayload') } [MessageHandler(type="com.proving.event.MessageExtendingFromEventWithPayload", messageProperties="firstName, lastName")] /** *This metadata allows you to similarly to messageBinding, parameterize a method with properties from an event with a payload * @param val - incoming message * */ public function handleMessageBySelectorWithParameterizedFunction(firstName:String, lastName:String):void{ trace('received parameterized message of type MessageExtendingFromEventWithPayload') } [MessageHandler(selector="sendMessageWithError")] public function handleMessageBySelectorAndThrowError(val:MessageExtendingFromEventWithPayload):void{ throw new Error('Exercising Parsleys MessageError'); } [MessageHandler] /** *This method handler simply handles a message that does not extend from event * this can be useful for reasons of true decoupling * unlike with a message with an event, you can not get the target through this, making it truly decoupled * @param val * */ public function handleObjectMessage(val:MessageExtendingFromObjectWithPayload):void{ trace('received all managed messages of class type MessageExtendingFromObjectWithPayload') } [MessageBinding(messageProperty="firstName",type="com.proving.event.MessageExtendingFromEventWithPayload")] /** *This metadata allows you to do bindings through messsages * you associate a property on your message with the property you declare below the metadata */ public var firstName:String; [MessageBinding(messageProperty="lastName",type="com.proving.event.MessageExtendingFromEventWithPayload")] public var lastName:String; } }
Hope it helps
Eric
