KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > naming > LocalModel


1 /*
2  * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.naming;
30
31 import java.io.*;
32 import java.util.*;
33
34 import javax.naming.*;
35 import javax.ejb.*;
36
37 import com.caucho.util.*;
38 import com.caucho.vfs.*;
39
40 import com.caucho.naming.*;
41
42 import com.caucho.ejb.EnvServerManager;
43 import com.caucho.ejb.AbstractContext;
44 import com.caucho.ejb.AbstractServer;
45
46 import com.caucho.ejb.protocol.EjbProtocolManager;
47
48 /**
49  * JNDI context for Local requests.
50  */

51 public class LocalModel extends AbstractModel {
52   protected EjbProtocolManager _protocolManager;
53   protected String _prefix;
54
55   /**
56    * Creates a new Local Context.
57    */

58   public LocalModel(EjbProtocolManager protocolManager)
59   {
60     _protocolManager = protocolManager;
61     _prefix = "";
62   }
63
64   /**
65    * Creates a subcontext.
66    *
67    * @param env the JNDI environment
68    * @param prefix the URL prefix
69    */

70   public LocalModel(EjbProtocolManager protocolManager, String prefix)
71   {
72     _protocolManager = protocolManager;
73     
74     if (! prefix.endsWith("/"))
75       prefix = prefix + "/";
76     
77     if (! prefix.startsWith("/"))
78       prefix = "/" + prefix;
79     
80     _prefix = prefix;
81   }
82
83   /**
84    * Creates a new instance of MemoryModel.
85    */

86   protected AbstractModel create()
87   {
88     return new LocalModel(_protocolManager, _prefix);
89   }
90
91   public EnvServerManager getServerContainer()
92   {
93     return _protocolManager.getServerManager();
94   }
95
96   /**
97    * Looks up the named bean. Since we're assuming only a single level,
98    * just try to look it up directly.
99    *
100    * @param name the segment name to lookup
101    *
102    * @return the home stub.
103    */

104   public Object lookup(String name)
105     throws NamingException
106   {
107     try {
108       // _protocolManager.initJdbc();
109

110       AbstractServer server = _protocolManager.getServerByEJBName(_prefix + name);
111
112       if (server != null)
113         return server.getEJBLocalHome();
114       else {
115         String newPrefix = _prefix + name + "/";
116
117         ArrayList list = _protocolManager.getLocalChildren(newPrefix);
118
119         if (list != null && list.size() > 0)
120           return new LocalModel(_protocolManager, newPrefix);
121
122         if (newPrefix.equals("caucho-ejb-admin/"))
123           return _protocolManager.getServerManager().getAdmin();
124         
125         return null;
126       }
127     } catch (Exception e) {
128       throw new NamingExceptionWrapper(e);
129     }
130   }
131
132   /**
133    * Can't currently bind.
134    */

135   public void bind(String name, Object value)
136     throws NamingException
137   {
138     throw new UnsupportedOperationException();
139   }
140
141   /**
142    * Can't currently unbind.
143    */

144   public void unbind(String name)
145     throws NamingException
146   {
147     throw new UnsupportedOperationException();
148   }
149
150   /**
151    * Can't currently destroy a subcontext
152    */

153   public void destroySubcontext(String name)
154     throws NamingException
155   {
156     throw new UnsupportedOperationException();
157   }
158
159   /**
160    * Return the names.
161    */

162   public List list()
163   {
164     ArrayList list = _protocolManager.getLocalChildren(_prefix);
165
166     return list;
167   }
168
169   public AbstractModel createSubcontext(String name)
170     throws NamingException
171   {
172     throw new UnsupportedOperationException();
173   }
174
175   public String toString()
176   {
177     return "[LocalModel " + _prefix + "]";
178   }
179 }
180
Popular Tags