KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > connector > ra > fos > FosConnectionFactory


1 /**
2  * perseus/connector: this is an implementation of some JCA-related technologies
3  * (resource adapters and managers) for the ObjectWeb consortium.
4  * Copyright (C) 2001-2002 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: pascal.dechamboux@rd.francetelecom.com
21  *
22  */

23
24 package org.objectweb.perseus.connector.ra.fos;
25
26 import org.objectweb.perseus.connector.manager.standalone.SaManager;
27 import org.objectweb.perseus.fos.api.FosLoggerFactory;
28 import org.objectweb.util.monolog.api.BasicLevel;
29 import org.objectweb.util.monolog.api.Level;
30 import org.objectweb.util.monolog.api.Logger;
31
32 import javax.naming.NamingException JavaDoc;
33 import javax.naming.Reference JavaDoc;
34 import javax.resource.NotSupportedException JavaDoc;
35 import javax.resource.ResourceException JavaDoc;
36 import javax.resource.cci.Connection JavaDoc;
37 import javax.resource.cci.ConnectionFactory JavaDoc;
38 import javax.resource.cci.ConnectionSpec JavaDoc;
39 import javax.resource.cci.RecordFactory JavaDoc;
40 import javax.resource.cci.ResourceAdapterMetaData JavaDoc;
41 import javax.resource.spi.ConnectionManager JavaDoc;
42 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
43 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
44 import javax.security.auth.Subject JavaDoc;
45
46 /**
47  * @author S. Chassande-Barrioz, P. Dechamboux
48  */

49 public class FosConnectionFactory
50     implements ConnectionFactory JavaDoc, ResourceAdapterMetaData JavaDoc {
51     /**
52      * The logger into which traces about FosConnectionFactory are produced.
53      */

54     private Logger logger;
55     /**
56      * The logger into which traces about FosConnectionImpl are produced.
57      */

58     private Logger entityLogger;
59     /**
60      * The FOS Adapter Version.
61      */

62     private final static String JavaDoc FOSADAPTERVERSION = "1.01";
63     /**
64      * The FOS Adapter Vendor Name (i.e. ObjectWeb !!).
65      */

66     private final static String JavaDoc FOSADAPTERVENDORNAME = "The ObjectWeb Consortium";
67     /**
68      * The FOS Adapter Name.
69      */

70     private final static String JavaDoc FOSADAPTERNAME = "File Object Store (FOS) Adapter";
71     /**
72      * A short description of the FOS Adapter.
73      */

74     private final static String JavaDoc FOSADAPTERSHORTDESCRIPTION = "It provides a storage subsystem for storing data objects into files.\nThe approach assumes that each data object is stored within a different file.\nIt supports transactions (atomic I/Os through logging/recovery) as well as XA.";
75     /**
76      * The FOS Spec Version (none yet).
77      */

78     private final static String JavaDoc FOSSPECVERSION = "1.01";
79
80     /**
81      * The JNDI Reference associated to this adapter.
82      */

83     private Reference JavaDoc jndiReference = null;
84     /**
85      * The ConnectionManager used to actually get Connection.
86      */

87     private ConnectionManager JavaDoc connectionManager = null;
88     /**
89      * The ManagedConnectionFactory associated to this ConnectionFactory.
90      */

91     private FosManagedConnectionFactory managedConnectionFactory;
92
93     /**
94      * Constructs a FosConnectionFactory. Associates a ConnectionManager with
95      * it, or creates a default one (if null).
96      * @param fmcf The ManagedConnectionFactory to be associated with this
97      * ConnectionFactory.
98      * @param cm The ConnectionManager to be associated with this
99      * ConnectionFactory. It may be null.
100      */

101     FosConnectionFactory(FosManagedConnectionFactory fmcf, ConnectionManager JavaDoc cm)
102         throws ResourceException JavaDoc {
103         logger = fmcf.getLogger(FosLoggerFactory.CONNECTION, true);
104         entityLogger = fmcf.getLogger(FosLoggerFactory.CONNECTION, false);
105         if (FosLoggerFactory.DEBUG)
106             logger.log(BasicLevel.DEBUG,
107                        "Constructs a new FosConnectionFactory.");
108         if (cm == null) {
109             if (FosLoggerFactory.DEBUG)
110                 logger.log(BasicLevel.DEBUG,
111                     "Constructs a default ConnectionManager.");
112             connectionManager = new SaManager();
113             ((SaManager) connectionManager).setManagedConnectionFactory(fmcf);
114         } else {
115             connectionManager = cm;
116         }
117         managedConnectionFactory = fmcf;
118     }
119
120     /**
121      * Creates a new FosConnectionImpl.
122      * Should add a Pool in the future ??
123      */

124     FosConnectionImpl createConnection() throws ResourceException JavaDoc {
125         if (FosLoggerFactory.DEBUG)
126             logger.log(BasicLevel.DEBUG, "Creates a new FosConnectionImpl.");
127         return new FosConnectionImpl(entityLogger, this);
128     }
129
130     // IMPLEMENTATION OF METHODS FROM THE (cci)ConnectionFactory INTERFACE
131

132     /**
133      * Connection allocation is delegated to the ConnectionManager assigned to
134      * this factory.
135      */

136     public Connection JavaDoc getConnection() throws ResourceException JavaDoc {
137         return (Connection JavaDoc) connectionManager.allocateConnection(
138             managedConnectionFactory,
139             (ConnectionRequestInfo JavaDoc) null);
140     }
141
142     /**
143      * Connection allocation is delegated to the ConnectionManager assigned to
144      * this factory.
145      * @param spec The connection is not taken into account within FOS.
146      */

147     public Connection JavaDoc getConnection(ConnectionSpec JavaDoc spec) throws ResourceException JavaDoc {
148         return (Connection JavaDoc) connectionManager.allocateConnection(
149             managedConnectionFactory,
150             (ConnectionRequestInfo JavaDoc) null);
151     }
152
153     /**
154      * Assigns a JNDI Reference to the adapter.
155      * @param reference The JNDI Reference to be assigned.
156      */

157     public void setReference(Reference JavaDoc reference) {
158         jndiReference = reference;
159     }
160
161     /**
162      * Returns the JNDI Reference.
163      * @return The JNDI Reference.
164      */

165     public Reference JavaDoc getReference() throws NamingException JavaDoc {
166         return jndiReference;
167     }
168
169     /**
170      * No support for record.
171      */

172     public RecordFactory JavaDoc getRecordFactory() throws ResourceException JavaDoc {
173         throw new NotSupportedException JavaDoc("FOS: no support for record.");
174     }
175
176     /**
177      * The FosConnectionFactory manages its metadata on its own.
178      */

179     public ResourceAdapterMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
180         return this;
181     }
182
183     // IMPLEMENTATION OF METHODS FROM THE (cci)ResourceAdapaterMetaData INTERFACE
184

185     /**
186      * Gives access to the adapter version metadata for the FOS.
187      * @return The FOS adapter version.
188      */

189     public String JavaDoc getAdapterVersion() {
190         return FOSADAPTERVERSION;
191     }
192
193     /**
194      * Gives access to the adapter vendor name metadata for the FOS.
195      * @return The FOS adapter vendor name.
196      */

197     public String JavaDoc getAdapterVendorName() {
198         return FOSADAPTERVENDORNAME;
199     }
200
201     /**
202      * Gives access to the adapter name metadata for the FOS.
203      * @return The FOS adapter name.
204      */

205     public String JavaDoc getAdapterName() {
206         return FOSADAPTERNAME;
207     }
208
209     /**
210      * Gives access to a short description of the FOS adapter.
211      * @return The FOS short description.
212      */

213     public String JavaDoc getAdapterShortDescription() {
214         return FOSADAPTERSHORTDESCRIPTION;
215     }
216
217     /**
218      * Gives access to the specification version of the FOS.
219      * @return The FOS specification version.
220      */

221     public String JavaDoc getSpecVersion() {
222         return FOSSPECVERSION;
223     }
224
225     /**
226      * No interaction is supported by the FOS adapter.
227      */

228     public String JavaDoc[] getInteractionSpecsSupported() {
229         return new String JavaDoc[0];
230     }
231
232     /**
233      * No support for record.
234      */

235     public boolean supportsExecuteWithInputAndOutputRecord() {
236         return false;
237     }
238
239     /**
240      * No support for record.
241      */

242     public boolean supportsExecuteWithInputRecordOnly() {
243         return false;
244     }
245
246     /**
247      * Yes, it does support local transaction demarcation.
248      */

249     public boolean supportsLocalTransactionDemarcation() {
250         return true;
251     }
252 }
Popular Tags