Coverage report

  %line %branch
org.apache.jetspeed.components.jndi.SpringJNDIStarter
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.components.jndi;
 18  
 
 19  
 /**
 20  
  * <p>
 21  
  * Helper class to establish a jndi based datasource for commandline and maven based applications
 22  
  *  
 23  
  * </p>
 24  
  * 
 25  
  * 
 26  
  * @
 27  
  * @author <a href="mailto:hajo@bluesunrise.com">Hajo Birthelmer</a>
 28  
  * @version $ $
 29  
  *
 30  
  */
 31  
 
 32  
 
 33  
 import java.util.Map;
 34  
 
 35  
 import org.apache.commons.pool.impl.GenericObjectPool;
 36  
 import org.apache.jetspeed.components.SpringComponentManager;
 37  
 import org.apache.jetspeed.components.datasource.BoundDBCPDatasourceComponent;
 38  
 import org.apache.jetspeed.components.jndi.JNDIComponent;
 39  
 import org.apache.jetspeed.components.jndi.TyrexJNDIComponent;
 40  
 
 41  
 public class SpringJNDIStarter
 42  
 {
 43  
 
 44  
 	   public static final String JNDI_DS_NAME = "jetspeed";
 45  0
 		public static final String DATASOURCE_DRIVER = "org.apache.jetspeed.database.driver".intern();
 46  0
 		public static final String DATASOURCE_URL = "org.apache.jetspeed.database.url".intern();
 47  0
 		public static final String DATASOURCE_USERNAME = "org.apache.jetspeed.database.user".intern();
 48  0
 		public static final String DATASOURCE_PASSWORD = "org.apache.jetspeed.database.password".intern();
 49  
 
 50  
 
 51  
 		
 52  
 		
 53  
 		private final Map context;
 54  
 	   
 55  
 	    protected BoundDBCPDatasourceComponent datasourceComponent;
 56  
 	    protected JNDIComponent jndi;
 57  0
 	    String appRoot = null; 
 58  0
 	    String[] bootConfig = null;
 59  0
         String[] appConfig = null;
 60  0
         SpringComponentManager scm = null;
 61  
 	
 62  
         
 63  
    /**
 64  
     * 
 65  
     * Create an instance with a given context  and the usual SpringComponent arguments 
 66  
     * @param context
 67  
     * @param appRoot root directory of the application
 68  
     * @param bootConfig (string-)list of files to process on boot
 69  
     * @param appConfig (string-)list of files to process as configuration 
 70  
     */
 71  
         public SpringJNDIStarter(Map context,String appRoot, String[] bootConfig, String[] appConfig)
 72  0
 	    {
 73  0
 	    	this.context = context;
 74  0
 	    	this.appRoot = appRoot;
 75  0
 	    	this.bootConfig = bootConfig;
 76  0
 	    	this.appConfig = appConfig;
 77  0
 	    }
 78  
 
 79  
 /**
 80  
  * The main startup routine.
 81  
  * Establishes a JNDI connection based on the following System parameters:
 82  
  * <p> org.apache.jetspeed.database.url
 83  
  * <p> org.apache.jetspeed.database.driver
 84  
  * <p> org.apache.jetspeed.database.user
 85  
  * <p> org.apache.jetspeed.database.password
 86  
  * @throws Exception
 87  
  */
 88  
     public void setUp() throws Exception
 89  
     {
 90  0
     	setupJNDI();
 91  0
          scm = new SpringComponentManager(bootConfig, appConfig,  appRoot );
 92  0
         }
 93  
 
 94  
     public void tearDown() throws Exception
 95  
     {
 96  
     	try
 97  
     	{
 98  0
     		datasourceComponent.stop();
 99  
     	}
 100  0
     	catch (Exception e)
 101  
     	{
 102  0
     		System.out.println("datasourceComponent stop failed with " + e.getLocalizedMessage());
 103  0
     		e.printStackTrace();
 104  0
     	}
 105  
     	try
 106  
     	{
 107  0
     		scm.stop();
 108  
     	}
 109  0
     	catch (Exception e)
 110  
     	{
 111  0
     		System.out.println("SpringComponentManager stop failed with " + e.getLocalizedMessage());
 112  0
     		e.printStackTrace();
 113  0
     	}
 114  
     	
 115  
     	try
 116  
     	{
 117  0
     		jndi.unbindFromCurrentThread();
 118  
 		}
 119  0
 		catch (Exception e)
 120  
 		{
 121  0
 			System.out.println("JNDI  unbindFromCurrentThread failed with " + e.getLocalizedMessage());
 122  0
 			e.printStackTrace();
 123  0
 		}
 124  0
     }
 125  
     
 126  
     String getProperty(String name)
 127  
     {
 128  0
     	String s = null;
 129  
     	try
 130  
     	{
 131  0
     		if (context != null)
 132  0
     			s = (String) context.get(name);
 133  
     	}
 134  0
     	catch (Exception e)
 135  
     	{
 136  0
     		e.printStackTrace();
 137  0
     	}
 138  0
     	if (s == null)
 139  0
     		s = System.getProperty(name);
 140  0
     	return s;
 141  
     }
 142  
     
 143  
     
 144  
     public void setupJNDI() throws Exception
 145  
     {
 146  0
         jndi = new TyrexJNDIComponent();
 147  0
         String url = getProperty("org.apache.jetspeed.database.url");
 148  0
         String driver = getProperty("org.apache.jetspeed.database.driver");
 149  0
         String user = getProperty("org.apache.jetspeed.database.user");
 150  0
         String password = getProperty("org.apache.jetspeed.database.password");
 151  0
         datasourceComponent = new BoundDBCPDatasourceComponent(user, password, driver, url, 20, 5000,
 152  
                 GenericObjectPool.WHEN_EXHAUSTED_GROW, true, JNDI_DS_NAME, jndi);
 153  0
         datasourceComponent.start();
 154  0
     }
 155  
 
 156  
 	public SpringComponentManager getComponentManager()
 157  
 	{
 158  0
 		return scm;
 159  
 	}
 160  
 
 161  
     public Map getContext()
 162  
     {
 163  0
         return context;
 164  
     }
 165  
     
 166  
     
 167  
 }

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