随笔-0  评论-0  文章-9  trackbacks-0
WebAdapterServlet 运行机制(2)
 LinkedList applications =
            (LinkedList) session.getAttribute(SESSION_ATTR_APPS);
        
if (applications == null)
            
return null;

        
// Search for the application (using the application URI) from the list
        Application application = null;
        
for (Iterator i = applications.iterator();
            i.hasNext() 
&& application == null;
            ) 
{
            Application a 
= (Application) i.next();
            String aPath 
= a.getURL().getPath();
            String servletPath 
=
                request.getContextPath() 
+ request.getServletPath();
            
if (servletPath.length() < aPath.length())
                servletPath 
+= "/";
            
if (servletPath.equals(aPath))
                application 
= a;
        }


        
// Remove stopped applications from the list
        if (application != null && !application.isRunning()) {
            applications.remove(application);
            application 
= null;
        }


根据request 得到适当的application,如果为第一次请求则建立一个application
 application = createApplication(request);
详细过程如下:
URL applicationUrl = getApplicationUrl(request);
创建session 中的applications.
// Get application list.
        HttpSession session = request.getSession();
        
if (session == null)
            
return null;
        LinkedList applications 
=
            (LinkedList) session.getAttribute(SESSION_ATTR_APPS);
        
if (applications == null{
            applications 
= new LinkedList();
            session.setAttribute(SESSION_ATTR_APPS, applications);
            HttpSessionBindingListener sessionBindingListener 
=
                
new SessionBindingListener(applications);
            session.setAttribute(
                SESSION_BINDING_LISTENER,
                sessionBindingListener);
        }
初始化并启动
 application = (Application) this.applicationClass.newInstance();
            applications.add(application);
            application.addListener((Application.WindowAttachListener) 
this);
            application.addListener((Application.WindowDetachListener) 
this);
            application.setLocale(request.getLocale());
            application.start(
                applicationUrl,
                
this.applicationProperties,
                
new WebApplicationContext(session));
启动过程非常简单,设置变量,并调用application.init()
public void start(URL applicationUrl, Properties applicationProperties, ApplicationContext context) {
        
this.applicationUrl = applicationUrl;
        
this.properties = applicationProperties;
        
this.context = context;
        init();
        applicationIsRunning 
= true;
    }

posted on 2005-08-05 18:43 staunch 阅读(175) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: