KickJava   Java API By Example, From Geeks To Geeks.

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


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

26 public class Register implements ContextAware, ParentAware,
27     ObjectCreationCallback, NullObject {
28
29   private RenderContext _context;
30   private Object JavaDoc _parent;
31   private String JavaDoc _id;
32
33   public void setId(String JavaDoc id) {
34     _id = id;
35   }
36
37   /**
38    * @see org.sapia.gumby.factory.ContextAware#handleContext(org.sapia.gumby.RenderContext)
39    */

40   public void handleContext(RenderContext context) {
41     _context = context;
42   }
43
44   /**
45    * @see org.sapia.gumby.factory.ParentAware#handleParent(java.lang.Object)
46    */

47   public void handleParent(Object JavaDoc parent) {
48     _parent = parent;
49   }
50
51   /**
52    * @see org.sapia.util.xml.confix.ObjectCreationCallback#onCreate()
53    */

54   public Object JavaDoc onCreate() throws ConfigurationException {
55     if(_id == null) {
56       throw new ConfigurationException("id not specified");
57     }
58     String JavaDoc[] idAndScope = ScopeIdParser.parse(_id);
59     if(idAndScope.length == 0) {
60       _context.getSettings().getBindings().put(_id, _parent);
61     } else if(idAndScope.length == 1) {
62       _context.getSettings().getBindings().put(idAndScope[ScopeIdParser.ID],
63           _parent);
64     } else {
65       _context.getEnv().put(idAndScope[ScopeIdParser.ID], _parent,
66           idAndScope[ScopeIdParser.SCOPE]);
67     }
68     return this;
69   }
70
71 }
72
Popular Tags