Coverage report

  %line %branch
org.apache.commons.jelly.tags.sql.SetDataSourceTag
5% 
91% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.jelly.tags.sql;
 18  
 
 19  
 import javax.sql.DataSource;
 20  
 
 21  
 import org.apache.commons.jelly.JellyTagException;
 22  
 import org.apache.commons.jelly.TagSupport;
 23  
 import org.apache.commons.jelly.XMLOutput;
 24  
 import org.apache.commons.jelly.tags.Resources;
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * <p>Tag handler for &lt;SetDataSource&gt; in JSTL, used to create
 30  
  * a simple DataSource for prototyping.</p>
 31  
  *
 32  
  * @author Hans Bergsten
 33  
  * @author Justyna Horwat
 34  
  */
 35  2
 public class SetDataSourceTag extends TagSupport {
 36  
 
 37  
     /** The Log to which logging calls will be made. */
 38  2
     private static final Log log = LogFactory.getLog(SetDataSourceTag.class);
 39  
 
 40  
     protected Object dataSource;
 41  
     protected boolean dataSourceSpecified;
 42  
     protected String jdbcURL;
 43  
     protected String driverClassName;
 44  
     protected String userName;
 45  
     protected String password;
 46  
 
 47  0
     private String scope = "page";
 48  
     private String var;
 49  
 
 50  
     //*********************************************************************
 51  
     // Constructor and initialization
 52  
 
 53  0
     public SetDataSourceTag() {
 54  0
     }
 55  
 
 56  
     //*********************************************************************
 57  
     // Accessor methods
 58  
 
 59  
     /**
 60  
      * Sets the scope of the variable to hold the
 61  
      * result.
 62  
      *
 63  
      */
 64  
     public void setScope(String scope) {
 65  0
         this.scope = scope;
 66  0
     }
 67  
 
 68  
     public void setVar(String var) {
 69  0
         this.var = class="keyword">var;
 70  0
     }
 71  
 
 72  
     public void setDataSource(Object dataSource) {
 73  0
         this.dataSource = dataSource;
 74  0
         this.dataSourceSpecified = true;
 75  0
     }
 76  
 
 77  
     public void setDriver(String driverClassName) {
 78  0
         this.driverClassName = driverClassName;
 79  0
     }
 80  
 
 81  
     public void setUrl(String jdbcURL) {
 82  0
         this.jdbcURL = jdbcURL;
 83  0
     }
 84  
 
 85  
     public void setUser(String userName) {
 86  0
         this.userName = userName;
 87  0
     }
 88  
 
 89  
     public void setPassword(String password) {
 90  0
         this.password = password;
 91  0
     }
 92  
 
 93  
     //*********************************************************************
 94  
     // Tag logic
 95  
 
 96  
     public void doTag(XMLOutput output) throws JellyTagException {
 97  0
         DataSource ds = null;
 98  
 
 99  0
         if (dataSource != null) {
 100  0
             ds = DataSourceUtil.getDataSource(dataSource, context);
 101  
         }
 102  
         else {
 103  0
             if (dataSourceSpecified) {
 104  0
                 throw new JellyTagException(Resources.getMessage("SQL_DATASOURCE_NULL"));
 105  
             }
 106  
 
 107  0
             DataSourceWrapper dsw = new DataSourceWrapper();
 108  
             try {
 109  
                 // set driver class iff provided by the tag
 110  0
                 if (driverClassName != null) {
 111  0
                     dsw.setDriverClassName(driverClassName);
 112  
                 }
 113  0
             }
 114  
             catch (Exception e) {
 115  0
                 log.error( "Could not load driver class: " + e, e );
 116  0
                 throw new JellyTagException(
 117  
                     Resources.getMessage("DRIVER_INVALID_CLASS", e.getMessage()));
 118  
             }
 119  0
             dsw.setJdbcURL(jdbcURL);
 120  0
             dsw.setUserName(userName);
 121  0
             dsw.setPassword(password);
 122  0
             ds = (DataSource) dsw;
 123  
         }
 124  
 
 125  0
         if (var != null) {
 126  0
             context.setVariable(var, ds);
 127  
         }
 128  
         else {
 129  0
             context.setVariable("org.apache.commons.jelly.sql.DataSource", ds);
 130  
         }
 131  0
     }
 132  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.