Reference Manual for Gracelets - 2.0.0.SP2SourceForge.net Logo
5.3 - Framework : Binding Resolvers
The API for getting involved with the way variables are resolved from gracelet scripts is in the gracelets.api.binding package. The base interface gracelets.api.binding.GraceletBindingResolver. This interface is defined as follows:

GraceletBindingResolver.java
Toggle Line Numbers
1 package gracelets.api.binding; 
2  
3 /** 
4  * This is the basic contract/interface for binding resolvers, that can be used as a part 
5  * of variable resolution. 
6  * 
7  * @author elponderador 
8  * @author $Author: ponderator $ 
9  * @version $Id: GraceletBindingResolver.java 1699 2009-07-09 17:55:47Z ponderator $ 
10  */ 
11 public interface GraceletBindingResolver { 
12  
13     /** 
14      * @param key The key whose corresponding value should be retrieved 
15      * @return Returns the value, which can be null, and thus null does not mean the value is not actually set 
16      */ 
17     Object resolve (Object key); 
18      
19     /** 
20      * This is used to assign a value to a key. {@link GraceletBindingResolver#canAssign(Object)} should be 
21      * called first in order to know if this method will be successful. 
22      *  
23      * @param key The key to assign to the value 
24      * @param value The value to assign to the key 
25      */ 
26     void assign (Object key, Object value); 
27      
28     /** 
29      * If this returns false, {@link #assign(Object, Object)} should not be called. 
30      *  
31      * @param key The key to validate 
32      * @return Returns true if this resolver can retrieve a value for the key, otherwise false 
33      */ 
34     boolean canAssign (Object key); 
35      
36 } 
Every gracelet script's binding uses a composite binding resolver to get/set undeclared variable references. The default gracelets implementation defines a set of binding resolvers, used together in the composite binding resolver in the order they are added. These are as follows:
This api is available mainly for those who want to add fundamental script binding resolution to the core framework, since if all you want to do is provide a few variables to your gracelets scripts you can use ScriptBindings defined in a Gracelet Component Library. Also if you are integrating Gracelets into your own framework, you can define a set of binding resolvers and add them in the order you want them to be resolved in, even mixing some of the default Gracelet implementations if you want to. This would be done inside the implementation of the GraceletsPhaseListener.