001: /*
002: * $Id: AbstractBehavior.java 508111 2007-02-15 19:50:42Z ivaynberg $
003: * $Revision: 508111 $ $Date: 2007-02-15 20:50:42 +0100 (Thu, 15 Feb 2007) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.behavior;
019:
020: import wicket.Component;
021: import wicket.markup.ComponentTag;
022:
023: /**
024: * Adapter implementation of {@link wicket.behavior.IBehavior}. It is
025: * recommended to extend from this class instead of directly implementing
026: * {@link wicket.behavior.IBehavior} as this class has an extra clean
027: *
028: * @author Ralf Ebert
029: * @author Eelco Hillenius
030: */
031: public abstract class AbstractBehavior implements IBehavior {
032: /**
033: * Construct.
034: */
035: public AbstractBehavior() {
036: }
037:
038: /**
039: * @see wicket.behavior.IBehavior#bind(wicket.Component)
040: */
041: public void bind(final Component component) {
042: }
043:
044: /**
045: * @see wicket.behavior.IBehavior#detachModel(Component)
046: */
047: public void detachModel(Component component) {
048: cleanup();
049: }
050:
051: /**
052: * @see wicket.behavior.IBehavior#onComponentTag(wicket.Component,
053: * wicket.markup.ComponentTag)
054: */
055: public void onComponentTag(final Component component,
056: final ComponentTag tag) {
057: }
058:
059: /**
060: * @see wicket.behavior.IBehavior#rendered(wicket.Component)
061: */
062: public final void rendered(final Component component) {
063: try {
064: onRendered(component);
065: } finally {
066: cleanup();
067: }
068: }
069:
070: /**
071: * Called when a component that has this behavior coupled was rendered.
072: *
073: * @param component
074: * the component that has this behavior coupled
075: */
076: public void onRendered(Component component) {
077: }
078:
079: /**
080: * @see wicket.behavior.IBehavior#exception(wicket.Component,
081: * java.lang.RuntimeException)
082: */
083: public void exception(Component component,
084: RuntimeException exception) {
085: try {
086: onException(component, exception);
087: } finally {
088: cleanup();
089: }
090: }
091:
092: /**
093: * In case an unexpected exception happened anywhere between
094: * onComponentTag() and rendered(), onException() will be called for any
095: * behavior.
096: *
097: * @param component
098: * the component that has a reference to this behavior and during
099: * which processing the exception occured
100: * @param exception
101: * the unexpected exception
102: */
103: public void onException(Component component,
104: RuntimeException exception) {
105: }
106:
107: /**
108: * This method is called either by {@link #onRendered(Component)} or
109: * {@link #onException(Component, RuntimeException)} AFTER they called their
110: * respective template methods. Override this template method to do any
111: * necessary cleanup.
112: */
113: public void cleanup() {
114: }
115: }
|