KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > container > visitor > VisitorFactory


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7  http://www.apache.org/licenses/LICENSE-2.0
8
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package com.jdon.container.visitor;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpSession JavaDoc;
20
21 import com.jdon.bussinessproxy.TargetMetaDef;
22 import com.jdon.util.Debug;
23
24 /**
25  * Factory that get visitors for the container that have been optimized by
26  * cache(HttpSession)
27  *
28  * replace this class in container.xml ,we can change HttpSession
29  * with another session type, HttpSession is binding to Web container.
30  *
31  *
32  * <p>
33  *
34  * @author <a HREF="mailto:banqiao@jdon.com">banq </a>
35  * </p>
36  */

37 public class VisitorFactory {
38
39     private final static String JavaDoc module = VisitorFactory.class.getName();
40     
41     private ComponentVisitor componentVisitor;
42     
43     /**
44      * @param componentVisitor
45      */

46     public VisitorFactory(ComponentVisitor componentVisitor) {
47         this.componentVisitor = componentVisitor;
48     }
49     /**
50      * return a ComponentVisitor with cache.
51      * the httpSession is used for optimizing the component performance
52      * @param request
53      * @param targetMetaDef
54      * @return
55      */

56     public ComponentVisitor getVisitor(HttpServletRequest JavaDoc request,
57             TargetMetaDef targetMetaDef) {
58         HttpSession JavaDoc session = request.getSession();
59         ComponentVisitor cm = (ComponentVisitor)session.getAttribute("HttpSessionProxyVisitor");
60         if (cm == null){
61             Debug.logVerbose("[JdonFramework] first time get ComponentVisitor ", module);
62             cm = new HttpSessionProxyVisitor(componentVisitor);
63             session.setAttribute("HttpSessionProxyVisitor", cm);
64         }
65         return cm;
66     }
67
68     /**
69      * return a ComponentVisitor without cache.
70      * @param request
71      * @param targetMetaDef
72      * @param cw
73      * @return
74      */

75     public ComponentVisitor getVisitor(TargetMetaDef targetMetaDef) {
76         return componentVisitor;
77
78     }
79
80 }
81
Popular Tags