001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.core.request.handler;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.behavior.Behavior;
021
022/**
023 * Thrown when a listener invocation is attempted on a component or behavior that does not allow it.
024 * For example, somehow the user attempted to invoke link's onclick method on a disabled link.
025 *
026 * @author igor
027 */
028public class ListenerInvocationNotAllowedException extends RuntimeException
029{
030        private static final long serialVersionUID = 1L;
031
032        private final Component component;
033        private final Behavior behavior;
034
035        /**
036         * Constructor
037         *
038         * @param component
039         * @param behavior
040         * @param message
041         */
042        public ListenerInvocationNotAllowedException(Component component, Behavior behavior, String message)
043        {
044                super(message + detail(component, behavior));
045                this.component = component;
046                this.behavior = behavior;
047        }
048
049        private static String detail(Component component,
050                Behavior behavior)
051        {
052                StringBuilder detail = new StringBuilder("Component: ").append(component.toString(false));
053                if (behavior != null)
054                {
055                        detail.append(" Behavior: ").append(behavior.toString());
056                }
057                return detail.toString();
058        }
059
060        /**
061         * @return component that was the target of invocation or hosted the behavior that was
062         */
063        public Component getComponent()
064        {
065                return component;
066        }
067
068        /**
069         * @return behavior that was the target of invocation or {@code null}
070         */
071        public Behavior getBehavior()
072        {
073                return behavior;
074        }
075
076
077}