KickJava   Java API By Example, From Geeks To Geeks.

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


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

24 public class ViewTag implements ContextAware, ObjectWrapperIF, NullObject {
25
26   private View _view;
27   private RenderContext _context;
28
29   public void setScope(String JavaDoc scope) {
30     try {
31       _view = (View) _context.getEnv().getScope(scope);
32     } catch(ClassCastException JavaDoc e) {
33       throw new IllegalStateException JavaDoc("Scope '" + scope
34           + "' not an instance of " + View.class.getName() + ": "
35           + _context.getEnv().getScope(scope).getClass().getName());
36     }
37     if(_view == null) {
38       _view = _context.createView(scope);
39     }
40   }
41
42   /**
43    * @see org.sapia.gumby.factory.ContextAware#handleContext(org.sapia.gumby.RenderContext)
44    */

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

52   public Object JavaDoc getWrappedObject() {
53     if(_view == null) {
54       throw new IllegalStateException JavaDoc("View not set");
55     }
56     return _view;
57   }
58 }
59
Popular Tags