KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > web > WebUtils


1 package jfun.yan.web;
2
3 import java.beans.IntrospectionException JavaDoc;
4
5 import jfun.yan.Component;
6 import jfun.yan.xml.NutsUtils;
7 import jfun.yan.xml.nuts.ArgumentsAndPropertiesNut;
8
9 /**
10  * Web integration related utilities.
11  * <p>
12  * @author Ben Yu
13  * Jan 17, 2006 1:24:11 PM
14  */

15 public class WebUtils {
16   /**
17    * The default property name for receiving ServletContext instance.
18    */

19   public static final String JavaDoc DEFAULT_SERVLET_CONTEXT_PROPERTY = "servletContext";
20   /**
21    * Wrap a Component to set the service object identified by
22    * {@link YanLoader#SERVLET_CONTEXT_KEY} to the specified property.
23    * <p>
24    * Nothing happens if the property cannot be found, or if the property type doesn't match
25    * or if the property is already explicitly specified in the tag
26    * or if the property is implied by a wildcard.
27    * </p>
28    * @param c The Component object to wrap.
29    * @param name the property name.
30    * @param nut the Nut object.
31    * @return the Component that's responsible for setting the property if any.
32    */

33   public static final Component setPossibleServletContext(
34       Component c, String JavaDoc name, ArgumentsAndPropertiesNut nut){
35     if(name==null || name.length()==0) return c;
36     //when all properties are specified or the property key is explicitly specified,
37
//we skip.
38
if(nut.isAllProperties() || nut.containsExplicitProperty(name))
39       return c;
40     final Object JavaDoc servletcontext = nut.getNutEnvironment()
41     .findService(YanLoader.SERVLET_CONTEXT_KEY);
42     if(servletcontext==null){
43       return c;
44     }
45     try{
46       return NutsUtils.setPossiblePropertyValue(c, name, servletcontext);
47     }
48     catch(IntrospectionException JavaDoc e){
49       throw nut.raise(e);
50     }
51   }
52 }
53
Popular Tags