KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > jsp > tagext > ObjectClassTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http.jsp.tagext;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
11
12 import org.apache.struts.util.RequestUtils;
13
14 /**
15  * Tag that put the object class in the page context
16  * <p>
17  * The object class is put in the context with :<ul>
18  * <li>The <code>id</code> parameter : used as the identifier</li>
19  * <li>The <code>name</code>,<code>property</code> and <code>scope</code> parameter : used to fetch an object. This object class it then computes</li>
20  * </ul>
21  * </p>
22  *
23  * @author Laurent Etiemble
24  * @version $Revision: 1.4 $
25  * @jsp:tag name="className"
26  * body-content="empty"
27  */

28 public class ObjectClassTag extends TagSupport JavaDoc
29 {
30    /** Id property of the tag */
31    protected String JavaDoc id = null;
32    /** Name property of the tag */
33    protected String JavaDoc name = null;
34    /** Property property of the tag */
35    protected String JavaDoc property = null;
36    /** Scope property of the tag */
37    protected String JavaDoc scope = null;
38
39
40    /**
41     * Executed when the start tag is encountered
42     *
43     * @return An int value to resume or not the processing
44     * @exception JspException In case of problem
45     */

46    public int doStartTag()
47       throws JspException JavaDoc
48    {
49       Object JavaDoc object = null;
50
51       // Look up the requested bean (if necessary)
52
if (property != null)
53       {
54          object = RequestUtils.lookup(pageContext, this.name, this.property, this.scope);
55       }
56       else
57       {
58          object = RequestUtils.lookup(pageContext, this.name, this.scope);
59       }
60
61       if (object == null)
62       {
63          throw new JspException JavaDoc("Unable to find bean " + this.name + " or its property " + this.property);
64       }
65
66       // Put the classname in the pagecontext
67
pageContext.setAttribute(this.id, object.getClass().getName());
68
69       // Continue processing this page
70
return (SKIP_BODY);
71    }
72
73
74    /**
75     * Gets the id value of this tag
76     *
77     * @return The id value
78     * @jsp:attribute name="id"
79     * required="true"
80     * rtexprvalue="true"
81     */

82    public String JavaDoc getId()
83    {
84       return this.id;
85    }
86
87
88    /**
89     * Gets the name value of this tag
90     *
91     * @return The name value
92     * @jsp:attribute name="name"
93     * required="true"
94     * rtexprvalue="true"
95     */

96    public String JavaDoc getName()
97    {
98       return this.name;
99    }
100
101
102    /**
103     * Gets the property value of this tag
104     *
105     * @return The property value
106     * @jsp:attribute name="property"
107     * required="false"
108     * rtexprvalue="true"
109     */

110    public String JavaDoc getProperty()
111    {
112       return this.property;
113    }
114
115
116    /**
117     * Gets the scope value of this tag
118     *
119     * @return The scope value
120     * @jsp:attribute name="scope"
121     * required="false"
122     * rtexprvalue="true"
123     */

124    public String JavaDoc getScope()
125    {
126       return this.scope;
127    }
128
129
130    /** Release all allocated resources. */
131    public void release()
132    {
133       super.release();
134       this.id = null;
135       this.name = null;
136       this.property = null;
137       this.scope = null;
138    }
139
140
141    /**
142     * Sets the id value of this tag
143     *
144     * @param id The new id value
145     */

146    public void setId(String JavaDoc id)
147    {
148       this.id = id;
149    }
150
151
152    /**
153     * Sets the name value of this tag
154     *
155     * @param name The new name value
156     */

157    public void setName(String JavaDoc name)
158    {
159       this.name = name;
160    }
161
162
163    /**
164     * Sets the property value of this tag
165     *
166     * @param property The new property value
167     */

168    public void setProperty(String JavaDoc property)
169    {
170       this.property = property;
171    }
172
173
174    /**
175     * Sets the scope value of this tag
176     *
177     * @param scope The new scope value
178     */

179    public void setScope(String JavaDoc scope)
180    {
181       this.scope = scope;
182    }
183 }
184
185
Popular Tags