KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > jsp > ResourceInjectorImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.web.jsp;
25
26 import java.security.AccessController JavaDoc;
27 import java.security.PrivilegedAction JavaDoc;
28
29 import javax.servlet.ServletContext JavaDoc;
30 import javax.servlet.jsp.tagext.JspTag JavaDoc;
31
32 import org.apache.catalina.core.ApplicationContextFacade;
33 import org.apache.catalina.core.StandardContext;
34 import org.apache.jasper.runtime.ResourceInjector;
35
36 import com.sun.enterprise.Switch;
37 import com.sun.enterprise.deployment.JndiNameEnvironment;
38 import com.sun.enterprise.InjectionManager;
39
40 /**
41  * SJSAS implementation of the org.apache.jasper.runtime.ResourceInjector
42  * interface.
43  *
44  * @author Jan Luehe
45  */

46 public class ResourceInjectorImpl implements ResourceInjector {
47
48     private InjectionManager injectionMgr;
49     private JndiNameEnvironment desc;
50
51     /**
52      * Constructor.
53      */

54     public ResourceInjectorImpl() {
55         injectionMgr = Switch.getSwitch().getInjectionManager();
56     }
57
58
59     /**
60      * Associates this ResourceInjector with the component environment of the
61      * given servlet context.
62      *
63      * @param servletContext The servlet context
64      */

65     public void setContext(ServletContext JavaDoc servletContext) {
66
67         if (!(servletContext instanceof ApplicationContextFacade)) {
68             return;
69         }
70
71         final ApplicationContextFacade contextFacade =
72             (ApplicationContextFacade) servletContext;
73
74         StandardContext context = null;
75
76         context = (StandardContext) AccessController.doPrivileged(
77                 new PrivilegedAction JavaDoc() {
78             public Object JavaDoc run() {
79                 return contextFacade.getUnwrappedContext();
80             }
81         });
82
83         if (context != null) {
84             desc = (JndiNameEnvironment)
85                 Switch.getSwitch().getDescriptorFor(context);
86         }
87     }
88
89    
90     /**
91      * Injects the injectable resources from the component environment
92      * associated with this ResourceInjectorImpl into the given
93      * tag handler instance.
94      *
95      * @param handler The tag handler instance to be injected
96      *
97      * @throws Exception if an error occurs during injection
98      */

99     public void inject(JspTag JavaDoc handler) throws Exception JavaDoc {
100
101         if( desc != null ) {
102             injectionMgr.injectInstance(handler, desc);
103         }
104     }
105
106 }
107
Popular Tags