(no commit message)
[utils] / wicket / components / src / main / java / org / wamblee / wicket / page / ExpireBehavior.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.wicket.page;
17
18 import java.util.logging.Logger;
19
20 import org.apache.wicket.markup.html.WebPage;
21
22 /**
23  * Bahevior that will expire a page when the page is disabled.
24  * Implementations should implemnet 
25  * 
26  * @author Erik Brakkee
27  * 
28  */
29 public abstract class ExpireBehavior extends AbstractPageBehavior {
30     private static final Logger LOGGER = Logger.getLogger(ExpireBehavior.class.getName());
31
32     /**
33      * Constructs the behavior.
34      */
35     public ExpireBehavior() { 
36         super();
37     }
38
39     @Override
40     public void onDetach(WebPage aPage) {
41         if (isExpired(aPage)) {
42             aPage.getPageMap().remove(aPage);
43         }
44     }
45     
46     /**
47      * Must be implemented to determine if a page is expired.
48      * @param aPage Page to check. If a behavior instance is only used on one page then this 
49      *     argument is always that page so it can bne ignored in that case.
50      * @return
51      */
52     protected abstract boolean isExpired(WebPage aPage); 
53     
54 }