KickJava   Java API By Example, From Geeks To Geeks.

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


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
59 import javax.naming.Context JavaDoc;
60 import javax.naming.Name JavaDoc;
61 import javax.naming.NamingException JavaDoc;
62 import javax.naming.RefAddr JavaDoc;
63
64 import javax.naming.Reference JavaDoc;
65 import javax.naming.spi.InitialContextFactory JavaDoc;
66 import javax.naming.spi.ObjectFactory JavaDoc;
67
68 import org.apache.log4j.Logger;
69
70 public class LocalContextFactory implements InitialContextFactory JavaDoc, ObjectFactory JavaDoc {
71   private static final Logger log = Logger.getLogger(LocalContextFactory.class.getName());
72   private static final String JavaDoc NAME = "name";
73   
74   public LocalContextFactory() {
75   }
76   
77   public Context JavaDoc getInitialContext(Hashtable JavaDoc ht) throws NamingException JavaDoc {
78     if (ht != null && ht.containsKey(WLocalContext.NAMING_FACTORY_INITIAL)) {
79       return new WLocalContext(ht);
80     }
81     else {
82       return new LocalContext(ht);
83     }
84   }
85   
86   public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc ctx, Hashtable JavaDoc environment) throws Exception JavaDoc {
87     Reference JavaDoc ref = (Reference JavaDoc)obj;
88     if (ref.getClassName().equals(LocalContext.class.getName())) {
89       return LocalContext.getContext(getProperty(ref, NAME));
90     }
91     else {
92       return null;
93     }
94   }
95
96   protected String JavaDoc getProperty(Reference JavaDoc ref, String JavaDoc s) {
97     RefAddr JavaDoc addr = ref.get(s);
98     if (addr == null) {
99       return null;
100     }
101     return (String JavaDoc)addr.getContent();
102   }
103 }
104
Popular Tags