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