14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
19
17
package org.apache.naming.factory;
21
import java.util.Hashtable;
23
import javax.naming.Context;
24
import javax.naming.Name;
25
import javax.naming.NamingException;
26
import javax.naming.RefAddr;
27
19
import javax.naming.Reference;
28
20
import javax.naming.spi.ObjectFactory;
35
27
* @author Remy Maucherat
37
public class TransactionFactory
38
implements ObjectFactory {
41
// ----------------------------------------------------------- Constructors
44
// -------------------------------------------------------------- Constants
47
// ----------------------------------------------------- Instance Variables
50
// --------------------------------------------------------- Public Methods
53
// -------------------------------------------------- ObjectFactory Methods
57
* Create a new User transaction instance.
59
* @param obj The reference object describing the DataSource
62
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
63
Hashtable<?,?> environment)
66
if (obj instanceof TransactionRef) {
67
Reference ref = (Reference) obj;
68
ObjectFactory factory = null;
69
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
70
if (factoryRefAddr != null) {
71
// Using the specified factory
72
String factoryClassName =
73
factoryRefAddr.getContent().toString();
76
Thread.currentThread().getContextClassLoader();
77
Class<?> factoryClass = null;
80
factoryClass = tcl.loadClass(factoryClassName);
81
} catch(ClassNotFoundException e) {
82
NamingException ex = new NamingException
83
("Could not load resource factory class");
89
factoryClass = Class.forName(factoryClassName);
90
} catch(ClassNotFoundException e) {
91
NamingException ex = new NamingException
92
("Could not load resource factory class");
97
if (factoryClass != null) {
99
factory = (ObjectFactory) factoryClass.newInstance();
100
} catch(Throwable t) {
101
if (t instanceof NamingException)
102
throw (NamingException) t;
103
NamingException ex = new NamingException
104
("Could not create resource factory instance");
110
if (factory != null) {
111
return factory.getObjectInstance
112
(obj, name, nameCtx, environment);
114
throw new NamingException
115
("Cannot create resource instance");
29
public class TransactionFactory extends FactoryBase {
32
protected boolean isReferenceTypeSupported(Object obj) {
33
return obj instanceof TransactionRef;
37
protected ObjectFactory getDefaultFactory(Reference ref) {
38
// No default factory supported.
43
protected Object getLinked(Reference ref) {