/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* 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
*
* $Id: ManagedConnectionFactorySupport.java 2372 2007-05-17 21:53:00Z mlipp $
*
* $Log$
*/
package de.danet.an.util.ra;
import java.io.PrintWriter;
import java.util.Set;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject;
/**
* This class provides a base class for implementing managed connection
* factories for managed connections derived from
* <code>ManagedConnectionFactorySupport</code>.
*
* @author mnl
*/
public abstract class ManagedConnectionFactorySupport
implements ManagedConnectionFactory {
private PrintWriter logWriter;
/* (non-Javadoc)
* @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory
*/
public Object createConnectionFactory()
throws ResourceException {
return createConnectionFactory(new DefaultConnectionManager());
}
/**
* The default implementation simply returns the first connection from
* the set.
*
* @param connectionSet candidate connection set
* @param subject caller's security information
* @param requestInfo additional resource adapter specific connection
* request information
* @return the managed connection
*
* @see javax.resource.spi.ManagedConnectionFactory#matchManagedConnections
*/
public ManagedConnection matchManagedConnections
(Set connectionSet, Subject subject, ConnectionRequestInfo requestInfo)
throws ResourceException {
ManagedConnection res = null;
if (connectionSet.size() > 0) {
res = (ManagedConnection)connectionSet.iterator().next();
}
return res;
}
/* (non-Javadoc)
* @see javax.resource.spi.ManagedConnectionFactory#setLogWriter(java.io.PrintWriter)
*/
public void setLogWriter(PrintWriter logWriter) throws ResourceException {
this.logWriter = logWriter;
}
/* (non-Javadoc)
* @see javax.resource.spi.ManagedConnectionFactory#getLogWriter()
*/
public PrintWriter getLogWriter() throws ResourceException {
return logWriter;
}
/**
* Create the managed connection meta data with the given user info.
* @param user
* @return
*/
public abstract ManagedConnectionMetaData createMetaData (String user);
/**
* Helper that can handles <code>null</code> values properly.
* @param o1
* @param o2
* @return
*/
protected boolean equals (Object o1, Object o2) {
if (o1 == null && o2 == null) {
return true;
}
if (o1 != null && o2 != null) {
return o1.equals(o2);
}
return false;
}
}