01: /*
02: * This file is part of the WfMOpen project.
03: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
04: * All rights reserved.
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * $Id: ConnectionFactorySupport.java,v 1.1 2007/05/17 21:52:59 mlipp Exp $
21: *
22: * $Log: ConnectionFactorySupport.java,v $
23: * Revision 1.1 2007/05/17 21:52:59 mlipp
24: * Refactored resource adaptors.
25: *
26: */
27: package de.danet.an.util.ra;
28:
29: import java.io.Serializable;
30:
31: import javax.naming.NamingException;
32: import javax.naming.Reference;
33: import javax.resource.ResourceException;
34: import javax.resource.spi.ConnectionManager;
35: import javax.resource.spi.ManagedConnectionFactory;
36:
37: /**
38: * A ready to use default connection factory for connections derived from
39: * <code>ConnectionFactory</code>.
40: *
41: * @author mnl
42: */
43: public abstract class ConnectionFactorySupport implements Serializable {
44:
45: private ManagedConnectionFactory mcf;
46: private ConnectionManager cm;
47: private Reference reference;
48:
49: /**
50: * Create a new instance with properties initialized to the given values.
51: * @param mcf
52: * @param cm
53: */
54: public ConnectionFactorySupport(ManagedConnectionFactory mcf,
55: ConnectionManager cm) {
56: this .mcf = mcf;
57: this .cm = cm;
58: }
59:
60: /**
61: * Create a connection. Derived classes should implement
62: * a method <code>getConnection</code> that calls this method
63: * and casts the result to the specific connection type.
64: *
65: * @see javax.resource.cci.ConnectionFactory#getConnection()
66: */
67: protected ConnectionSupport createConnection()
68: throws ResourceException {
69: return (ConnectionSupport) cm.allocateConnection(mcf, null);
70: }
71:
72: /* (non-Javadoc)
73: * @see javax.resource.Referenceable#setReference(javax.naming.Reference)
74: */
75: public void setReference(Reference reference) {
76: this .reference = reference;
77: }
78:
79: /* (non-Javadoc)
80: * @see javax.naming.Referenceable#getReference()
81: */
82: public Reference getReference() throws NamingException {
83: return reference;
84: }
85: }
|