1 28 29 package com.caucho.jstl.rt; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import javax.servlet.jsp.JspException ; 35 import javax.servlet.jsp.jstl.core.Config; 36 import javax.servlet.jsp.tagext.TagSupport ; 37 import javax.sql.DataSource ; 38 import java.util.logging.Logger ; 39 40 public class SqlSetDataSourceTag extends TagSupport { 41 private static final Logger log = Log.open(SqlSetDataSourceTag.class); 42 private static final L10N L = new L10N(SqlSetDataSourceTag.class); 43 44 private Object _dataSource; 45 46 private String _url; 47 private String _driver; 48 private String _user; 49 private String _password; 50 51 private String _var; 52 private String _scope; 53 54 57 public void setDataSource(Object dataSource) 58 { 59 _dataSource = dataSource; 60 } 61 62 65 public void setUrl(String url) 66 { 67 _url = url; 68 } 69 70 73 public void setDriver(String driver) 74 { 75 _driver = driver; 76 } 77 78 81 public void setUser(String user) 82 { 83 _user = user; 84 } 85 86 89 public void setPassword(String password) 90 { 91 _password = password; 92 } 93 94 97 public void setVar(String var) 98 { 99 _var = var; 100 } 101 102 105 public void setScope(String scope) 106 { 107 _scope = scope; 108 } 109 110 public int doStartTag() throws JspException 111 { 112 String var = _var; 113 114 if (var == null) 115 var = Config.SQL_DATA_SOURCE; 116 117 DataSource dataSource = null; 118 119 if (_dataSource != null) 120 dataSource = SqlQueryTag.getDataSource(pageContext, _dataSource); 121 else 122 dataSource = openDataSource(_driver, _url, _user, _password); 123 124 CoreSetTag.setValue(pageContext, var, _scope, dataSource); 125 126 return SKIP_BODY; 127 } 128 129 private DataSource openDataSource(String driver, String url, 130 String user, String password) 131 throws JspException 132 { 133 try { 134 return com.caucho.jstl.el.SqlSetDataSourceTag.openDataSource(driver, url, user, password); 135 } catch (Exception e) { 136 throw new JspException (e); 137 } 138 } 139 } 140 | Popular Tags |