View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.logic.interceptor;
17  
18  import java.util.Iterator;
19  import java.util.Map;
20  
21  import org.aopalliance.intercept.MethodInterceptor;
22  import org.aopalliance.intercept.MethodInvocation;
23  import org.seasar.tuigwaa.logic.TgwFunction;
24  import org.seasar.tuigwaa.util.TgwContext;
25  
26  import com.isenshi.util.TableMap;
27  
28  public class PageViewInterceptorImpl implements PageViewInterceptor,
29  		MethodInterceptor {
30  
31  	private TableMap functionTableMap = new TableMap();
32  
33  	public void deregisterAction(String siteName, String pageName,
34  			String logicName) {
35  		functionTableMap.remove(siteName + "/" + pageName, logicName);
36  	}
37  
38  	public void registerAction(String siteName, String pageName,
39  			String logicName, TgwFunction tfunction) {
40  		functionTableMap.put(tfunction, siteName + "/" + pageName, logicName);
41  	}
42  
43  	public Object invoke(MethodInvocation invocation) throws Throwable {
44  
45  		String siteName = TgwContext.getSiteName();
46  		String pageName = TgwContext.getPageName();
47  		String path = siteName + "/" + pageName;
48  
49  		Map funcMap = functionTableMap.getSubMap(path);
50  
51  		if (funcMap != null) {
52  			for(Iterator i=funcMap.values().iterator();i.hasNext();){
53  				TgwFunction func = (TgwFunction)i.next();
54  				func.run(null);
55  			}
56  		}
57  		return invocation.proceed();
58  	}
59  }