KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > naming > NameService


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.naming;
20
21 import gcc.adapter.Adapter;
22
23 import javax.naming.*;
24 import java.util.*;
25
26 public class NameService
27 {
28     protected static NameService _ns = null;
29
30     public static NameService getInstance()
31     {
32         if (_ns == null)
33         {
34             synchronized( NameService.class )
35             {
36                 if (_ns == null)
37                 {
38                     _ns = new NameService();
39                     _ns.init();
40                 }
41             }
42         }
43
44         return _ns;
45     }
46
47     private gcc.naming.InitialContext _context;
48
49     /*
50      * TODO: Do we need this method?
51      */

52     public void bindAdapter(Adapter adp)
53     {
54         NamingContext.getInstance(NameService.class).bindAdapter( adp );
55     }
56
57     public static gcc.naming.InitialContext getInitialContext()
58     {
59         return getInstance()._context;
60     }
61
62     public HashMap getMap()
63     {
64         return _context.getMap();
65     }
66
67     public Object lookup(String name) throws NamingException
68     {
69         return _context.lookup(name);
70     }
71
72     protected void init()
73     {
74         _context = new gcc.naming.InitialContext(null);
75     }
76 }
77
Popular Tags