KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lateralnz > panther > naming > WLocalContext


1 /* ====================================================================
2  * The LateralNZ Software License, Version 1.0
3  *
4  * Copyright (c) 2003 LateralNZ. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by
21  * LateralNZ (http://www.lateralnz.org/) and other third parties."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "LateralNZ" must not be used to endorse or promote
26  * products derived from this software without prior written
27  * permission. For written permission, please
28  * contact oss@lateralnz.org.
29  *
30  * 5. Products derived from this software may not be called "Panther",
31  * or "Lateral" or "LateralNZ", nor may "PANTHER" or "LATERAL" or
32  * "LATERALNZ" appear in their name, without prior written
33  * permission of LateralNZ.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of LateralNZ. For more
51  * information on Lateral, please see http://www.lateralnz.com/ or
52  * http://www.lateralnz.org
53  *
54  */

55 package org.lateralnz.panther.naming;
56
57 import java.util.Hashtable JavaDoc;
58 import java.util.HashMap JavaDoc;
59 import javax.naming.*;
60
61 import org.apache.log4j.Logger;
62
63 import org.lateralnz.common.util.Constants;
64 import org.lateralnz.common.util.StringUtils;
65 import org.lateralnz.panther.util.EJBRef;
66
67 /**
68  *
69  * @author jbriggs
70  */

71 public class WLocalContext extends LocalContext implements Context, Constants, Referenceable {
72   public static final String JavaDoc NAMING_FACTORY_INITIAL = "panther.naming.factory.initial";
73   
74   private static final Logger log = Logger.getLogger(WLocalContext.class.getName());
75
76   Context ctx = null;
77     
78   public WLocalContext(HashMap JavaDoc objects, Hashtable JavaDoc environ) {
79     super(objects, environ);
80   }
81   
82   public WLocalContext(Hashtable JavaDoc ht) throws NamingException {
83     super(ht);
84     String JavaDoc tmp = (String JavaDoc)ht.get(NAMING_FACTORY_INITIAL);
85     if (StringUtils.isEmpty(tmp)) {
86       tmp = System.getProperty(NAMING_FACTORY_INITIAL);
87     }
88     if (StringUtils.isEmpty(tmp)) {
89       throw new NamingException("missing '" + NAMING_FACTORY_INITIAL + "'");
90     }
91     ht.put(Context.INITIAL_CONTEXT_FACTORY, tmp);
92     ctx = new InitialContext(ht);
93   }
94   
95   public LocalContext create(HashMap JavaDoc objects, Hashtable JavaDoc environ) {
96     return new WLocalContext(objects, environ);
97   }
98
99   public Object JavaDoc addToEnvironment(String JavaDoc name, Object JavaDoc obj) throws NamingException {
100     ctx.addToEnvironment(name, obj);
101     return super.addToEnvironment(name, obj);
102   }
103   
104   public void bind(Name name, Object JavaDoc obj) throws NamingException {
105     bind(name.toString(), obj);
106   }
107   
108   public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
109     ctx.bind(name, obj);
110     super.bind(name, obj);
111   }
112   
113   public void close() throws NamingException {
114     super.close();
115     ctx = null;
116   }
117   
118   public Context createSubcontext(String JavaDoc name) throws NamingException {
119     Context sub = ctx.createSubcontext(name);
120     WLocalContext wctx = (WLocalContext)super.createSubcontext(name);
121     wctx.ctx = sub;
122     return wctx;
123   }
124   
125   public void destroySubcontext(Name name) throws NamingException {
126     destroySubcontext(name.toString());
127   }
128   
129   public void destroySubcontext(String JavaDoc name) throws NamingException {
130     ctx.destroySubcontext(name);
131     super.destroySubcontext(name);
132   }
133   
134   public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
135     ctx.rebind(name, obj);
136     super.rebind(name, obj);
137   }
138     
139   public Object JavaDoc removeFromEnvironment(String JavaDoc name) throws NamingException {
140     ctx.removeFromEnvironment(name);
141     return super.removeFromEnvironment(name);
142   }
143   
144   public void rename(String JavaDoc name1, String JavaDoc name2) throws NamingException {
145     ctx.rename(name1, name2);
146     super.rename(name1, name2);
147   }
148   
149   public void unbind(String JavaDoc name) throws NamingException {
150     ctx.unbind(name);
151     super.unbind(name);
152   }
153
154 }
Popular Tags