KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > container > finder > ServletContainerFinder


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.finder;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.ServletContext JavaDoc;
20
21 import com.jdon.container.ContainerWrapper;
22 import com.jdon.container.startup.ContainerSetupScript;
23 import com.jdon.container.builder.ContainerBuilder;
24 import com.jdon.util.Debug;
25
26 /**
27  * the components finder that registed in container
28  * same as JNDI Lookup.
29  *
30  * <p>@author <a HREF="mailto:banqiao@jdon.com">banq</a></p>
31  */

32 public class ServletContainerFinder {
33   private final static String JavaDoc module = ServletContainerFinder.class.getName();
34   
35   private ContainerSetupScript ContainerSetupScript = new ContainerSetupScript();
36
37   public ContainerWrapper findContainer(HttpServletRequest JavaDoc request) {
38     ServletContext JavaDoc sc = request.getSession().getServletContext();
39     ContainerWrapper containerWrapper = findContainer(sc);
40     
41     return containerWrapper;
42   }
43
44   /**
45    * lazy startup container
46    * when first time the method is called, it will startup the
47    * container
48    * @param sc ServletContext
49    * @return ContainerWrapper
50    * @throws Exception
51    */

52   public ContainerWrapper findContainer(ServletContext JavaDoc sc) {
53     ContainerBuilder cb = (ContainerBuilder) sc.getAttribute(ContainerBuilder.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
54     ContainerWrapper containerWrapper = null;
55     try{
56         if (!cb.isStartup())
57             ContainerSetupScript.startup(sc);
58         containerWrapper = cb.getContainerWrapper();
59     }catch(Exception JavaDoc ex){
60         Debug.logError("[JdonFramework] not find jdonFramework configuration file" , module);
61     }
62     return containerWrapper;
63   }
64
65 }
66
Popular Tags