KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > iiop > IiopProtocol


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.iiop;
31
32 import com.caucho.log.Log;
33 import com.caucho.management.j2ee.J2EEManagedObject;
34 import com.caucho.management.j2ee.RMI_IIOPResource;
35 import com.caucho.server.connection.Connection;
36 import com.caucho.server.port.Protocol;
37 import com.caucho.server.port.ServerRequest;
38
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * The main class for the HTTP server.
43  *
44  * <p>TcpServer handles the main thread control. HttpServer just needs
45  * to create the right kind of request when a new thread is spawned.
46  *
47  * @see com.caucho.server.TcpServer
48  */

49 public class IiopProtocol extends Protocol {
50   private static final Logger JavaDoc log = Log.open(IiopProtocol.class);
51
52   static final String JavaDoc COPYRIGHT =
53     "Copyright (c) 1998-2006 Caucho Technology. All rights reserved.";
54
55   private String JavaDoc _protocolName = "iiop";
56   private CosServer _cos;
57
58   private IiopContext _iiopContext;
59
60   /**
61    * Creates the IIOP protocol.
62    */

63   public IiopProtocol()
64   {
65     _iiopContext = new IiopContext();
66
67     _cos = new CosServer(this);
68
69     IiopContext.setLocalContext(_iiopContext);
70   }
71
72   /**
73    * Returns the protocol name.
74    */

75   public String JavaDoc getProtocolName()
76   {
77     return _protocolName;
78   }
79
80   /**
81    * Sets the protocol name.
82    */

83   public void setProtocolName(String JavaDoc name)
84   {
85     _protocolName = name;
86   }
87
88   public void init()
89   {
90     J2EEManagedObject.register(new RMI_IIOPResource(this));
91
92   }
93
94   public CosServer getCos()
95   {
96     return _cos;
97   }
98
99   public IiopSkeleton getService(String JavaDoc host, int port, String JavaDoc oid)
100   {
101     return lookupService(host, port, oid);
102   }
103
104   /**
105    * Returns the service with the given URL.
106    */

107   private IiopSkeleton lookupService(String JavaDoc host, int port, String JavaDoc oid)
108   {
109     String JavaDoc url;
110     String JavaDoc local;
111
112     int p = oid.indexOf('?');
113
114     if (p < 0) {
115       url = oid;
116       local = null;
117     }
118     else {
119       url = oid.substring(0, p);
120       local = oid.substring(p + 1);
121     }
122
123     IiopRemoteService service = _iiopContext.getService(url);
124
125     if (service == null)
126       return null;
127     else if (local == null) {
128       return new IiopSkeleton(service.getHome(),
129                   service.getHomeAPI(),
130                               service.getClassLoader(),
131                               host, port, url);
132     }
133     else {
134       Object JavaDoc obj = service.getObject(local);
135
136       if (obj == null)
137         return null;
138
139       return new IiopSkeleton(obj, service.getObjectAPI(),
140                               service.getClassLoader(),
141                               host, port, url + '?' + local);
142     }
143   }
144
145   /**
146    * Create a HttpRequest object for the new thread.
147    */

148   public ServerRequest createRequest(Connection conn)
149   {
150     return new IiopRequest(this, conn);
151   }
152 }
153
Popular Tags