KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > NutEnvironment


1 package jfun.yan.xml;
2
3 import java.io.File JavaDoc;
4
5 import jfun.yan.Component;
6 import jfun.yan.ParameterBinder;
7 import jfun.yan.PropertyBinder;
8 import jfun.yan.lifecycle.DefaultLifecycleManager;
9 import jfun.yan.util.deserializer.Deserializer;
10 import jfun.yan.util.resource.ResourceLoader;
11
12
13 /**
14  * The environment that a Nut object is running in.
15  * <p>
16  * @author Ben Yu
17  * Nov 11, 2005 1:21:55 PM
18  */

19 public interface NutEnvironment{
20   /**
21    * Get the ResourceLoader object for loading resources.
22    */

23   ResourceLoader getResourceLoader();
24   
25   /**
26    * Get the class loader used to load the Nut tags.
27    */

28   ClassLoader JavaDoc getNutClassLoader();
29   /**
30    * Get the class loader used to load the component classes.
31    */

32   ClassLoader JavaDoc getComponentClassLoader();
33   /**
34    * Convert an object to a target type.
35    * @param target_type the target type.
36    * @param val the object to be converted.
37    * @param loc the location within the source that does the conversion.
38    * @return the object of the target type.
39    */

40   Object JavaDoc convert(Class JavaDoc target_type, Object JavaDoc val, Location loc);
41   /**
42    * Transform a Component so that the instantiated instance is converted
43    * to the target type.
44    * @param target_type the target type.
45    * @param c the Component to transform.
46    * @param loc the location within the source that does the casting.
47    * @return the Component that instantiates object of the target type.
48    */

49   Component cast(Class JavaDoc target_type, Component c, Location loc);
50   /**
51    * Get the base directory setting of the system.
52    * It may be different from <code>new File(".")</code>.
53    */

54   File JavaDoc getBaseDir();
55
56   /**
57    * Get the auto wiring mode specified by the mode name.
58    * @param mode_name the mode name.
59    * @param loc the Location within the source file.
60    * @return the PropertyBinder object encapsulating the auto wiring mode,
61    * or null if this is manual wiring.
62    * @throws ConfigurationException if the mode name is not recognized.
63    */

64   PropertyBinder getPropertyWiringMode(String JavaDoc mode_name, Location loc)
65   throws ConfigurationException;
66   /**
67    * Get the auto wiring mode specified by the mode name.
68    * @param mode_name the mode name.
69    * @param loc the location within the source file.
70    * @return the ParameterBinder object encapsulating the auto wiring mode,
71    * or null if this is manual wiring.
72    * @throws ConfigurationException if the mode name is not recognized.
73    */

74   ParameterBinder getParameterWiringMode(String JavaDoc mode_name, Location loc)
75   throws ConfigurationException;
76   
77   /**
78    * Do we by default eagerly instantiate components?
79    */

80   boolean isEagerlyInstantiating();
81   /**
82    * To find an optional service provided by the system.
83    * @param key the key to the service.
84    * @return the service object.
85    * Null is returned if the key is not found.
86    */

87   Object JavaDoc findService(Object JavaDoc key);
88   
89   /**
90    * Get the lifecycle manager.
91    */

92   DefaultLifecycleManager getLifecycleManager();
93   
94   /**
95    * Add a Component to the list to be eagerly instantiated.
96    * @param seq the sequence number of the component within the enclosing scope.
97    * This number is important to figure out the evaluation order of the components.
98    * @param key the key of the component.
99    * @param c the component.
100    */

101   void registerEagerInstantiation(int seq, Object JavaDoc key, Component c);
102   
103   /**
104    * Dynamically register an object.
105    * @param key the key of the object.
106    * @param val the object.
107    * @param overridable whether this registration is overridable.
108    * @param overriding do we override when the same key is already used
109    * by another dynamically registered entry.
110    * @param loc the location of the entry.
111    */

112   void registerDynamic(Object JavaDoc key, Object JavaDoc val,
113       boolean overridable, boolean overriding, Location loc);
114   /**
115    * Convert a string literal to an object of a certain type.
116    * @param type the target type.
117    * @param text the string literal.
118    * @return the object of the target type.
119    * @throws Throwable when any error happens.
120    */

121   Object JavaDoc deserialize(Class JavaDoc type, String JavaDoc text)
122   throws Throwable JavaDoc;
123   /**
124    * To register a Deserializer.
125    * @param type the type that uses the Deserializer to convert
126    * literal string to objects of this type.
127    * @param deserializer the Deserializer object.
128    * @param overriding whether override the existent Deserializer if any.
129    * and an Deserializer object is already registered for the target type.
130    * @param mandatory true if this registration has to go through.
131    * @exception IllegalArgumentException if not overriding
132    * and an Deserializer object is already registered for the target type.
133    */

134   void registerDeserializer(Class JavaDoc type, Deserializer deserializer,
135       boolean overriding, boolean mandatory);
136   /**
137    * To determine if string literal can be converted to the target type.
138    * @param type the target type.
139    * @return true if convertible.
140    */

141   boolean isDeserializable(Class JavaDoc type);
142 }
143
Popular Tags