01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.jca.fs;
23:
24: import javax.resource.spi.ConnectionManager;
25: import javax.resource.spi.ManagedConnectionFactory;
26: import javax.resource.ResourceException;
27: import javax.naming.NamingException;
28: import javax.naming.Reference;
29: import javax.naming.directory.DirContext;
30:
31: import org.apache.log4j.Category;
32:
33: /**
34: * @author Scott.Stark@jboss.org
35: * @version $Revision: 57211 $
36: */
37: public class DirContextFactoryImpl implements DirContextFactory {
38: static Category log = Category
39: .getInstance(DirContextFactoryImpl.class);
40: private transient ConnectionManager manager;
41: private transient ManagedConnectionFactory factory;
42: private transient FSRequestInfo fsInfo;
43: private Reference reference;
44:
45: DirContextFactoryImpl(ConnectionManager manager,
46: ManagedConnectionFactory factory, FSRequestInfo fsInfo) {
47: this .manager = manager;
48: this .factory = factory;
49: this .fsInfo = fsInfo;
50: log.debug("ctor, fsInfo=" + fsInfo);
51: }
52:
53: public DirContext getConnection() throws NamingException {
54: log.debug("getConnection", new Exception("CalledBy:"));
55: DirContext dc = null;
56: try {
57: dc = (DirContext) manager.allocateConnection(factory,
58: fsInfo);
59: } catch (ResourceException e) {
60: throw new NamingException("Unable to get Connection: " + e);
61: }
62: return dc;
63: }
64:
65: public DirContext getConnection(String user, String password)
66: throws NamingException {
67: log.debug("getConnection, user=" + user);
68: DirContext dc = null;
69: try {
70: dc = (DirContext) manager.allocateConnection(factory,
71: fsInfo);
72: } catch (ResourceException e) {
73: throw new NamingException("Unable to get Connection: " + e);
74: }
75: return dc;
76: }
77:
78: public void setReference(Reference reference) {
79: log.debug("setReference, reference=" + reference,
80: new Exception("CalledBy:"));
81: this .reference = reference;
82: }
83:
84: public Reference getReference() throws NamingException {
85: log.debug("getReference");
86: return reference;
87: }
88: }
|