001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.iiop;
030:
031: import com.caucho.log.Log;
032: import com.caucho.naming.AbstractModel;
033: import com.caucho.naming.MemoryModel;
034:
035: import org.omg.CosNaming.NameComponent;
036: import org.omg.CosNaming.NamingContextPackage.CannotProceed;
037: import org.omg.CosNaming.NamingContextPackage.InvalidName;
038: import org.omg.CosNaming.NamingContextPackage.NotFound;
039: import org.omg.CosNaming.NamingContextPackage.NotFoundReason;
040:
041: import javax.naming.NamingException;
042: import java.rmi.NoSuchObjectException;
043: import java.util.logging.Level;
044: import java.util.logging.Logger;
045:
046: public class CosServer {
047: private static final Logger log = Log.open(CosServer.class);
048:
049: private IiopProtocol _iiopServer;
050: private String _host;
051: private int _port;
052:
053: AbstractModel _model = new MemoryModel();
054:
055: CosServer(IiopProtocol iiopServer) {
056: _iiopServer = iiopServer;
057: }
058:
059: void setHost(String host) {
060: _host = host;
061: }
062:
063: void setPort(int port) {
064: _port = port;
065: }
066:
067: public org.omg.CORBA.Object resolve(NameComponent[] n)
068: throws NotFound, CannotProceed, InvalidName {
069: Object value = null;
070: String host = _host;
071: String uri = "";
072:
073: try {
074: if (log.isLoggable(Level.FINE)) {
075: String name = "";
076:
077: for (int i = 0; i < n.length; i++)
078: name += "/" + n[i].id;
079:
080: log.fine("IIOP NameService lookup: " + name);
081: }
082:
083: for (int i = 0; i < n.length; i++) {
084: String name = n[i].id;
085: String type = n[i].kind;
086:
087: value = _model.lookup(name);
088:
089: if (value != null)
090: continue;
091:
092: /*
093: if (i == 0) {
094: }
095: else if (i == 1) {
096: host = name;
097: continue;
098: }
099: else {
100: uri += "/" + name;
101: continue;
102: }
103: */
104: uri += "/" + name;
105: }
106:
107: IiopSkeleton skel;
108:
109: if (value != null) {
110: } else if (uri.equals("")) {
111: String oid = "/NameService";
112: skel = _iiopServer.getService(_host, _port, oid);
113:
114: return skel;
115: } else if ((skel = _iiopServer
116: .getService(_host, _port, uri)) != null) {
117: return skel;
118: }
119: } catch (NamingException e) {
120: log.log(Level.FINE, e.toString(), e);
121:
122: throw new NotFound(NotFoundReason
123: .from_int(NotFoundReason._missing_node), n);
124: } catch (NoSuchObjectException e) {
125: log.log(Level.FINE, e.toString(), e);
126:
127: throw new NotFound(NotFoundReason
128: .from_int(NotFoundReason._missing_node), n);
129: }
130:
131: log.fine("IIOP COS NotFound: " + uri);
132:
133: throw new NotFound(NotFoundReason
134: .from_int(NotFoundReason._missing_node), n);
135: }
136: }
|