    001    // Copyright 2006, 2008 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    //     http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.internal.util;
    016
    017    import org.apache.tapestry5.ComponentEventCallback;
    018
    019    /**
    020     * A {@link org.apache.tapestry5.ComponentEventCallback} used for notification events. Event handler methods may return
    021     * true (to abort the event) or false (to allow the event to continue bubbling up), but all other values are forbidden.
    022     */
    023    public class NotificationEventCallback implements ComponentEventCallback
    024    {
    025        private final String eventType;
    026
    027        private final String completeId;
    028
    029        public NotificationEventCallback(String eventType, String completeId)
    030        {
    031            this.eventType = eventType;
    032            this.completeId = completeId;
    033        }
    034
    035        public boolean handleResult(Object result)
    036        {
    037            if (result instanceof Boolean) return ((Boolean) result);
    038
    039            throw new IllegalArgumentException(
    040                    UtilMessages.noReturnValueAccepted(eventType, completeId, result));
    041        }
    042
    043    }