KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > jca > JalistoCfSerializationWrapper


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.jca;
25
26 import org.objectweb.jalisto.se.exception.JcaException;
27 import org.objectweb.jalisto.se.impl.trace.Trace;
28
29 import javax.naming.Reference JavaDoc;
30 import javax.resource.ResourceException JavaDoc;
31 import javax.resource.spi.ConnectionManager JavaDoc;
32 import java.io.ObjectStreamException JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34 import java.io.Serializable JavaDoc;
35
36 public class JalistoCfSerializationWrapper implements Serializable JavaDoc {
37
38     public JalistoCfSerializationWrapper() {
39     }
40
41     public void setConnectionManager(ConnectionManager JavaDoc cm) {
42         this.connectionManager = cm;
43     }
44
45     public void setManagedConnectionFactory(JalistoManagedConnectionFactory jdomcf) {
46         try {
47             logger = jdomcf.getLogWriter();
48         } catch (ResourceException JavaDoc e) {
49         }
50
51         connectionURL = jdomcf.getConnectionURL();
52         connectionDriverName = jdomcf.getConnectionDriverName();
53         hashCode = jdomcf.hashCode();
54     }
55
56     public void setReference(Reference JavaDoc ref) {
57         reference = ref;
58     }
59
60     public Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
61         if (trace != null) {
62             trace.println(Trace.JCA, TRACE_ID + " readResolve");
63         }
64
65         JalistoConnectionFactory result = null;
66
67         if (reference != null) {
68             result = (JalistoConnectionFactory) JalistoObjectFactory.getConnectionFactory(reference);
69         }
70
71         if (result == null) {
72             // fully rebuild a new identical JDOConnectionFactory (cluster case)
73
try {
74                 JalistoManagedConnectionFactory managedConnectionFactory = new JalistoManagedConnectionFactory();
75                 managedConnectionFactory.setLogWriter(logger);
76                 managedConnectionFactory.setConnectionURL(connectionURL);
77                 managedConnectionFactory.setConnectionDriverName(connectionDriverName);
78                 managedConnectionFactory.setHashCode(hashCode);
79                 result = (JalistoConnectionFactory) managedConnectionFactory.createConnectionFactory(connectionManager);
80             } catch (ResourceException JavaDoc e) {
81                 throw new JcaException("Cannot create new ConnectionFactory instance", e);
82             }
83         }
84
85         return result;
86     }
87
88
89     private ConnectionManager JavaDoc connectionManager = null;
90     private String JavaDoc connectionDriverName = null;
91     private String JavaDoc connectionURL = null;
92
93     private PrintWriter JavaDoc logger = null;
94     private Reference JavaDoc reference = null;
95
96     private Trace trace = null;
97     private int hashCode = 0;
98
99
100     private static final String JavaDoc TRACE_ID = "[JalistoCfSerializationWrapper]";
101
102     static final long serialVersionUID = -7589377087964761669L;
103 }
104
Popular Tags