KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > etc > injection > InjectionUtils


1 package jfun.yan.etc.injection;
2
3 import jfun.yan.Component;
4 import jfun.yan.Components;
5
6 /**
7  * Utility classes for post-injection.
8  * <p>
9  * @author Ben Yu
10  * Dec 17, 2005 11:31:39 AM
11  */

12 public class InjectionUtils {
13   /**
14    * Adapt any Component to be one that instantiates Injection instance.
15    * @param c the Component.
16    * @return the Component that instantiates Injection instance.
17    */

18   public static Component toInjection(Component c){
19     final Class JavaDoc type = c.getType();
20     if(type!=null && Injection.class.isAssignableFrom(type)){
21       return c;
22     }
23     else return returnTrue(c).factory(Injection.class);
24   }
25   
26   /**
27    * Make the Component always returns "true".
28    * @param c the Component to transform.
29    * @return the new Component object that returns true.
30    */

31   public static Component returnTrue(Component c){
32     return c.seq(Components.value(true));
33   }
34 }
35
Popular Tags