001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: package org.apache.taglibs.standard.tag.el.sql;
040:
041: import javax.servlet.jsp.JspException;
042:
043: import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
044: import org.apache.taglibs.standard.tag.common.sql.SetDataSourceTagSupport;
045:
046: /**
047: * <p>Tag handler for <SetDataSource> in JSTL, used to create
048: * a simple DataSource for prototyping.</p>
049: *
050: */
051: public class SetDataSourceTag extends SetDataSourceTagSupport {
052:
053: private String dataSourceEL;
054: private String driverClassNameEL;
055: private String jdbcURLEL;
056: private String userNameEL;
057: private String passwordEL;
058:
059: //*********************************************************************
060: // Accessor methods
061:
062: public void setDataSource(String dataSourceEL) {
063: this .dataSourceEL = dataSourceEL;
064: this .dataSourceSpecified = true;
065: }
066:
067: public void setDriver(String driverClassNameEL) {
068: this .driverClassNameEL = driverClassNameEL;
069: }
070:
071: public void setUrl(String jdbcURLEL) {
072: this .jdbcURLEL = jdbcURLEL;
073: }
074:
075: public void setUser(String userNameEL) {
076: this .userNameEL = userNameEL;
077: }
078:
079: public void setPassword(String passwordEL) {
080: this .passwordEL = passwordEL;
081: }
082:
083: //*********************************************************************
084: // Tag logic
085:
086: public int doStartTag() throws JspException {
087: evaluateExpressions();
088:
089: return super .doStartTag();
090: }
091:
092: //*********************************************************************
093: // Private utility methods
094:
095: // Evaluates expressions as necessary
096: private void evaluateExpressions() throws JspException {
097: if (dataSourceEL != null) {
098: dataSource = ExpressionEvaluatorManager.evaluate(
099: "dataSource", dataSourceEL, Object.class, this ,
100: pageContext);
101: }
102:
103: if (driverClassNameEL != null) {
104: driverClassName = (String) ExpressionEvaluatorManager
105: .evaluate("driver", driverClassNameEL,
106: String.class, this , pageContext);
107: }
108:
109: if (jdbcURLEL != null) {
110: jdbcURL = (String) ExpressionEvaluatorManager.evaluate(
111: "url", jdbcURLEL, String.class, this , pageContext);
112: }
113:
114: if (userNameEL != null) {
115: userName = (String) ExpressionEvaluatorManager
116: .evaluate("user", userNameEL, String.class, this ,
117: pageContext);
118: }
119:
120: if (passwordEL != null) {
121: password = (String) ExpressionEvaluatorManager.evaluate(
122: "password", passwordEL, String.class, this,
123: pageContext);
124: }
125: }
126:
127: }
|