KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > jndi > HAJNDI


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.ha.jndi;
23
24 import java.util.Collection JavaDoc;
25
26 import javax.naming.Name JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import org.jnp.interfaces.Naming;
30
31 import org.jboss.cache.Fqn;
32 import org.jboss.cache.Cache;
33 import org.jboss.ha.framework.interfaces.HAPartition;
34 import org.jboss.logging.Logger;
35
36 /**
37  * This class utilizes JBossCache to provide a distributed JNDI implementation.
38  * Lookups will look for Names in HAJNDI then delegate to the local InitialContext.
39  *
40  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
41  * @author Scott.Stark@jboss.org
42  * @version $Revision: 58573 $
43  */

44 public class HAJNDI
45    implements org.jnp.interfaces.Naming
46 {
47    /** @since 1.12.2.4, jboss-3.2.2 */
48    static final long serialVersionUID = -6277328603304171620L;
49   
50    public static final String JavaDoc ROOT = "__HA_JNDI__";
51    public static final Fqn ROOTFQN = new Fqn(new Object JavaDoc[] { ROOT });
52    
53    // Attributes --------------------------------------------------------
54
private static Logger log = Logger.getLogger(HAJNDI.class);
55    
56    protected HAPartition partition;
57    protected TreeHead delegate;
58    protected Naming haStub;
59
60    // Constructor --------------------------------------------------------
61

62    public HAJNDI(HAPartition partition, Cache cache)
63    throws NamingException JavaDoc
64    {
65       if (partition == null)
66          throw new IllegalArgumentException JavaDoc("Null partition");
67       if (cache == null)
68          throw new IllegalArgumentException JavaDoc("Null cache");
69       this.partition = partition;
70       delegate = new TreeHead(cache, HAJNDI.ROOTFQN);
71       delegate.setPartition(this.partition);
72       delegate.setHARMIHead(this);
73
74    }
75    
76    // Public --------------------------------------------------------
77

78    public void init() throws Exception JavaDoc
79    {
80       delegate.init();
81    }
82
83    public void stop() throws Exception JavaDoc
84    {
85       delegate.stop();
86    }
87
88    public void destroy() throws Exception JavaDoc
89    {
90       delegate.destroy();
91    }
92
93    public void setHAStub (Naming stub)
94    {
95       this.haStub = stub;
96    }
97
98    public Naming getHAStub ()
99    {
100       return this.haStub;
101    }
102
103    // Naming implementation -----------------------------------------
104

105
106    public synchronized void bind(Name JavaDoc name, Object JavaDoc obj, String JavaDoc className)
107       throws NamingException JavaDoc
108    {
109       delegate.bind (name, obj, className);
110    }
111
112    public synchronized void rebind(Name JavaDoc name, Object JavaDoc obj, String JavaDoc className)
113       throws NamingException JavaDoc
114    {
115       delegate.rebind (name, obj, className);
116    }
117
118    public synchronized void unbind(Name JavaDoc name)
119       throws NamingException JavaDoc
120    {
121       delegate.unbind (name);
122    }
123
124    public Object JavaDoc lookup(Name JavaDoc name)
125       throws NamingException JavaDoc
126    {
127       return delegate.lookup (name);
128    }
129
130    public Collection JavaDoc list(Name JavaDoc name)
131       throws NamingException JavaDoc
132    {
133       return delegate.list(name) ;
134    }
135     
136    public Collection JavaDoc listBindings(Name JavaDoc name)
137       throws NamingException JavaDoc
138    {
139       return delegate.listBindings(name);
140    }
141    
142    public javax.naming.Context JavaDoc createSubcontext(Name JavaDoc name)
143       throws NamingException JavaDoc
144    {
145       return delegate.createSubcontext(name);
146    }
147 }
148
Popular Tags