Coverage details for org.chwf.taglib.jutil.UseTag

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.taglib.jutil;
34  
35 import javax.servlet.ServletException;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.jsp.JspException;
38 import javax.servlet.jsp.PageContext;
39  
40 import org.chwf.plugin.Logger;
41 import org.chwf.servlet.ControllerException;
42 import org.chwf.servlet.InvocationContext;
43 import org.chwf.servlet.ServletUtils;
44 import org.chwf.servlet.engine.ControllerMapper;
45 import org.chwf.servlet.engine.URIMapper;
46 import org.chwf.taglib.base.ObjectTagSupport;
47 import org.chwf.taglib.base.TagException;
48 import org.chwf.util.MiscUtils;
49  
50 /**
51  * Tag handler for the <code>&lt;use&gt;</code> tag.
52  *
53  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
54  */
558public class UseTag extends ObjectTagSupport {
56  
57   /** The controller name. */
58   private String controller;
59  
60   /**
61    * Clean up data for tag handler reuse and pooling. Should be overridden in
62    * tag handler. Subclasses should always invoke their superclass's cleanup
63    * method: <code>super.cleanup()</code>
64    */
65   public void cleanup() {
661    super.cleanup();
671    this.controller = null;
681  }
69   
70   /**
71    * Calls superclass method. Is present here because of a bug in some servlet
72    * engines that requires tag attibute setters to be defined in the tag class
73    * itself.
74    *
75    * @param var The object name.
76    */
77   public void setVar(String var) {
782    super.setVar(var);
792  }
80  
81   /**
82    * The controller name.
83    *
84    * @param controller The controller name.
85    */
86   public void setController(String controller) {
873    this.controller = controller;
883  }
89  
90   /**
91    * The controller name.
92    *
93    * @return The controller name.
94    */
95   public String getController() {
962    return this.controller;
97   }
98   
99   /**
100    * Calls superclass method. Is present here because of a bug in some servlet
101    * engines that requires tag attibute setters to be defined in the tag class
102    * itself.
103    *
104    * @param property The property name.
105    * @throws JspException For errors.
106    */
107   public void setProperty(String property) throws JspException {
1082    super.setProperty(property);
1092  }
110  
111   /**
112    * Retrieve controller.
113    *
114    * @return The controller.
115    * @throws ControllerException For controller failures.
116    */
117   private Class getControllerClass() throws ControllerException {
1181    return URIMapper.getControllerFromShortName(this.controller);
119   }
120  
121   /**
122    * Stores the retrieved bean in the specified variable.
123    *
124    * @return SKIP_BODY
125    * @throws JspException For controller exceptions.
126    */
127   public int doStart() throws JspException {
128     try {
1291      Object result =
130         initBean(pageContext, getVar(), getControllerClass(), getProperty());
1311      storeDefaultObject(result);
1321    } catch (ControllerException ex) {
1330      Logger.getInstance().log(UseTag.class, "Page Controller failed", ex);
1340      throw new TagException(ex);
135     } catch (ServletException ex) {
1360      Throwable root = ex.getRootCause();
1370      Logger.getInstance().log(UseTag.class, "Page Controller failed", ex);
1380      throw new TagException(root);
139     }
1401    return SKIP_BODY;
141   }
142  
143   /**
144    * Call bean initializer. Public to facilitate testing.
145    *
146    * @param pageContext The page context.
147    * @param var The variable name to store the bean.
148    * @param controller The controller.
149    * @param bean The bean name.
150    * @return The bean object.
151    * @throws ControllerException For controller exceptions.
152    * @throws ServletException For servlet exceptions.
153    */
154   public static Object initBean(
155     PageContext pageContext,
156     String var,
157     Class controller,
158     String bean)
159     throws ControllerException, ServletException {
160  
1614    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
1624    ControllerMapper mapper = ControllerMapper.getMapper(controller);
1634    String beanGetter = "get" + MiscUtils.capitalize(bean);
1644    InvocationContext context = mapper.invoke(request, beanGetter);
1653    if (context.hasError()) {
1660      throw new ServletException(context.getError());
167     }
1683    Object result = context.getResult();
1693    ServletUtils.setPageAttribute(pageContext, var, result);
1703    return result;
171   }
172 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.