Update of /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee/resource
In directory sc8-pr-cvs1:/tmp/cvs-serv27662/src/com/babeldoc/j2ee/resource
Added Files:
JndiDatasource.java
Log Message:
Re-adding of the J2ee module. THe most you can say about this is that it compiles.
--- NEW FILE: JndiDatasource.java ---
/*
* $Header: /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee/resource/JndiDatasource.java,v 1.1 2003/08/27 03:15:31 triphop Exp $
* $DateTime: 2002/07/21 17:01:20 $
*
*
* babeldoc: universal document processor
* Copyright (C) 2002 Bruce McDonald, Elogex Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.babeldoc.j2ee.resource;
import com.babeldoc.core.resource.Resource;
import com.babeldoc.core.resource.ResourceException;
import com.babeldoc.core.resource.ResourceConfigInfo;
import com.babeldoc.core.option.IConfigInfo;
import com.babeldoc.core.GeneralException;
import com.babeldoc.j2ee.ServiceLocator;
import java.sql.Connection;
import java.util.Collection;
import javax.sql.DataSource;
/**
* Version of IResource to use when running in a J2EE container
*
* <p>Title: Babel</p>
* <p>Description: Universal Document Processor</p>
* <p>Copyright: Copyright (c) 2002</p>
* @author Bmcdonald
* @version 1.0
*/
public class JndiDatasource
extends Resource {
/** Config option name */
public static String JNDI_NAME = "datasourceName";
public static final String NAMING_URL = "namingUrl";
public static final String NAMING_PROVIDER = "namingProvider";
/** service locator object - could be the global or could be specific */
private ServiceLocator locator;
/** name of the pool */
private String poolName;
/** configuration information object */
private IConfigInfo info;
/**
* Does lazy init of DataSource lookup (expensive operation).
* @return datasource the datasource object
* @throws GeneralException
*/
protected DataSource getDataSource()
throws GeneralException {
return locator.getDataSource(poolName);
}
/**
* Setup the resource - this MUST be overridden by child resources
*
* @throws ResourceException
*/
protected void setup()
throws ResourceException {
poolName = getInfo().getStrValue(JNDI_NAME);
String namingUrl = getInfo().getStrValue(NAMING_URL);
String namingProvider = getInfo().getStrValue(NAMING_PROVIDER);
if(namingUrl!=null&&namingProvider!=null) {
try {
locator = new ServiceLocator(namingUrl, namingProvider);
} catch (GeneralException e) {
throw new ResourceException("", e);
}
} else {
locator = ServiceLocator.getGlobal();
}
}
/**
* Get a new connection.
* @return the connection
* @throws ResourceException
*/
public synchronized Object checkOut()
throws ResourceException {
try {
return getDataSource().getConnection();
} catch (Exception e ) {
throw new ResourceException("[ResourceException.checkOut], e");
}
}
/**
* Checkin this connection
* @param object the connection to check back in
* @throws ResourceException
*/
public synchronized void checkIn(Object object)
throws ResourceException {
try {
((Connection)object).close();
} catch (Exception e ) {
throw new ResourceException("[ResourceException.checkIn]", e);
}
}
/**
* Get the configuration iformation for this class
*
* @return IConfigInfo object
*/
public IConfigInfo getInfo() {
if(info==null) {
info = new ResourceConfigInfo() {
/**
* This method returns type specific options
*
* @return comments
*/
public Collection getTypeSpecificOptions() {
return null;
}
/**
* Return description of this worker
*
* @return description
*/
public String getDescription() {
return null;
}
/**
* return the name
*
* @return
*/
public String getName() {
return null;
}
};
}
return info;
}
}
|