KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 1998-2000 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.iiop;
30
31 import com.caucho.log.Log;
32 import com.caucho.naming.AbstractModel;
33 import com.caucho.naming.MemoryModel;
34
35 import org.omg.CosNaming.NameComponent JavaDoc;
36 import org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc;
37 import org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc;
38 import org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc;
39 import org.omg.CosNaming.NamingContextPackage.NotFoundReason JavaDoc;
40
41 import javax.naming.NamingException JavaDoc;
42 import java.util.logging.Level JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44
45 public class CosServer {
46   private static final Logger JavaDoc log = Log.open(CosServer.class);
47     
48   private IiopProtocol _iiopServer;
49   private String JavaDoc _host;
50   private int _port;
51   
52   AbstractModel _model = new MemoryModel();
53
54   CosServer(IiopProtocol iiopServer)
55   {
56     _iiopServer = iiopServer;
57   }
58
59   void setHost(String JavaDoc host)
60   {
61     _host = host;
62   }
63
64   void setPort(int port)
65   {
66     _port = port;
67   }
68
69   public org.omg.CORBA.Object JavaDoc resolve(NameComponent JavaDoc []n)
70     throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc
71   {
72     Object JavaDoc value = null;
73     String JavaDoc host = _host;
74     String JavaDoc uri = "";
75
76     try {
77       if (log.isLoggable(Level.FINE)) {
78     String JavaDoc name = "";
79       
80     for (int i = 0; i < n.length; i++)
81       name += "/" + n[i].id;
82
83     log.fine("IIOP NameService lookup: " + name);
84       }
85       
86       for (int i = 0; i < n.length; i++) {
87         String JavaDoc name = n[i].id;
88         String JavaDoc type = n[i].kind;
89
90         value = _model.lookup(name);
91
92         if (value != null)
93           continue;
94
95     /*
96         if (i == 0) {
97         }
98         else if (i == 1) {
99           host = name;
100           continue;
101         }
102         else {
103           uri += "/" + name;
104           continue;
105         }
106     */

107     uri += "/" + name;
108       }
109
110       IiopSkeleton skel;
111       
112       if (value != null) {
113       }
114       else if (uri.equals("")) {
115         String JavaDoc oid = "/NameService";
116         skel = _iiopServer.getService(_host, _port, oid);
117
118     return skel;
119       }
120       else if ((skel = _iiopServer.getService(_host, _port, uri)) != null) {
121     return skel;
122       }
123     } catch (NamingException JavaDoc e) {
124       log.log(Level.FINE, e.toString(), e);
125       
126       throw new NotFound JavaDoc(NotFoundReason.from_int(NotFoundReason._missing_node), n);
127     }
128
129     log.fine("IIOP COS NotFound: " + uri);
130
131     throw new NotFound JavaDoc(NotFoundReason.from_int(NotFoundReason._missing_node), n);
132   }
133 }
134
Popular Tags