/// <summary> Calls event handler method with appropriate chaining across event handlers. /// /// </summary> /// <param name="methodExecutor"> /// </param> /// <param name="rsvc">current instance of RuntimeServices /// </param> /// <param name="context">The current context /// </param> /// <returns> return value from method, or null if no return value /// </returns> public static object InvalidReferenceHandlerCall(IEventHandlerMethodExecutor methodExecutor, IRuntimeServices rsvc, IInternalContextAdapter context) { // app level cartridges have already been initialized EventCartridge ev1 = rsvc.ApplicationEventCartridge; System.Collections.IEnumerator applicationEventHandlerIterator = (ev1 == null) ? null : ev1.InvalidReferenceEventHandlers; EventCartridge ev2 = context.EventCartridge; InitializeEventCartridge(rsvc, ev2); System.Collections.IEnumerator contextEventHandlerIterator = (ev2 == null) ? null : ev2.InvalidReferenceEventHandlers; try { CallEventHandlers(applicationEventHandlerIterator, contextEventHandlerIterator, methodExecutor); return(methodExecutor.ReturnValue); } catch (System.SystemException e) { throw e; } catch (System.Exception e) { throw new RuntimeException("Exception in event handler.", e); } }
/// <summary> Called before a reference is inserted. All event handlers are called in /// sequence. The default implementation inserts the reference as is. /// /// This is a major hotspot method called by ASTReference render. /// /// </summary> /// <param name="reference">reference from template about to be inserted /// </param> /// <param name="value">value about to be inserted (after toString() ) /// </param> /// <param name="rsvc">current instance of RuntimeServices /// </param> /// <param name="context">The internal context adapter. /// </param> /// <returns> Object on which toString() should be called for output. /// </returns> public static object ReferenceInsert(IRuntimeServices rsvc, IInternalContextAdapter context, string reference, object value) { // app level cartridges have already been initialized /* * Performance modification: EventCartridge.getReferenceInsertionEventHandlers * now returns a null if there are no handlers. Thus we can avoid creating the * Iterator object. */ EventCartridge ev1 = rsvc.ApplicationEventCartridge; System.Collections.IEnumerator applicationEventHandlerIterator = (ev1 == null) ? null : ev1.ReferenceInsertionEventHandlers; EventCartridge ev2 = context.EventCartridge; InitializeEventCartridge(rsvc, ev2); System.Collections.IEnumerator contextEventHandlerIterator = (ev2 == null) ? null : ev2.ReferenceInsertionEventHandlers; try { /* * Performance modification: methodExecutor is created only if one of the * iterators is not null. */ IEventHandlerMethodExecutor methodExecutor = null; if (applicationEventHandlerIterator != null) { methodExecutor = new ReferenceInsertExecutor(context, reference, value); LterateOverEventHandlers(applicationEventHandlerIterator, methodExecutor); } if (contextEventHandlerIterator != null) { if (methodExecutor == null) { methodExecutor = new ReferenceInsertExecutor(context, reference, value); } LterateOverEventHandlers(contextEventHandlerIterator, methodExecutor); } return(methodExecutor != null ? methodExecutor.ReturnValue : value); } catch (System.SystemException e) { throw e; } catch (System.Exception e) { throw new RuntimeException("Exception in event handler.", e); } }
/// <summary> Loop through a given iterator of event handlers. /// /// </summary> /// <param name="handlerIterator">Iterator that loops through event handlers /// </param> /// <param name="eventExecutor">Strategy object that executes event handler method /// </param> /// <exception cref="Exception">generic exception potentially thrown by event handlers /// </exception> private static void LterateOverEventHandlers(System.Collections.IEnumerator handlerIterator, IEventHandlerMethodExecutor eventExecutor) { if (handlerIterator != null) { for (System.Collections.IEnumerator i = handlerIterator; i.MoveNext();) { IEventHandler eventHandler = (IEventHandler)i.Current; if (!eventExecutor.Done) { eventExecutor.Execute(eventHandler); } } } }
/// <summary> Loop through both the application level and context-attached event handlers. /// /// </summary> /// <param name="applicationEventHandlerIterator">Iterator that loops through all global event handlers declared at application level /// </param> /// <param name="contextEventHandlerIterator">Iterator that loops through all global event handlers attached to context /// </param> /// <param name="eventExecutor">Strategy object that executes event handler method /// </param> /// <exception cref="Exception">generic exception potentially thrown by event handlers /// </exception> private static void CallEventHandlers(System.Collections.IEnumerator applicationEventHandlerIterator, System.Collections.IEnumerator contextEventHandlerIterator, IEventHandlerMethodExecutor eventExecutor) { /** * First loop through the event handlers configured at the app level * in the properties file. */ LterateOverEventHandlers(applicationEventHandlerIterator, eventExecutor); /** * Then loop through the event handlers attached to the context. */ LterateOverEventHandlers(contextEventHandlerIterator, eventExecutor); }