KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > gumby > tags > Ref


1 package org.sapia.gumby.tags;
2
3 import org.sapia.gumby.RenderContext;
4 import org.sapia.gumby.factory.ContextAware;
5 import org.sapia.gumby.tags.support.ScopeIdParser;
6 import org.sapia.util.xml.confix.ConfigurationException;
7 import org.sapia.util.xml.confix.ObjectCreationCallback;
8 import org.sapia.util.xml.confix.ObjectWrapperIF;
9
10 /**
11  * @author Yanick Duchesne
12  *
13  * <dl>
14  * <dt><b>Copyright: </b>
15  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
16  * Source Software </a>. All Rights Reserved.</dd>
17  * </dt>
18  * <dt><b>License: </b>
19  * <dd>Read the license.txt file of the jar or visit the <a
20  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
21  * OSS web site</dd>
22  * </dt>
23  * </dl>
24  */

25 public class Ref implements ContextAware, ObjectCreationCallback,
26     ObjectWrapperIF {
27
28   private RenderContext _context;
29   private Object JavaDoc _ref;
30
31   public void setId(String JavaDoc id) {
32     String JavaDoc[] idAndScope = ScopeIdParser.parse(id);
33     if(idAndScope.length <= 1) {
34       _ref = _context.getSettings().getBindings().get(id);
35     } else {
36       _ref = _context.getEnv().get(idAndScope[ScopeIdParser.ID],
37           idAndScope[ScopeIdParser.SCOPE]);
38     }
39   }
40
41   /**
42    * @see org.sapia.gumby.factory.ContextAware#handleContext(org.sapia.gumby.RenderContext)
43    */

44   public void handleContext(RenderContext context) {
45     _context = context;
46   }
47
48   /**
49    * @see org.sapia.util.xml.confix.ObjectWrapperIF#getWrappedObject()
50    */

51   public Object JavaDoc getWrappedObject() {
52     if(_ref == null) {
53       throw new NullPointerException JavaDoc(
54           "Object reference invalid; 'id' not set or not resolve to existing object");
55     }
56     return _ref;
57   }
58
59   /**
60    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
61    */

62   public Object JavaDoc onCreate() throws ConfigurationException {
63     return _ref;
64   }
65
66 }
67
Popular Tags