1 2 17 package org.apache.taglibs.dbtags.preparedstatement; 18 19 import java.lang.reflect.Field ; 20 import java.sql.PreparedStatement ; 21 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 31 public class BaseSetterTag extends TagSupport { 32 33 protected int _position = 1; 34 protected String _attributeName = null; 35 36 41 public void setPosition(int position) { 42 _position = position; 43 } 44 45 52 public void setName(String attributeName) { 53 _attributeName = attributeName; 54 } 55 56 64 protected Object getAttribute(String name) 65 throws JspTagException { 66 Object object = pageContext.getAttribute(name); 67 68 if (object == null) { 69 throw new JspTagException ("attribute " + name + " does not exist"); 70 } 71 72 return object; 73 } 74 75 82 protected PreparedStatement getPreparedStatement() 83 throws JspTagException { 84 try { 85 PreparedStatementImplTag stmtTag = 86 (PreparedStatementImplTag) findAncestorWithClass(this, Class.forName("org.apache.taglibs.dbtags.preparedstatement.PreparedStatementImplTag")); 87 return stmtTag.getPreparedStatement(); 88 } catch (ClassNotFoundException e) { 89 throw new JspTagException (e.toString()); 90 } 91 } 92 93 103 protected int getSqlTypeForFieldName(String fieldName) 104 throws JspTagException { 105 try { 106 Class typesClass = Class.forName("java.sql.Types"); 107 Field typeField = typesClass.getField(fieldName); 108 return typeField.getInt(null); 109 } catch (ClassNotFoundException e) { 110 throw new JspTagException (e.toString()); 111 } catch (NoSuchFieldException e) { 112 throw new JspTagException ("Illegal argument: setnull tag could not find = '" + 113 fieldName + "' field in the java.sql.Types class" + e.toString()); 114 } catch (IllegalAccessException e) { 115 throw new JspTagException (e.toString()); 116 } 117 } 118 119 public void release() { 120 _position = 1; 121 _attributeName = null; 122 } 123 } 124 | Popular Tags |