jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hor...@apache.org
Subject cvs commit: jakarta-taglibs/standard/examples/web/sql Update.jsp Transaction.jsp QueryParam.jsp QueryIterate.jsp QueryDirect.jsp DriverSetup.jsp
Date Tue, 16 Apr 2002 00:01:35 GMT
horwat      02/04/15 17:01:35

  Modified:    standard/src/org/apache/taglibs/standard/tag/common/sql
                        QueryTagSupport.java TransactionTagSupport.java
                        UpdateTagSupport.java DataSourceWrapper.java
               standard/conf sql.tld sql-rt.tld
               standard/src/org/apache/taglibs/standard/resources
                        Resources.properties
               standard/src/org/apache/taglibs/standard/tlv JstlSqlTLV.java
               standard/examples/web/sql Update.jsp Transaction.jsp
                        QueryParam.jsp QueryIterate.jsp QueryDirect.jsp
                        DriverSetup.jsp
  Added:       standard/src/org/apache/taglibs/standard/tag/common/sql
                        DataSourceUtil.java SetDataSourceTagSupport.java
               standard/src/org/apache/taglibs/standard/tag/el/sql
                        SetDataSourceTag.java
               standard/src/org/apache/taglibs/standard/tag/rt/sql
                        SetDataSourceTag.java
  Removed:     standard/src/org/apache/taglibs/standard/tag/common/sql
                        DriverTagSupport.java
               standard/src/org/apache/taglibs/standard/tag/el/sql
                        DriverTag.java
               standard/src/org/apache/taglibs/standard/tag/rt/sql
                        DriverTag.java
  Log:
  setDataSource tag implementation
  
  Revision  Changes    Path
  1.20      +11 -31    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
  
  Index: QueryTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- QueryTagSupport.java	14 Apr 2002 02:22:12 -0000	1.19
  +++ QueryTagSupport.java	16 Apr 2002 00:01:34 -0000	1.20
  @@ -101,7 +101,7 @@
       private Connection conn;
       private List parameters;
       private boolean isPartOfTransaction;
  -    private boolean hasDataSourceAttribute;
  +    private DataSourceUtil dsUtil;
   
       //*********************************************************************
       // Constructor
  @@ -170,7 +170,9 @@
               }
           }
   
  -        setDataSource();
  +        dsUtil = new DataSourceUtil();
  +        dsUtil.setDataSource(rawDataSource, pageContext);
  +        dataSource = dsUtil.getDataSource();
   	try {
   	    conn = getConnection();
   	}
  @@ -259,45 +261,18 @@
   	conn = null;
           dataSource = null;
           rawDataSource = null;
  -        hasDataSourceAttribute = false;
       }
   
       //*********************************************************************
       // Private utility methods
   
  -    private void setDataSource() throws JspException {
  -
  -        if (rawDataSource == null) {
  -            rawDataSource = Config.find(pageContext, Config.SQL_DATASOURCE);
  -        }
  -        else {
  -            hasDataSourceAttribute = true;
  -        }
  -
  -        // If the 'dataSource' attribute's value resolves to a String
  -        // after rtexpr/EL evaluation, use the string as JNDI path to 
  -        // a DataSource
  -        if (rawDataSource instanceof String) {
  -            try {
  -                Context ctx = new InitialContext();
  -                // relative to standard JNDI root for J2EE app
  -                Context envCtx = (Context) ctx.lookup("java:comp/env");
  -                dataSource = (DataSource) envCtx.lookup((String)rawDataSource);
  -            } catch (NamingException ex) {
  -                throw new JspException(ex.toString(), ex);
  -            }
  -        }
  -        else dataSource = (DataSource) rawDataSource;
  -    }
  -
  -
       private Connection getConnection() throws JspException, SQLException {
   	// Fix: Add all other mechanisms
   	Connection conn = null;
   	TransactionTagSupport parent = (TransactionTagSupport) 
   	    findAncestorWithClass(this, TransactionTagSupport.class);
   	if (parent != null) {
  -            if (hasDataSourceAttribute) {
  +            if (dsUtil.hasDataSourceAttribute()) {
                   throw new JspTagException(
                       Resources.getMessage("ERROR_NESTED_DATASOURCE"));
               }
  @@ -305,7 +280,12 @@
               isPartOfTransaction = true;
   	}
   	else {
  -	    conn = dataSource.getConnection();
  +            try {
  +	        conn = dataSource.getConnection();
  +            } catch (Exception ex) {
  +                throw new JspException(
  +                    Resources.getMessage("DATASOURCE_INVALID"));
  +            }
   	}
   	return conn;
       }
  
  
  
  1.8       +8 -26     jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java
  
  Index: TransactionTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/TransactionTagSupport.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TransactionTagSupport.java	12 Apr 2002 22:36:29 -0000	1.7
  +++ TransactionTagSupport.java	16 Apr 2002 00:01:34 -0000	1.8
  @@ -95,6 +95,7 @@
        */
       private Connection conn;
       private int origIsolation;
  +    private DataSourceUtil dsUtil;
   
       //*********************************************************************
       // Public utility methods
  @@ -141,7 +142,11 @@
        */
       public int doStartTag() throws JspException {
   
  -        setDataSource();
  +        dsUtil = new DataSourceUtil();
  +        dsUtil.setDataSource(rawDataSource, pageContext);
  +
  +        dataSource = dsUtil.getDataSource();
  +
   	try {
   	    conn = getConnection();
   	    int origIsolation = conn.getTransactionIsolation();
  @@ -158,7 +163,8 @@
   	catch (SQLException e) {
   	    throw new JspTagException(
                   Resources.getMessage("ERROR_GET_CONNECTION", e.getMessage()));
  -	}
  +	} 
  +
   	return EVAL_BODY_INCLUDE;
       }
   
  @@ -210,30 +216,6 @@
   
       //*********************************************************************
       // Private utility methods
  -
  -    private void setDataSource() throws JspException {
  -
  -        if (rawDataSource == null) {
  -            rawDataSource = Config.find(pageContext, Config.SQL_DATASOURCE);
  -        }
  -
  -        // If the 'dataSource' attribute's value resolves to a String
  -        // after rtexpr/EL evaluation, use the string as JNDI path to
  -        // a DataSource
  -        if (rawDataSource instanceof String) {
  -            try {
  -                Context ctx = new InitialContext();
  -                // relative to standard JNDI root for J2EE app
  -                Context envCtx = (Context) ctx.lookup("java:comp/env");
  -                dataSource = (DataSource) envCtx.lookup((String)rawDataSource);
  -            } catch (NamingException ex) {
  -                throw new JspTagException(ex.toString());
  -            }
  -        }
  -        else {
  -            dataSource = (DataSource) rawDataSource;
  -        }
  -    }
   
       private Connection getConnection() throws SQLException {
   	// Fix: Add all other mechanisms
  
  
  
  1.16      +13 -31    jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java
  
  Index: UpdateTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/UpdateTagSupport.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- UpdateTagSupport.java	14 Apr 2002 02:22:12 -0000	1.15
  +++ UpdateTagSupport.java	16 Apr 2002 00:01:34 -0000	1.16
  @@ -97,7 +97,7 @@
       private Connection conn;
       private List parameters;
       private boolean isPartOfTransaction;
  -    private boolean hasDataSourceAttribute;
  +    private DataSourceUtil dsUtil;
   
       //*********************************************************************
       // Accessor methods
  @@ -143,7 +143,11 @@
        */
       public int doStartTag() throws JspException {
   
  -        setDataSource();
  +        dsUtil = new DataSourceUtil();
  +        dsUtil.setDataSource(rawDataSource, pageContext);
  +
  +        dataSource = dsUtil.getDataSource();
  +
   	try {
   	    conn = getConnection();
   	}
  @@ -224,45 +228,18 @@
           dataSource = null;
           bodyContent = null;
           rawDataSource = null;
  -        hasDataSourceAttribute = false;
       }
   
       //*********************************************************************
       // Private utility methods
   
  -    private void setDataSource() throws JspException {
  -
  -        if (rawDataSource == null) {
  -            rawDataSource = Config.find(pageContext, Config.SQL_DATASOURCE);
  -        }
  -        else {
  -            hasDataSourceAttribute = true;
  -        }
  -
  -
  -        // If the 'dataSource' attribute's value resolves to a String
  -        // after rtexpr/EL evaluation, use the string as JNDI path to
  -        // a DataSource
  -        if (rawDataSource instanceof String) {
  -            try {
  -                Context ctx = new InitialContext();
  -                // relative to standard JNDI root for J2EE app
  -                Context envCtx = (Context) ctx.lookup("java:comp/env");
  -                dataSource = (DataSource) envCtx.lookup((String)rawDataSource);
  -            } catch (NamingException ex) {
  -                throw new JspException(ex.toString(), ex);
  -            }
  -        }
  -        else dataSource = (DataSource) rawDataSource;
  -    }
  -
       private Connection getConnection() throws JspException, SQLException {
   	// Fix: Add all other mechanisms
   	Connection conn = null;
   	TransactionTagSupport parent = (TransactionTagSupport) 
   	    findAncestorWithClass(this, TransactionTagSupport.class);
   	if (parent != null) {
  -            if (hasDataSourceAttribute) {
  +            if (dsUtil.hasDataSourceAttribute()) {
                   throw new JspTagException(
                       Resources.getMessage("ERROR_NESTED_DATASOURCE"));
               }
  @@ -270,7 +247,12 @@
               isPartOfTransaction = true;
   	}
   	else {
  -	    conn = dataSource.getConnection();
  +            try {
  +                conn = dataSource.getConnection();
  +            } catch (Exception ex) {
  +                throw new JspException(
  +                    Resources.getMessage("DATASOURCE_INVALID"));
  +            }
   	}
   	return conn;
       }
  
  
  
  1.4       +1 -0      jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java
  
  Index: DataSourceWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/DataSourceWrapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DataSourceWrapper.java	18 Mar 2002 18:49:53 -0000	1.3
  +++ DataSourceWrapper.java	16 Apr 2002 00:01:34 -0000	1.4
  @@ -146,4 +146,5 @@
           throw new SQLException(Resources.getMessage("NOT_SUPPORTED"));
       }
   
  +
   }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/DataSourceUtil.java
  
  Index: DataSourceUtil.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.taglibs.standard.tag.common.sql;
  
  import javax.sql.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.jstl.core.Config;
  import javax.naming.InitialContext;
  import javax.naming.Context;
  import javax.naming.NamingException;
  import org.apache.taglibs.standard.resources.Resources;
  
  
  /**
   * <p>A simple <code>DataSource</code> utility for the standard
   * <code>DriverManager</code> class.
   *
   * TO DO: need to cache DataSource
   * 
   * @author Justyna Horwat
   */
  public class DataSourceUtil {
  
      private static String ESCAPE = "\\";
      private static String TOKEN = ",";
      private DataSource dataSource;
      private boolean hasDataSourceAttribute = false;
  
      DataSourceUtil() {
          dataSource = new DataSourceWrapper();
      }
  
      public DataSource getDataSource() {
          return dataSource;
      }
  
      /**
       * Useful for Transaction nesting check
       **/
      public boolean hasDataSourceAttribute() {
          return hasDataSourceAttribute;
      }
  
      /**
       *
       * If dataSource is a String first do JNDI lookup
       * If lookup fails parse String like it was a set of JDBC parameters
       * Otherwise check to see if dataSource is a DataSource object and use as is
       *
       **/
      public void setDataSource(Object rawDataSource, PageContext pageContext) throws JspException
{
  
          if (rawDataSource == null) {
              rawDataSource = Config.find(pageContext, Config.SQL_DATASOURCE);
              hasDataSourceAttribute = false;
          }
          else {
              hasDataSourceAttribute = true;
          }
  
          // If the 'dataSource' attribute's value resolves to a String
          // after rtexpr/EL evaluation, use the string as JNDI path to
          // a DataSource
          if (rawDataSource instanceof String) {
              try {
                  Context ctx = new InitialContext();
                  // relative to standard JNDI root for J2EE app
                  Context envCtx = (Context) ctx.lookup("java:comp/env");
                  dataSource = (DataSource) envCtx.lookup((String)rawDataSource);
              } catch (NamingException ex) {
                  throw new JspException(ex.toString(), ex);
              }
              if (dataSource == null) {
                  setUsingParams((String)rawDataSource);
              }
          }
          else if (rawDataSource instanceof DataSource) {
              dataSource = (DataSource) rawDataSource;
          }
      }
  
      /**
       *
       * Parse JDBC parameters and setup dataSource appropriately
       *
       **/
      private void setUsingParams(String params) throws JspException {
          dataSource = (DataSource) new DataSourceWrapper();
  
          String[] paramString = new String[4];
          int escCount = 0; 
          int aryCount = 0; 
          int begin = 0;
  
          for(int index=0; index < params.length(); index++) {
              char nextChar = params.charAt(index);
              if (TOKEN.indexOf(nextChar) != -1) {
                  if (escCount == 0) {
                      paramString[aryCount] = params.substring(begin,index);
                      begin = index + 1;
                      if (++aryCount > 4) {
                          throw new JspTagException(
                              Resources.getMessage("JDBC_PARAM_COUNT"));
                      }
                  }
              }
              if (ESCAPE.indexOf(nextChar) != -1) {
                  escCount++;
              }
              else {
                  escCount = 0;
              }
          }
          paramString[aryCount] = params.substring(begin);
  
          ((DataSourceWrapper)dataSource).setJdbcURL(paramString[0]);
          try {
              ((DataSourceWrapper)dataSource).setDriverClassName(paramString[1]);
          } catch (Exception ex) {
              throw new JspTagException(
                  Resources.getMessage("DRIVER_INVALID_CLASS", ex.getMessage()));
          }
          ((DataSourceWrapper)dataSource).setUserName(paramString[2]);
          ((DataSourceWrapper)dataSource).setPassword(paramString[3]);
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/SetDataSourceTagSupport.java
  
  Index: SetDataSourceTagSupport.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.taglibs.standard.tag.common.sql;
  
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.jstl.sql.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsp.jstl.core.Config;
  import org.apache.taglibs.standard.tag.common.core.Util;
  import org.apache.taglibs.standard.resources.Resources;
  
  
  /**
   * <p>Tag handler for &lt;SetDataSource&gt; in JSTL, used to create
   * a simple DataSource for prototyping.</p>
   * 
   * @author Hans Bergsten
   * @author Justyna Horwat
   */
  public class SetDataSourceTagSupport extends TagSupport {
  
      protected Object dataSource;
      protected String jdbcURL;
      protected String driverClassName;
      protected String userName;
      protected String password;
  
      private int scope = PageContext.PAGE_SCOPE;
      private String var;
  
      //*********************************************************************
      // Accessor methods
  
      /**
       * Setter method for the scope of the variable to hold the
       * result.
       *
       */
      public void setScope(String scopeName) {
          Util.getScope(scopeName);
      }
  
      public void setVar(String var) {
  	this.var = var;
      }
  
      //*********************************************************************
      // Tag logic
  
      public int doStartTag() throws JspException {
          DataSourceWrapper ds;
  
          if (dataSource != null) {
              DataSourceUtil dsUtil = new DataSourceUtil(dataSource, pageContext);
              ds = (DataSourceWrapper) dsUtil.getDataSource();
          }
          else {
              ds = new DataSourceWrapper();
              try {
              ds.setDriverClassName(getDriverClassName());
              }
              catch (Exception e) {
                  throw new JspTagException(
                      Resources.getMessage("DRIVER_INVALID_CLASS", e.getMessage()));
              }
              ds.setJdbcURL(getJdbcURL());
              ds.setUserName(getUserName());
              ds.setPassword(getPassword());
          }
  
          if (var != null) {
  	    pageContext.setAttribute(var, ds, scope);
          }
          else {
              pageContext.setAttribute(Config.SQL_DATASOURCE, ds, scope);
          }
  	return SKIP_BODY;
      }
  
  
      //*********************************************************************
      // Private utility methods
  
      private String getDriverClassName() {
  	if (driverClassName != null) {
  	    return driverClassName;
  	}
  	return (String) Config.find(pageContext, Config.SQL_DRIVER);
      }
  
      private String getJdbcURL() {
  	if (jdbcURL != null) {
  	    return jdbcURL;
  	}
  	return (String) Config.find(pageContext, Config.SQL_URL);
      }
  
      private String getUserName() {
  	if (userName != null) {
  	    return userName;
  	}
  	return (String) Config.find(pageContext, Config.SQL_USER);
      }
  
      private String getPassword() {
  	if (password != null) {
  	    return password;
  	}
  	return (String) Config.find(pageContext, Config.SQL_PASSWORD);
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/sql/SetDataSourceTag.java
  
  Index: SetDataSourceTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.taglibs.standard.tag.el.sql;
  
  import javax.servlet.jsp.*;
  import org.apache.taglibs.standard.lang.support.*;
  import org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport;
  
  /**
   * <p>Tag handler for &lt;SetDataSource&gt; in JSTL, used to create
   * a simple DataSource for prototyping.</p>
   * 
   */
  public class SetDataSourceTag extends SetDataSourceTagSupport {
  
      private String dataSourceEL;
      private String driverClassNameEL;
      private String jdbcURLEL;
      private String userNameEL;
      private String passwordEL;
  
      //*********************************************************************
      // Accessor methods
  
      public void setDataSource(String dataSourceEL) {
  	this.dataSourceEL = dataSourceEL;
      }
  
      public void setDriver(String driverClassNameEL) {
  	this.driverClassNameEL = driverClassNameEL;
      }
  
      public void setUrl(String jdbcURLEL) {
  	this.jdbcURLEL = jdbcURLEL;
      }
  
      public void setUser(String userNameEL) {
  	this.userNameEL = userNameEL;
      }
  
      public void setPassword(String passwordEL) {
  	this.passwordEL = passwordEL;
      }
  
      //*********************************************************************
      // Tag logic
  
      public int doStartTag() throws JspException {
          evaluateExpressions();
  
          return super.doStartTag();
      }
  
  
      //*********************************************************************
      // Private utility methods
  
      // Evaluates expressions as necessary
      private void evaluateExpressions() throws JspException {
          if (dataSourceEL != null) {
                  dataSource = (Object) ExpressionEvaluatorManager.evaluate
                  ("dataSource", dataSourceEL, String.class, this, pageContext);
          }
  
          if (driverClassNameEL != null) {
                  driverClassName = (String) ExpressionEvaluatorManager.evaluate
                  ("driver", driverClassNameEL, String.class, this, pageContext);
          }
  
          if (jdbcURLEL != null) {
                  jdbcURL = (String) ExpressionEvaluatorManager.evaluate
                  ("url", jdbcURLEL, String.class, this, pageContext);
          }
  
          if (userNameEL != null) {
                  userName = (String) ExpressionEvaluatorManager.evaluate
                  ("user", userNameEL, String.class, this, pageContext);
          }
  
          if (passwordEL != null) {
                  password = (String) ExpressionEvaluatorManager.evaluate
                  ("password", passwordEL, String.class, this, pageContext);
          }
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/sql/SetDataSourceTag.java
  
  Index: SetDataSourceTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.taglibs.standard.tag.rt.sql;
  
  import org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport;
  
  /**
   * <p>Tag handler for &lt;Driver&gt; in JSTL, used to create
   * a simple DataSource for prototyping.</p>
   * 
   */
  public class SetDataSourceTag extends SetDataSourceTagSupport {
  
      //*********************************************************************
      // Accessor methods
  
      public void setDataSource(Object dataSource) {
  	this.dataSource = dataSource;
      }
  
      public void setDriver(String driverClassName) {
  	this.driverClassName = driverClassName;
      }
  
      public void setUrl(String jdbcURL) {
  	this.jdbcURL = jdbcURL;
      }
  
      public void setUser(String userName) {
  	this.userName = userName;
      }
  
      public void setPassword(String password) {
  	this.password = password;
      }
  
  }
  
  
  
  1.16      +8 -7      jakarta-taglibs/standard/conf/sql.tld
  
  Index: sql.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/sql.tld,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- sql.tld	14 Apr 2002 02:10:31 -0000	1.15
  +++ sql.tld	16 Apr 2002 00:01:34 -0000	1.16
  @@ -28,10 +28,11 @@
           param:value
           dateParam:value
           dateParam:type
  -        setDriver:driver
  -        setDriver:url
  -        setDriver:user
  -        setDriver:password
  +        setDataSource:dataSource
  +        setDataSource:driver
  +        setDataSource:url
  +        setDataSource:user
  +        setDataSource:password
           </param-value>
           <description>
               Whitespace-separated list of colon-separated token pairs
  @@ -151,7 +152,7 @@
   
     <tag>
       <name>dateParam</name>
  -    <tag-class>org.apache.taglibs.standard.tag.rt.sql.DateParamTag</tag-class>
  +    <tag-class>org.apache.taglibs.standard.tag.el.sql.DateParamTag</tag-class>
       <body-content>JSP</body-content>
       <description>
           Sets a parameter in an SQL statement to the specified java.util.Date val
  @@ -170,8 +171,8 @@
     </tag>
   
     <tag>
  -    <name>setDriver</name>
  -    <tag-class>org.apache.taglibs.standard.tag.el.sql.DriverTag</tag-class>
  +    <name>setDataSource</name>
  +    <tag-class>org.apache.taglibs.standard.tag.el.sql.SetDataSourceTag</tag-class>
       <body-content>empty</body-content>
       <description>
           Creates a simple DataSource suitable only for prototyping.
  
  
  
  1.15      +2 -2      jakarta-taglibs/standard/conf/sql-rt.tld
  
  Index: sql-rt.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/sql-rt.tld,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- sql-rt.tld	14 Apr 2002 17:06:57 -0000	1.14
  +++ sql-rt.tld	16 Apr 2002 00:01:34 -0000	1.15
  @@ -143,8 +143,8 @@
     </tag>
   
     <tag>
  -    <name>setDriver</name>
  -    <tag-class>org.apache.taglibs.standard.tag.common.sql.DriverTag</tag-class>
  +    <name>setDataSource</name>
  +    <tag-class>org.apache.taglibs.standard.tag.rt.sql.SetDataSourceTag</tag-class>
       <body-content>empty</body-content>
       <description>
           Creates a simple DataSource suitable only for prototyping.
  
  
  
  1.20      +6 -0      jakarta-taglibs/standard/src/org/apache/taglibs/standard/resources/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/resources/Resources.properties,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Resources.properties	15 Apr 2002 16:58:31 -0000	1.19
  +++ Resources.properties	16 Apr 2002 00:01:34 -0000	1.20
  @@ -154,6 +154,12 @@
   DRIVER_INVALID_CLASS=\
       In &lt;driver&gt;, invalid driver class name: "{0}"
   
  +DATASOURCE_INVALID=\
  +    Unable to get connection, DataSource invalid
  + 
  +JDBC_PARAM_COUNT=\
  +    Invalid number of JDBC parameters specified.
  + 
   TRANSACTION_NO_SUPPORT=\
       In &lt;transaction&gt;, datasource does not support transactions
   
  
  
  
  1.5       +1 -0      jakarta-taglibs/standard/src/org/apache/taglibs/standard/tlv/JstlSqlTLV.java
  
  Index: JstlSqlTLV.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tlv/JstlSqlTLV.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JstlSqlTLV.java	14 Apr 2002 02:10:31 -0000	1.4
  +++ JstlSqlTLV.java	16 Apr 2002 00:01:34 -0000	1.5
  @@ -77,6 +77,7 @@
       // Constants
   
       // tag names
  +    private final String SETDATASOURCE = "setDataSource";
       private final String QUERY = "query";
       private final String UPDATE = "update";
       private final String TRANSACTION = "transaction";
  
  
  
  1.12      +2 -2      jakarta-taglibs/standard/examples/web/sql/Update.jsp
  
  Index: Update.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/Update.jsp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Update.jsp	12 Apr 2002 23:18:51 -0000	1.11
  +++ Update.jsp	16 Apr 2002 00:01:35 -0000	1.12
  @@ -10,9 +10,9 @@
   <h1>SQL Update Execution</h1>
   
   
  -<!-- NOTE: the sql:setDriver tag is for prototyping and simple applications. You should
really use a DataSource object instead --!>
  +<!-- NOTE: the sql:setDataSource tag is for prototyping and simple applications. You
should really use a DataSource object instead --!>
   
  -<sql:setDriver
  +<sql:setDataSource
     var="example"
     driver="${myDbDriver}"
     url="${myDbUrl}"
  
  
  
  1.8       +2 -2      jakarta-taglibs/standard/examples/web/sql/Transaction.jsp
  
  Index: Transaction.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/Transaction.jsp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Transaction.jsp	12 Apr 2002 22:20:08 -0000	1.7
  +++ Transaction.jsp	16 Apr 2002 00:01:35 -0000	1.8
  @@ -9,9 +9,9 @@
   <h1>SQL Transactions</h1>
   
   
  -<!-- NOTE: the sql:setDriver tag is for prototyping and simple applications. You should
really use a DataSource object instead --!>
  +<!-- NOTE: the sql:setDataSource tag is for prototyping and simple applications. You
should really use a DataSource object instead --!>
   
  -<sql:setDriver
  +<sql:setDataSource
     var="example"
     driver="${myDbDriver}"
     url="${myDbUrl}"
  
  
  
  1.10      +2 -2      jakarta-taglibs/standard/examples/web/sql/QueryParam.jsp
  
  Index: QueryParam.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/QueryParam.jsp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QueryParam.jsp	12 Apr 2002 22:20:08 -0000	1.9
  +++ QueryParam.jsp	16 Apr 2002 00:01:35 -0000	1.10
  @@ -14,9 +14,9 @@
   
   
   
  -<!-- NOTE: the sql:setDriver tag is for prototyping and simple applications. You should
really use a DataSource object instead --!>
  +<!-- NOTE: the sql:setDataSource tag is for prototyping and simple applications. You
should really use a DataSource object instead --!>
   
  -<sql:setDriver
  +<sql:setDataSource
     var="example"
     driver="${myDbDriver}"
     url="${myDbUrl}"
  
  
  
  1.12      +2 -2      jakarta-taglibs/standard/examples/web/sql/QueryIterate.jsp
  
  Index: QueryIterate.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/QueryIterate.jsp,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- QueryIterate.jsp	12 Apr 2002 23:18:51 -0000	1.11
  +++ QueryIterate.jsp	16 Apr 2002 00:01:35 -0000	1.12
  @@ -10,9 +10,9 @@
   <h1>SQL Query Execution using an iterator</h1>
   
   
  -<!-- NOTE: the sql:setDriver tag is for prototyping and simple applications. You should
really use a DataSource object instead --!>
  +<!-- NOTE: the sql:setDataSource tag is for prototyping and simple applications. You
should really use a DataSource object instead --!>
   
  -<sql:setDriver
  +<sql:setDataSource
     var="example"
     driver="${myDbDriver}"
     url="${myDbUrl}"
  
  
  
  1.11      +2 -2      jakarta-taglibs/standard/examples/web/sql/QueryDirect.jsp
  
  Index: QueryDirect.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/QueryDirect.jsp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- QueryDirect.jsp	12 Apr 2002 22:20:08 -0000	1.10
  +++ QueryDirect.jsp	16 Apr 2002 00:01:35 -0000	1.11
  @@ -11,9 +11,9 @@
   <p>This example demonstrates how the row and columns can be directly accessed using
various direct mechanisms.<p>
   
   
  -<!-- NOTE: the sql:setDriver tag is for prototyping and simple applications. You should
really use a DataSource object instead --!>
  +<!-- NOTE: the sql:setDataSource tag is for prototyping and simple applications. You
should really use a DataSource object instead --!>
   
  -<sql:setDriver
  +<sql:setDataSource
     var="example"
     driver="${myDbDriver}"
     url="${myDbUrl}"
  
  
  
  1.4       +1 -1      jakarta-taglibs/standard/examples/web/sql/DriverSetup.jsp
  
  Index: DriverSetup.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/sql/DriverSetup.jsp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DriverSetup.jsp	12 Apr 2002 22:20:08 -0000	1.3
  +++ DriverSetup.jsp	16 Apr 2002 00:01:35 -0000	1.4
  @@ -10,7 +10,7 @@
   
   <code>
   <pre>
  -&lt;sql:setDriver
  +&lt;sql:setDataSource
     var="example"
     driver="RmiJdbc.RJDriver"
     url="jdbc:rmi://localhost:1099/jdbc:cloudscape:CloudscapeDB;create=true"
  
  
  

--
To unsubscribe, e-mail:   <mailto:taglibs-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-dev-help@jakarta.apache.org>


Mime
View raw message