KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > protocol > IiopProtocolContainer


1 /*
2  * Copyright (c) 1998-2006 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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.ejb.protocol;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.ejb.AbstractServer;
34 import com.caucho.iiop.IiopContext;
35 import com.caucho.iiop.IiopRemoteService;
36 import com.caucho.util.L10N;
37
38 import javax.ejb.EJBHome JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * Server containing all the EJBs for a given configuration.
43  *
44  * <p>Each protocol will extend the container to override Handle creation.
45  */

46 public class IiopProtocolContainer extends ProtocolContainer {
47   private static final Logger JavaDoc log
48     = Logger.getLogger(IiopProtocolContainer.class.getName());
49   private static final L10N L = new L10N(IiopProtocolContainer.class);
50
51   private IiopContext _context;
52
53   private IiopProtocolContainer(IiopContext context)
54   {
55     _context = context;
56   }
57
58   /**
59    * Creates the IIOP protocol server if IIOP is available.
60    */

61   public static IiopProtocolContainer createProtocolContainer()
62   {
63     IiopContext context = IiopContext.getLocalContext();
64
65     if (context != null)
66       return new IiopProtocolContainer(context);
67     else
68       return null;
69   }
70
71   /**
72    * Creates the IIOP protocol server if IIOP is available.
73    */

74   public static EJBHome JavaDoc findRemoteEJB(String JavaDoc ejbName)
75   {
76     IiopContext context = IiopContext.getLocalContext();
77
78     if (context == null)
79       return null;
80
81     if (! ejbName.startsWith("/"))
82       ejbName = "/" + ejbName;
83
84     IiopRemoteService service = context.getService(ejbName);
85
86     if (service != null)
87       return (EJBHome JavaDoc) service.getHome();
88     else
89       return null;
90   }
91
92   public String JavaDoc getName()
93   {
94     return "iiop";
95   }
96
97   /**
98    * Exports a server to iiop.
99    */

100   @Override JavaDoc
101   public void addServer(AbstractServer server)
102   {
103     if (server.getRemoteObject() == null)
104       return;
105
106     String JavaDoc name = getName(server);
107
108     log.fine("iiop: add server " + name);
109
110     EjbIiopRemoteService service = new EjbIiopRemoteService(server);
111
112     _context.setService(name, service);
113   }
114
115   private String JavaDoc getName(AbstractServer server)
116   {
117     String JavaDoc name = server.getProtocolId();
118     if (name == null)
119       name = server.getEJBName();
120
121     if (! name.startsWith("/"))
122       name = "/" + name;
123
124     return name;
125   }
126
127   /**
128    * Removes a server from iiop.
129    */

130   public void removeServer(AbstractServer server)
131   {
132     if (server.getRemoteObject() == null)
133       return;
134
135     String JavaDoc name = getName(server);
136     
137     _context.removeService(name);
138   }
139
140   protected HandleEncoder createHandleEncoder(AbstractServer server,
141                                               Class JavaDoc primaryKeyClass)
142     throws ConfigException
143   {
144     String JavaDoc name = getName(server);
145     
146     if (_urlPrefix != null)
147       return new HandleEncoder(server, _urlPrefix + name);
148     else
149       return new HandleEncoder(server, name);
150   }
151
152   /**
153    * Returns the skeleton
154    */

155   public Skeleton getSkeleton(String JavaDoc uri, String JavaDoc queryString)
156     throws Exception JavaDoc
157   {
158     throw new UnsupportedOperationException JavaDoc();
159   }
160 }
161
Popular Tags