001: /*
002: * $Id: DefaultMuleConnectionFactory.java 10789 2008-02-12 20:04:43Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.jca;
012:
013: import java.io.IOException;
014: import java.io.ObjectInputStream;
015:
016: import javax.naming.Reference;
017: import javax.resource.ResourceException;
018: import javax.resource.spi.ConnectionManager;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022:
023: /**
024: * <code>DefaultMuleConnectionFactory</code> an implementation of the
025: * MuleconnectionFactory interface used by clients of this ResourceAdapter to obtain
026: * a connection to Mule resources.
027: */
028: public class DefaultMuleConnectionFactory implements
029: MuleConnectionFactory {
030: /**
031: * Serial version
032: */
033: private static final long serialVersionUID = 1552386015565975623L;
034:
035: /**
036: * logger used by this class
037: */
038: protected transient Log logger = LogFactory.getLog(this .getClass());
039:
040: private transient ConnectionManager manager;
041: private transient MuleManagedConnectionFactory factory;
042: private Reference reference;
043: private MuleConnectionRequestInfo info;
044:
045: public DefaultMuleConnectionFactory(
046: MuleManagedConnectionFactory factory,
047: ConnectionManager manager, MuleConnectionRequestInfo info) {
048: this .factory = factory;
049: this .manager = manager;
050: this .info = info;
051: }
052:
053: private void readObject(ObjectInputStream ois)
054: throws ClassNotFoundException, IOException {
055: ois.defaultReadObject();
056: // TODO this is incomplete:
057: // MuleManagedConnectionFactory is Serializable but marked transient?!
058: this .logger = LogFactory.getLog(this .getClass());
059: }
060:
061: public MuleConnection createConnection() throws ResourceException {
062: return createConnection(info);
063: }
064:
065: public MuleConnection createConnection(
066: MuleConnectionRequestInfo info) throws ResourceException {
067: // TODO try {
068: return (MuleConnection) manager.allocateConnection(factory,
069: info);
070: // }
071: // catch (ResourceException e) {
072: //
073: // logger.warn("Connection could not be created: " + e.getMessage(), e);
074: // throw new DefaultMuleException(e.getMessage());
075: // }
076: }
077:
078: public ConnectionManager getManager() {
079: return manager;
080: }
081:
082: public void setManager(ConnectionManager manager) {
083: this .manager = manager;
084: }
085:
086: public MuleManagedConnectionFactory getFactory() {
087: return factory;
088: }
089:
090: public void setFactory(MuleManagedConnectionFactory factory) {
091: this .factory = factory;
092: }
093:
094: public Reference getReference() {
095: return reference;
096: }
097:
098: public void setReference(Reference reference) {
099: this .reference = reference;
100: }
101:
102: public MuleConnectionRequestInfo getInfo() {
103: return info;
104: }
105:
106: public void setInfo(MuleConnectionRequestInfo info) {
107: this.info = info;
108: }
109: }
|