KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > vendor > jboss > jndi > FakeSerializableArrayList


1 /**
2 * Library name : Primrose - A Java Database Connection Pool.
3 * Published by Ben Keeping, http://primrose.org.uk .
4 * Copyright (C) 2004 Ben Keeping, primrose.org.uk
5 * Email: Use "Contact Us Form" on website
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package uk.org.primrose.vendor.jboss.jndi;
23
24 import java.util.ArrayList JavaDoc;
25 import java.io.Serializable JavaDoc;
26 import org.jboss.naming.NonSerializableFactory;
27
28 /**
29 * This comment is on all of the vendor.jboss package classes, because the classes are
30 * so interlinked. It documents how we bind primrose under JBoss.<p>
31 * JBoss has two JNDI trees.
32 * <ul>
33 * <li>A serializable object tree.
34 * <li>A non-serializable object tree.
35 * </ul>
36 * Primrose's core jmx objects (Queue, PoolController) cannot be bound under the serializable tree
37 * because JBoss checks <i>on binding</i> whether the objects can be serialized. Because the Queue objects
38 * contain Connection objects, this will always fail.<p>
39 * So how do we get around this ?!<br>
40 * First, the MasterPoolDataSourceFactory (deployed via the SAR) initializes the pool, and binds
41 * the Queue objects, and the PoolController object under the non-serializable tree.<p>
42 * Then all the pool DataSource objects, created via the PoolDataSourceFactory's (via BindPrimrose)
43 * are all bound under the non-serializable tree.<br>
44 * Get a list of the pools bound by PoolController,
45 * and then for each one, let the PoolDataSourceFactory object
46 * create our DatSource objects, which we will bind under the non-serializable tree.
47 * Also bind our 'fake' DataSource objects under the normal JNDI tree
48 * so they can be bound, and access the real non-serializable objects at runtime
49 * for extracting client connections.<p>
50 *
51 * When client code looks up our fake DataSource object (unbeknown to them obviously), and calls
52 * the getConnection() method, our fake object gets a ref to the real DataSource from the non-serializable
53 * JNDI tree, and extracts the Connection for the client.<p>
54 *
55 * Why does this work ? <br>
56 * The serializable JNDI tree only checks for serializablity at the point of binding - not when you
57 * do lookup() calls - so as long as we can bind our fake DataSources at the primrose initialization
58 * point, it works.
59 */

60 public class FakeSerializableArrayList implements Serializable JavaDoc {
61     private String JavaDoc name = "";
62
63     /**
64     * Default constructor to conform with Serialization protocol. Not used.
65     */

66     public FakeSerializableArrayList() {}
67
68     /**
69     * Construct the object with the name that the real JNDI resource is bound under.
70     */

71     public FakeSerializableArrayList(String JavaDoc name) {
72         this.name = name;
73     }
74
75     /**
76     * Called from PoolDataSource.<br>
77     * When the JNDI call is made to obtain the list of bound Queue objects,
78     * it is checked whether the object is an instanceof FakeSerializableArrayList.<br>
79     * If it is, this initialize() method is called to obtain the real ArrayList.
80     */

81     public ArrayList JavaDoc initialize() {
82         ArrayList JavaDoc faked = (ArrayList JavaDoc)NonSerializableFactory.lookup(name);
83         return faked;
84     }
85 }
Popular Tags