KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > fs > DirContextFactoryImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
26 import javax.resource.ResourceException JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28 import javax.naming.Reference JavaDoc;
29 import javax.naming.directory.DirContext JavaDoc;
30
31 import org.jboss.logging.Logger;
32
33 /**
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 58115 $
36  */

37 public class DirContextFactoryImpl implements DirContextFactory
38 {
39    static Logger log = Logger.getLogger(DirContextFactoryImpl.class);
40    private transient ConnectionManager JavaDoc manager;
41    private transient ManagedConnectionFactory JavaDoc factory;
42    private transient FSRequestInfo fsInfo;
43    private Reference JavaDoc reference;
44
45    DirContextFactoryImpl(ConnectionManager JavaDoc manager,
46       ManagedConnectionFactory JavaDoc factory, FSRequestInfo fsInfo)
47    {
48       this.manager = manager;
49       this.factory = factory;
50       this.fsInfo = fsInfo;
51       log.debug("ctor, fsInfo="+fsInfo);
52    }
53
54    public DirContext JavaDoc getConnection() throws NamingException JavaDoc
55    {
56       log.debug("getConnection", new Exception JavaDoc("CalledBy:"));
57       DirContext JavaDoc dc = null;
58       try
59       {
60          dc = (DirContext JavaDoc) manager.allocateConnection(factory, fsInfo);
61       }
62       catch(ResourceException JavaDoc e)
63       {
64          throw new NamingException JavaDoc("Unable to get Connection: "+e);
65       }
66       return dc;
67    }
68    public DirContext JavaDoc getConnection(String JavaDoc user, String JavaDoc password) throws NamingException JavaDoc
69    {
70       log.debug("getConnection, user="+user);
71       DirContext JavaDoc dc = null;
72       try
73       {
74          dc = (DirContext JavaDoc) manager.allocateConnection(factory, fsInfo);
75       }
76       catch(ResourceException JavaDoc e)
77       {
78          throw new NamingException JavaDoc("Unable to get Connection: "+e);
79       }
80       return dc;
81    }
82
83    public void setReference(Reference JavaDoc reference)
84    {
85       log.debug("setReference, reference="+reference, new Exception JavaDoc("CalledBy:"));
86       this.reference = reference;
87    }
88
89    public Reference JavaDoc getReference() throws NamingException JavaDoc
90    {
91       log.debug("getReference");
92       return reference;
93    }
94 }
95
Popular Tags