1 7 package com.inversoft.verge.mvc.view.jsp.model; 8 9 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.tagext.TagSupport ; 12 13 import com.inversoft.util.ReflectionException; 14 import com.inversoft.util.ReflectionTools; 15 import com.inversoft.verge.mvc.MVCException; 16 import com.inversoft.verge.mvc.model.ModelResolution; 17 import com.inversoft.verge.mvc.model.web.WebMetaData; 18 import com.inversoft.verge.util.ScopeTools; 19 20 21 32 public class UseBeanTag extends TagSupport { 33 34 private String className; 35 private String type; 36 private String var; 37 private String scope; 38 39 40 45 public String getClassName() { 46 return className; 47 } 48 49 54 public void setClassName(String className) { 55 this.className = className; 56 } 57 58 63 public String getType() { 64 return type; 65 } 66 67 72 public void setType(String type) { 73 this.type = type; 74 } 75 76 81 public String getVar() { 82 return var; 83 } 84 85 90 public void setVar(String var) { 91 this.var = var; 92 } 93 94 99 public String getScope() { 100 return scope; 101 } 102 103 108 public void setScope(String scope) { 109 this.scope = scope; 110 } 111 112 119 public int doStartTag() throws JspException { 120 try { 121 int scopeInt = ScopeTools.convertScope(scope); 122 int j2eeScope = ScopeTools.convertToJ2EE(scopeInt); 123 Object bean = pageContext.getAttribute(var, j2eeScope); 124 125 if (bean == null) { 126 bean = ReflectionTools.instantiate(className); 127 pageContext.setAttribute(var, bean, j2eeScope); 128 pageContext.setAttribute(var, bean); 129 } else if (bean.getClass() != ReflectionTools.findClass(className)) { 130 throw new JspException ("Bean already exists in " + scope + 131 " scope and is a different type then specified by useBean" + 132 "tag"); 133 } 134 135 WebMetaData md = new WebMetaData(var, className, scopeInt); 136 ModelResolution modelResolution = new ModelResolution(bean, md); 137 ModelResolutionRegistry.store(var, modelResolution, pageContext); 138 } catch (MVCException mvce) { 139 throw new JspException (mvce); 140 } catch (ReflectionException re) { 141 throw new JspException (re); 142 } catch (IllegalArgumentException iae) { 143 throw new JspException (iae); 145 } 146 147 return EVAL_PAGE; 148 } 149 } | Popular Tags |