Search in sources :

Example 66 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class ComponentPageElementImpl method processEventTriggering.

@SuppressWarnings("all")
private boolean processEventTriggering(String eventType, EventContext context, ComponentEventCallback callback) {
    boolean result = false;
    ComponentPageElement component = this;
    String componentId = "";
    // Provide a default handler for when the provided handler is null.
    final ComponentEventCallback providedHandler = callback == null ? new NotificationEventCallback(eventType, completeId) : callback;
    ComponentEventCallback wrapped = new ComponentEventCallback() {

        public boolean handleResult(Object result) {
            if (result instanceof Boolean)
                return (Boolean) result;
            return providedHandler.handleResult(result);
        }
    };
    RuntimeException rootException = null;
    // Because I don't like to reassign parameters.
    String currentEventType = eventType;
    EventContext currentContext = context;
    // Track the location of the original component for the event, even as we work our way up
    // the hierarchy. This may not be ideal if we trigger an "exception" event ... or maybe
    // it's right (it's the location of the originally thrown exception).
    Location location = component.getComponentResources().getLocation();
    while (component != null) {
        try {
            Logger logger = component.getEventLogger();
            ComponentEvent event = new ComponentEventImpl(currentEventType, componentId, currentContext, wrapped, elementResources, exactParameterCountMatch, coreResources.getComponentModel(), logger);
            logger.debug(TapestryMarkers.EVENT_DISPATCH, "Dispatch event: {}", event);
            result |= component.dispatchEvent(event);
            if (event.isAborted())
                return result;
        }// not the JVM).
         catch (Exception ex) {
            if (rootException != null)
                throw rootException;
            // We know component is not null and therefore has a component resources that
            // should have a location.
            // Wrap it up to help ensure that a location is available to the event handler
            // method or,
            // more likely, to the exception report page.
            rootException = new ComponentEventException(ex.getMessage(), eventType, context, location, ex);
            // Switch over to triggering an "exception" event, starting in the component that
            // threw the exception.
            currentEventType = "exception";
            currentContext = createParameterContext(rootException);
            continue;
        }
        // On each bubble up, make the event appear to come from the previous component
        // in which the event was triggered.
        componentId = component.getId();
        component = component.getContainerElement();
    }
    if (rootException != null)
        throw rootException;
    return result;
}
Also used : ComponentEventImpl(org.apache.tapestry5.internal.services.ComponentEventImpl) Logger(org.slf4j.Logger) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) NotificationEventCallback(org.apache.tapestry5.internal.util.NotificationEventCallback) Location(org.apache.tapestry5.commons.Location)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2