View Javadoc

1   /*
2    * $Id: DefaultMuleConnectionFactory.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.ra;
12  
13  import java.io.IOException;
14  import java.io.ObjectInputStream;
15  
16  import javax.naming.Reference;
17  import javax.resource.ResourceException;
18  import javax.resource.spi.ConnectionManager;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /**
24   * <code>DefaultMuleConnectionFactory</code> an implementation of the
25   * MuleconnectionFactory interface used by clients of this ResourceAdapter to obtain
26   * a connection to Mule resources.
27   */
28  public class DefaultMuleConnectionFactory implements MuleConnectionFactory
29  {
30      /**
31       * Serial version
32       */
33      private static final long serialVersionUID = 1552386015565975623L;
34  
35      /**
36       * logger used by this class
37       */
38      protected transient Log logger = LogFactory.getLog(this.getClass());
39  
40      private transient ConnectionManager manager;
41      private transient MuleManagedConnectionFactory factory;
42      private Reference reference;
43      private MuleConnectionRequestInfo info;
44  
45      public DefaultMuleConnectionFactory(MuleManagedConnectionFactory factory,
46                                          ConnectionManager manager,
47                                          MuleConnectionRequestInfo info)
48      {
49          this.factory = factory;
50          this.manager = manager;
51          this.info = info;
52      }
53  
54      private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
55      {
56          ois.defaultReadObject();
57          // TODO this is incomplete:
58          // MuleManagedConnectionFactory is Serializable but marked transient?!
59          this.logger = LogFactory.getLog(this.getClass());
60      }
61  
62      public MuleConnection createConnection() throws ResourceException
63      {
64          return createConnection(info);
65      }
66  
67      public MuleConnection createConnection(MuleConnectionRequestInfo info) throws ResourceException
68      {
69          // TODO try {
70          return (MuleConnection)manager.allocateConnection(factory, info);
71          // }
72          // catch (ResourceException e) {
73          //            
74          // logger.warn("Connection could not be created: " + e.getMessage(), e);
75          // throw new UMOException(e.getMessage());
76          // }
77      }
78  
79      public ConnectionManager getManager()
80      {
81          return manager;
82      }
83  
84      public void setManager(ConnectionManager manager)
85      {
86          this.manager = manager;
87      }
88  
89      public MuleManagedConnectionFactory getFactory()
90      {
91          return factory;
92      }
93  
94      public void setFactory(MuleManagedConnectionFactory factory)
95      {
96          this.factory = factory;
97      }
98  
99      public Reference getReference()
100     {
101         return reference;
102     }
103 
104     public void setReference(Reference reference)
105     {
106         this.reference = reference;
107     }
108 
109     public MuleConnectionRequestInfo getInfo()
110     {
111         return info;
112     }
113 
114     public void setInfo(MuleConnectionRequestInfo info)
115     {
116         this.info = info;
117     }
118 }