1 package com.quadcap.http.servlets.jsp; 2 3 40 41 import java.io.PrintWriter ; 42 43 import java.util.Hashtable ; 44 45 import org.xml.sax.AttributeList ; 46 47 import com.quadcap.util.Debug; 48 49 55 public class TagJspUseBean extends TagJsp { 56 static Hashtable scopes = new Hashtable (); 57 static { 58 scopes.put("page", "PageContext.PAGE_SCOPE"); 59 scopes.put("request", "PageContext.REQUEST_SCOPE"); 60 scopes.put("session", "PageContext.SESSION_SCOPE"); 61 scopes.put("application", "PageContext.APPLICATION_SCOPE"); 62 } 63 64 public TagJspUseBean() {} 65 66 public TagJspUseBean(TagContext context) { 67 super(context); 68 } 69 70 public TagInstance makeInstance(TagContext context) { 71 return new TagJspUseBean(context); 72 } 73 74 public void doStartTag(String tagName, AttributeList attributes) 75 throws JspException 76 { 77 super.doStartTag(tagName, attributes); 78 PrintWriter w = context.getPrintWriter(); 79 String id = attributes.getValue("id"); 80 String clazz = attributes.getValue("class"); 81 String scope = attributes.getValue("scope"); 82 if (scope == null || scope.equals("")) scope = "page"; 83 String scopeVal = (String )scopes.get(scope); 84 if (scopeVal == null) { 85 throw new JspException("Invalid scope for <jsp:useBean: " + 86 scope); 87 } 88 w.print(" "); 90 w.print(clazz); 91 w.print(" "); 92 w.print(id); 93 w.println(" = null;"); 94 95 w.println(" synchronized (this) {"); 97 98 w.print (" "); 100 w.print(id); 101 w.print(" = ("); 102 w.print(clazz); 103 w.print(")pageContext.getAttribute(\""); 104 w.print(id); 105 w.print("\", "); 106 w.print(scopeVal); 107 w.println(");"); 108 109 w.print (" if ("); 111 w.print(id); 112 w.println(" == null) {"); 113 114 w.print (" "); 116 w.print(id); 117 w.print(" = ("); 118 w.print(clazz); 119 w.print(")Class.forName(\""); 120 w.print(clazz); 121 w.println("\").newInstance();"); 122 123 w.print (" pageContext.setAttribute(\""); 125 w.print(id); 126 w.print("\", "); 127 w.print(id); 128 w.print(", "); 129 w.print(scopeVal); 130 w.println(");"); 131 132 w.println(" }"); 134 135 w.println(" }"); 137 } 138 139 public void doCharacters(char[] ch, int off, int cnt) throws JspException { 140 doTemplateCharacters(ch, off, cnt); 141 } 142 } 143 144 | Popular Tags |