001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: ManagedConnectionFactorySupport.java,v 1.1 2007/05/17 21:52:59 mlipp Exp $
021: *
022: * $Log: ManagedConnectionFactorySupport.java,v $
023: * Revision 1.1 2007/05/17 21:52:59 mlipp
024: * Refactored resource adaptors.
025: *
026: */
027: package de.danet.an.util.ra;
028:
029: import java.io.PrintWriter;
030: import java.util.Set;
031:
032: import javax.resource.ResourceException;
033: import javax.resource.spi.ConnectionRequestInfo;
034: import javax.resource.spi.ManagedConnection;
035: import javax.resource.spi.ManagedConnectionFactory;
036: import javax.resource.spi.ManagedConnectionMetaData;
037: import javax.security.auth.Subject;
038:
039: /**
040: * This class provides a base class for implementing managed connection
041: * factories for managed connections derived from
042: * <code>ManagedConnectionFactorySupport</code>.
043: *
044: * @author mnl
045: */
046: public abstract class ManagedConnectionFactorySupport implements
047: ManagedConnectionFactory {
048:
049: private PrintWriter logWriter;
050:
051: /* (non-Javadoc)
052: * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory
053: */
054: public Object createConnectionFactory() throws ResourceException {
055: return createConnectionFactory(new DefaultConnectionManager());
056: }
057:
058: /**
059: * The default implementation simply returns the first connection from
060: * the set.
061: *
062: * @param connectionSet candidate connection set
063: * @param subject caller's security information
064: * @param requestInfo additional resource adapter specific connection
065: * request information
066: * @return the managed connection
067: *
068: * @see javax.resource.spi.ManagedConnectionFactory#matchManagedConnections
069: */
070: public ManagedConnection matchManagedConnections(Set connectionSet,
071: Subject subject, ConnectionRequestInfo requestInfo)
072: throws ResourceException {
073: ManagedConnection res = null;
074: if (connectionSet.size() > 0) {
075: res = (ManagedConnection) connectionSet.iterator().next();
076: }
077: return res;
078: }
079:
080: /* (non-Javadoc)
081: * @see javax.resource.spi.ManagedConnectionFactory#setLogWriter(java.io.PrintWriter)
082: */
083: public void setLogWriter(PrintWriter logWriter)
084: throws ResourceException {
085: this .logWriter = logWriter;
086: }
087:
088: /* (non-Javadoc)
089: * @see javax.resource.spi.ManagedConnectionFactory#getLogWriter()
090: */
091: public PrintWriter getLogWriter() throws ResourceException {
092: return logWriter;
093: }
094:
095: /**
096: * Create the managed connection meta data with the given user info.
097: * @param user
098: * @return
099: */
100: public abstract ManagedConnectionMetaData createMetaData(String user);
101:
102: /**
103: * Helper that can handles <code>null</code> values properly.
104: * @param o1
105: * @param o2
106: * @return
107: */
108: protected boolean equals(Object o1, Object o2) {
109: if (o1 == null && o2 == null) {
110: return true;
111: }
112: if (o1 != null && o2 != null) {
113: return o1.equals(o2);
114: }
115: return false;
116: }
117:
118: }
|