/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wamblee.wicket.behavior;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebResponse;
/**
* Implements a composite page behavior which invokes all behaviors in the order they were
* added.
*
* To use this in an arbitrary page, override onBeforeRender()
,
* setHeaders()
and onAfterRender
in the page and delegate to the
* corresponding methods in this class.
*
* @author Erik Brakkee
*/
public class CompositePageBehavior implements PageBehavior {
private List behaviors;
/**
* Constructs the compositie.
*/
public CompositePageBehavior() {
behaviors = new ArrayList();
}
/**
* Adds a behavior.
* @param aBehavior Behavior
*/
public void add(PageBehavior aBehavior) {
behaviors.add(aBehavior);
}
@Override
public void onAfterRender(WebPage aPage) {
for (PageBehavior behavior: behaviors) {
behavior.onAfterRender(aPage);
}
}
@Override
public void onBeforeRender(WebPage aPage) {
for (PageBehavior behavior: behaviors) {
behavior.onBeforeRender(aPage);
}
}
@Override
public void setHeaders(WebPage aPage, WebResponse aResponse) {
for (PageBehavior behavior: behaviors) {
behavior.setHeaders(aPage, aResponse);
}
}
}