Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java Wed Mar 23 09:56:34 2005 @@ -36,27 +36,23 @@ import org.apache.geronimo.interop.rmi.iiop.compiler.StubFactory; import org.apache.geronimo.interop.util.ExceptionUtil; - public class ClientNamingContext implements Context, java.io.Serializable { + public static ClientNamingContext getInstance(Hashtable env) { - ClientNamingContext nc = (ClientNamingContext) _contextMap.get(env); + ClientNamingContext nc = (ClientNamingContext) contextMap.get(env); if (nc == null) { - synchronized (_contextMap) { - nc = (ClientNamingContext) _contextMap.get(env); + synchronized (contextMap) { + nc = (ClientNamingContext) contextMap.get(env); if (nc == null) { nc = new ClientNamingContext(); nc.init(env); - _contextMap.put(env, nc); + contextMap.put(env, nc); } } } return nc; } - // ----------------------------------------------------------------------- - // properties - // ----------------------------------------------------------------------- - public static final StringProperty usernameProperty = new StringProperty(SystemProperties.class, "java.naming.security.principal"); @@ -67,64 +63,45 @@ new IntProperty(SystemProperties.class, "org.apache.geronimo.interop.rmi.idleConnectionTimeout") .defaultValue(60); // seconds - // ----------------------------------------------------------------------- - // private data - // ----------------------------------------------------------------------- - - private static int _idleConnectionTimeout = + private static int idleConnectionTimeout = idleConnectionTimeoutProperty.getInt(); - private static int _namingContextCacheTimeout = + private static int namingContextCacheTimeout = SystemProperties.rmiNamingContextCacheTimeoutProperty.getInt(); - private static HashMap _contextMap = new HashMap(); - - private static HashMap _hostListCache = new HashMap(); - - private static HashMap _multiHostMap = new HashMap(); - - private static Random _random = new Random(); - - private HashMap _cache = new HashMap(); - - private Hashtable _env; - - private ConnectionPool _connectionPool; + private static HashMap contextMap = new HashMap(); + private static HashMap hostListCache = new HashMap(); + private static HashMap multiHostMap = new HashMap(); + private static Random random = new Random(); + private HashMap cache = new HashMap(); + private Hashtable env; + private ConnectionPool connectionPool; + private PropertyMap connectionProperties; + static private HashMap nameMap = new HashMap(); + private String prefix; + private String username; + private String password; - private PropertyMap _connectionProperties; - - private org.apache.geronimo.interop.CosNaming.NamingContext _serverNamingContext; - static private HashMap _nameMap = new HashMap(); - - - private String _prefix; - - private String _username; - - private String _password; - - // ----------------------------------------------------------------------- - // public methods - // ----------------------------------------------------------------------- + private org.apache.geronimo.interop.CosNaming.NamingContext serverNamingContext; public ConnectionPool getConnectionPool() { - return _connectionPool; + return connectionPool; } public PropertyMap getConnectionProperties() { - return _connectionProperties; + return connectionProperties; } public int getIdleConnectionTimeout() { - return _idleConnectionTimeout; + return idleConnectionTimeout; } public String getUsername() { - return _username; + return username; } public String getPassword() { - return _password; + return password; } // ----------------------------------------------------------------------- @@ -140,22 +117,22 @@ name = name.substring(14); } - String newName = (String) _nameMap.get(name); + String newName = (String) nameMap.get(name); if (newName != null) { name = newName; } - NameBinding nb = (NameBinding) _cache.get(name); + NameBinding nb = (NameBinding) cache.get(name); if (nb == null) { - synchronized (_cache) { - nb = (NameBinding) _cache.get(name); + synchronized (cache) { + nb = (NameBinding) cache.get(name); if (nb != null && nb.hasExpired()) { - _cache.remove(name); + cache.remove(name); nb = null; } if (nb == null) { nb = resolve(name); - _cache.put(name, nb); + cache.put(name, nb); } } } @@ -163,17 +140,16 @@ } public HostList lookupHost(String name) { - NameBinding nb = (NameBinding) _hostListCache.get(name); + NameBinding nb = (NameBinding) hostListCache.get(name); if (nb == null) { - synchronized (_hostListCache) { - nb = (NameBinding) _hostListCache.get(name); + synchronized (hostListCache) { + nb = (NameBinding) hostListCache.get(name); if (nb != null && nb.hasExpired()) { - _hostListCache.remove(name); + hostListCache.remove(name); nb = null; } - if (nb == null) { - nb = resolve_host(name); - _hostListCache.put(name, nb); + if (nb == null) { + hostListCache.put(name, nb); } } } @@ -181,7 +157,7 @@ } public static void bind(String bindName, String name) throws NamingException { - _nameMap.put(bindName, name); + nameMap.put(bindName, name); } public void bind(Name name, Object obj) throws NamingException { @@ -217,22 +193,18 @@ } public NamingEnumeration list(Name name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration list(String name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration listBindings(Name name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration listBindings(String name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } @@ -253,12 +225,10 @@ } public Object lookupLink(Name name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } public Object lookupLink(String name) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } @@ -271,12 +241,10 @@ } public Name composeName(Name name, Name prefix) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } public String composeName(String name, String prefix) throws NamingException { - // TODO: support this throw new OperationNotSupportedException(); } @@ -300,12 +268,8 @@ throw new OperationNotSupportedException(); } - // ----------------------------------------------------------------------- - // protected methods - // ----------------------------------------------------------------------- - protected void init(Hashtable env) { - _env = env; + env = env; Object urlObject = env.get(Context.PROVIDER_URL); if (urlObject == null) { System.out.println("ClientNamingContext.init(): TODO: urlObject was null, create one based on the current hostname."); @@ -314,16 +278,16 @@ } String url = urlObject.toString(); UrlInfo urlInfo = UrlInfo.getInstance(url); - _serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext) + serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext) StubFactory.getInstance().getStub(org.apache.geronimo.interop.CosNaming.NamingContext.class); - ObjectRef ncRef = (ObjectRef) _serverNamingContext; + ObjectRef ncRef = (ObjectRef) serverNamingContext; ncRef.$setNamingContext(this); ncRef.$setProtocol(urlInfo.getProtocol()); ncRef.$setHost("ns~" + urlInfo.getHost()); ncRef.$setPort(urlInfo.getPort()); ncRef.$setObjectKey(urlInfo.getObjectKey()); - _connectionProperties = urlInfo.getProperties(); - _connectionPool = ConnectionPool.getInstance(this); + connectionProperties = urlInfo.getProperties(); + connectionPool = ConnectionPool.getInstance(this); Object u = env.get(Context.SECURITY_PRINCIPAL); Object p = env.get(Context.SECURITY_CREDENTIALS); if (u == null) { @@ -332,8 +296,8 @@ if (p == null) { p = passwordProperty.getString(); } - _username = u != null ? u.toString() : null; - _password = p != null ? p.toString() : null; + username = u != null ? u.toString() : null; + password = p != null ? p.toString() : null; /* if (_serverNamingContext._is_a("IDL:org.apache.geronimo.interop/rmi/iiop/NameService:1.0")) @@ -355,34 +319,21 @@ if (value != null) { NameBinding nb = new NameBinding(); nb.object = value; - nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout; + nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout; return nb; } try { org.apache.geronimo.interop.CosNaming.NameComponent[] resolveName = {new org.apache.geronimo.interop.CosNaming.NameComponent(name, "")}; - org.omg.CORBA.Object object = _serverNamingContext.resolve(resolveName); + org.omg.CORBA.Object object = serverNamingContext.resolve(resolveName); NameBinding nb = new NameBinding(); nb.object = object; - nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout; + nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout; return nb; } catch (org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound notFound) { throw new NameNotFoundException(name); } catch (Exception ex) { throw new javax.naming.NamingException(ExceptionUtil.getStackTrace(ex)); } - } - - protected NameBinding resolve_host(String host) { - HostList list = null; - if (_serverNamingContext instanceof org.apache.geronimo.interop.rmi.iiop.NameService) { - org.apache.geronimo.interop.rmi.iiop.NameService nameService = (org.apache.geronimo.interop.rmi.iiop.NameService) _serverNamingContext; - list = new HostList(nameService.resolve_host(host)); - } - NameBinding nb = new NameBinding(); - nb.object = list; - //nb.cacheTimeout = System.currentTimeMillis() - // + (list != null ? list.getCacheTimeout() : _namingContextCacheTimeout); - return nb; } }
Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java Wed Mar 23 09:56:34 2005 @@ -39,8 +39,8 @@ import org.apache.geronimo.interop.util.ThreadContext; import org.apache.geronimo.interop.util.UTF8; - public class Connection { + public Connection() { } @@ -50,10 +50,6 @@ return conn; } - // ----------------------------------------------------------------------- - // properties - // ----------------------------------------------------------------------- - public static final BooleanProperty simpleIDLProperty = new BooleanProperty(SystemProperties.class, "org.apache.geronimo.interop.simpleIDL"); @@ -61,104 +57,56 @@ new IntProperty(Connection.class, "socketTimeout") .defaultValue(SystemProperties.rmiSocketTimeoutProperty.getInt()); - // ----------------------------------------------------------------------- - // private data - // ----------------------------------------------------------------------- - - private static final boolean SIMPLE_IDL = simpleIDLProperty.getBoolean(); - - private ServiceContext[] EMPTY_SERVICE_CONTEXT = {}; - - private String _url; - - private boolean _ok; - - private InstancePool _pool; - - private String _serverHost; - - private Socket _socket; - - private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream _input; - - private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream _output; - - private CdrOutputStream _parameters; + private static final boolean SIMPLE_IDL = false; // simpleIDLProperty.getBoolean(); + private ServiceContext[] EMPTY_SERVICE_CONTEXT = {}; + private String url; + private boolean ok; + private InstancePool pool; + private String serverHost; + private Socket socket; + private CdrOutputStream parameters; + private CdrOutputStream requestOut; + private CdrInputStream results; + private String exceptionType; + private Exception exception; + private RequestHeader_1_2 requestHeader; + private int callForget; - private CdrOutputStream _requestOut; + private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input; + private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output; - private CdrInputStream _results; - - private String _exceptionType; - - private Exception _exception; - - private RequestHeader_1_2 _requestHeader; - - private int _callForget; - - // ----------------------------------------------------------------------- - // protected data - // ----------------------------------------------------------------------- - - protected java.io.InputStream _socketIn; - - protected java.io.OutputStream _socketOut; - - // ----------------------------------------------------------------------- - // public methods - // ----------------------------------------------------------------------- + protected java.io.InputStream socketIn; + protected java.io.OutputStream socketOut; public String getInstanceName() { - return _url; + return url; } public void close() { - _parameters = null; -// _results.recycle(); -// _results = null; - _input = null; - _output = null; - if (_ok) { - _pool.put(this); + parameters = null; + input = null; + output = null; + if (ok) { + pool.put(this); } else { shutdown(); } } public void beforeInvoke() { - _ok = false; - _parameters = CdrOutputStream.getInstance(); + ok = false; + parameters = CdrOutputStream.getInstance(); } public void forget(Object requestKey) { - if (_callForget != 0) { - /* - String key = (String)requestKey; - try - { - ClusterService cs = _results.getNamingContext().getClusterService(); - if (_callForget == 0xCFCFCFCF) - { - cs.forgetRequest(key); - } - else if (_callForget == 0xDFDFDFDF) - { - cs.forgetResponse(key); - } - } - catch (Exception ignore) - { - // TODO: log in debug mode? - } - */ - } } public void invoke(ObjectRef object, String method, Object requestKey, int retryCount) { - _callForget = 0; // see 'forget' and 'processReplyServiceContext' + RequestHeader_1_2 request = requestHeader; - RequestHeader_1_2 request = _requestHeader; + System.out.println( "object = " + object ); + System.out.println( "method = " + method ); + System.out.println( "requestKey = " + requestKey ); request.request_id = 0; request.response_flags = 3; @@ -169,13 +117,15 @@ request.reserved = new byte[3]; // Sun's generated org.omg.GIOP.RequestHeader_1_2Helper wants this.... - if (_requestOut == null) { - _requestOut = CdrOutputStream.getInstance(); + if (requestOut == null) { + System.out.println( "requestOut == null" ); + requestOut = CdrOutputStream.getInstance(); } - _requestOut.write_request(request, _parameters); + System.out.println( "write_request" ); + requestOut.write_request(request, parameters); try { - _requestOut.send_message(_socketOut, _url);//_serverHost); + requestOut.send_message(socketOut, url);//_serverHost); } catch (RuntimeException ex) { //if (object.$getAutomaticFailover()) //{ @@ -184,18 +134,18 @@ throw ex; } - _requestOut.reset(); + requestOut.reset(); - if (_results == null) { - _results = CdrInputStream.getInstance(); + if (results == null) { + results = CdrInputStream.getInstance(); } else { - _results.reset(); + results.reset(); } - _results.setNamingContext(object.$getNamingContext()); + results.setNamingContext(object.$getNamingContext()); GiopMessage message; try { - message = _results.receive_message(_socketIn, _url);//_serverHost); + message = results.receive_message(socketIn, url);//_serverHost); } catch (BadMagicException ex) { throw new SystemException(ex); } catch (UnsupportedProtocolVersionException ex) { @@ -213,88 +163,84 @@ throw new SystemException("TODO: message type = " + message.type); } - _ok = true; + ok = true; } public InstancePool getInstancePool() { - return _pool; + return pool; } public void setInstancePool(InstancePool pool) { - _pool = pool; + this.pool = pool; } public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getInputStream() { if (SIMPLE_IDL) { return getSimpleInputStream(); } - if (_input == null) { - _input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(_results); + if (input == null) { + input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(results); } - return _input; + return input; } public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getOutputStream() { if (SIMPLE_IDL) { return getSimpleOutputStream(); } - if (_output == null) { - _output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(_parameters); + if (output == null) { + output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(parameters); } - return _output; + return output; } public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getSimpleInputStream() { - if (_input == null) { - _input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(_results); + if (input == null) { + input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(results); } - return _input; + return input; } public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getSimpleOutputStream() { - if (_output == null) { - _output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(_parameters); + if (output == null) { + output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(parameters); } - return _output; + return output; } public String getExceptionType() { - return _exceptionType; + return exceptionType; } public Exception getException() { - if (_exception == null) { - if (_exceptionType != null) { - return new SystemException(_exceptionType, new org.omg.CORBA.UNKNOWN()); + if (exception == null) { + if (exceptionType != null) { + return new SystemException(exceptionType, new org.omg.CORBA.UNKNOWN()); } else { throw new IllegalStateException("no exception"); } } else { - return _exception; + return exception; } } - // ----------------------------------------------------------------------- - // protected methods - // ----------------------------------------------------------------------- - // TODO: check why we have 'objectRef' parameter??? protected void init(String endpoint, ObjectRef objectRef, PropertyMap connProps) { - _url = "iiop://" + endpoint; - UrlInfo urlInfo = UrlInfo.getInstance(_url); + url = "iiop://" + endpoint; + UrlInfo urlInfo = UrlInfo.getInstance(url); String host = urlInfo.getHost(); int port = urlInfo.getPort(); int socketTimeout = socketTimeoutProperty.getInt(endpoint, connProps); try { - _socket = new Socket(host, port); - _socketIn = _socket.getInputStream(); - _socketOut = _socket.getOutputStream(); - _socket.setSoTimeout(1000 * socketTimeout); - _serverHost = host; + socket = new Socket(host, port); + socketIn = socket.getInputStream(); + socketOut = socket.getOutputStream(); + socket.setSoTimeout(1000 * socketTimeout); + serverHost = host; } catch (Exception ex) { throw new SystemException(errorConnectFailed(host, port, ex)); } - _requestHeader = new RequestHeader_1_2(); + requestHeader = new RequestHeader_1_2(); } public ServiceContext[] getServiceContext(ObjectRef object, Object requestKey, int retryCount) { @@ -386,7 +332,7 @@ || sc.context_id == 0xDFDFDFDF) { // "CF..." indicates "Call Forget Request" // "DF..." indicates "Call Forget Response" - _callForget = sc.context_id; + callForget = sc.context_id; } } } @@ -396,31 +342,31 @@ } protected void processUserException(ReplyHeader_1_2 reply) { - _exception = null; - _exceptionType = _results.read_string(); - _ok = true; + exception = null; + exceptionType = results.read_string(); + ok = true; } protected void processSystemException(ReplyHeader_1_2 reply) { - _exceptionType = "???"; - SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(_results); + exceptionType = "???"; + SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(results); String id = replyBody.exception_id; id = StringUtil.removePrefix(id, "IDL:omg.org/CORBA/"); id = StringUtil.removeSuffix(id, ":1.0"); String stackTrace = null; - if (_results.hasMoreData()) { - stackTrace = _results.read_string() + ExceptionUtil.getDivider(); + if (results.hasMoreData()) { + stackTrace = results.read_string() + ExceptionUtil.getDivider(); } - _ok = true; + ok = true; String exceptionClassName = "org.omg.CORBA." + id; try { Class exceptionClass = ThreadContext.loadClass(exceptionClassName); org.omg.CORBA.SystemException corbaException = (org.omg.CORBA.SystemException) exceptionClass.newInstance(); corbaException.minor = replyBody.minor_code_value; corbaException.completed = org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status); - _exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException); + exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException); } catch (Exception ex) { - _exception = new org.apache.geronimo.interop.SystemException(stackTrace, + exception = new org.apache.geronimo.interop.SystemException(stackTrace, new org.omg.CORBA.UNKNOWN(replyBody.exception_id, replyBody.minor_code_value, org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status))); @@ -428,30 +374,28 @@ } public void shutdown() { - if (_socketOut != null) { + if (socketOut != null) { try { - _socketOut.close(); + socketOut.close(); } catch (Exception ignore) { } - _socketOut = null; + socketOut = null; } - if (_socketIn != null) { + if (socketIn != null) { try { - _socketIn.close(); + socketIn.close(); } catch (Exception ignore) { } - _socketIn = null; + socketIn = null; } - if (_socket != null) { + if (socket != null) { try { - _socket.close(); + socket.close(); } catch (Exception ignore) { } - _socket = null; + socket = null; } } - - // log methods protected String errorConnectFailed(String host, int port, Exception ex) { String msg; Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java Wed Mar 23 09:56:34 2005 @@ -27,7 +27,6 @@ import org.apache.geronimo.interop.util.InstancePool; import org.apache.geronimo.interop.util.StringUtil; - public class ConnectionPool { public static ConnectionPool getInstance(ClientNamingContext namingContext) { ConnectionPool object = new ConnectionPool(); @@ -35,17 +34,21 @@ return object; } - // private data - - private ClientNamingContext _namingContext; - - private HashMap _poolMap; - - // public methods + private ClientNamingContext namingContext; + private HashMap poolMap; public Connection get(int protocol, String endpoint, ObjectRef objectRef) { - System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef); + //System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef); + + InstancePool pool = getInstancePool(protocol, endpoint); + System.out.println("ConnectionPool.get(): pool: " + pool); + Connection conn = (Connection) pool.get(); + if (conn == null) { + conn = newConnection(protocol, endpoint, objectRef, pool); + } + return conn; + /* HostList hostList = resolve(endpoint, objectRef); System.out.println("ConnectionPool.get(): hostlist: " + hostList); if (hostList == null) { @@ -87,17 +90,16 @@ // TODO: I18N throw new SystemException("CONNECT FAILED: host list = " + hostList); } + */ } public void put(Connection conn) { conn.getInstancePool().put(conn); } - // protected methods - protected void init(ClientNamingContext namingContext) { - _namingContext = namingContext; - _poolMap = new HashMap(); + this.namingContext = namingContext; + poolMap = new HashMap(); } /** @@ -154,40 +156,14 @@ protected InstancePool getInstancePool(final int protocol, final String endpoint) { System.out.println("ConnectionPool.getInstancePool(): protocol: " + protocol + ", endpoint: " + endpoint); - InstancePool pool = (InstancePool) _poolMap.get(endpoint); + InstancePool pool = (InstancePool) poolMap.get(endpoint); if (pool == null) { - synchronized (_poolMap) { - pool = (InstancePool) _poolMap.get(endpoint); + synchronized (poolMap) { + pool = (InstancePool) poolMap.get(endpoint); if (pool == null) { String poolName = Protocol.getName(protocol) + "://" + endpoint; - //long idleTimeout = 1000 * _namingContext.getIdleConnectionTimeout(); - //if (idleTimeout > 0) - //{ -/* - pool = new InstancePool - ( - poolName, - idleTimeout, - new TimeoutObject() - { - public void onTimeout(Object object) - { - Connection conn = (Connection)object; - if (RmiTrace.CONNECT) - { - RmiTrace.getInstance().traceDisconnect(Protocol.getName(protocol) + "://" + endpoint); - } - conn.shutdown(); - } - } - ); - */ - //} - //else - //{ pool = new InstancePool(poolName); - //} - _poolMap.put(endpoint, pool); + poolMap.put(endpoint, pool); } } } @@ -231,7 +207,10 @@ } protected Connection iiopConnection(String endpoint, ObjectRef objectRef) { - return Connection.getInstance(endpoint, objectRef, _namingContext.getConnectionProperties()); + System.out.println( "endpoint : " + endpoint ); + System.out.println( "objectRef : " + objectRef ); + System.out.println( "namingContext : " + namingContext ); + return Connection.getInstance(endpoint, objectRef, namingContext.getConnectionProperties()); } protected Connection iiopsConnection(String endpoint, ObjectRef objectRef) { @@ -246,14 +225,15 @@ throw new SystemException("TODO"); } + /* protected HostList resolve(String endpoint, ObjectRef objectRef) { -/* - if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService - && ! endpoint.startsWith("ns~mh~")) - { - return null; // Avoid unbounded recursion - } - */ + + //if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService + // && ! endpoint.startsWith("ns~mh~")) + //{ + // return null; // Avoid unbounded recursion + //} + HostList hostList = _namingContext.lookupHost(objectRef.$getHost()); // this uses a cache for good performance if (hostList != null && hostList.getPreferredServers().size() == 0 @@ -264,4 +244,5 @@ } return hostList; } + */ } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java Wed Mar 23 09:56:34 2005 @@ -18,9 +18,8 @@ package org.apache.geronimo.interop.rmi.iiop.client; public class NameBinding { - public Object object; - - public long cacheTimeout; + public Object object; + public long cacheTimeout; public boolean hasExpired() { long timeout = cacheTimeout; Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java Wed Mar 23 09:56:34 2005 @@ -29,7 +29,6 @@ import org.apache.geronimo.interop.util.NamedValueList; import org.apache.geronimo.interop.util.StringUtil; - public class UrlInfo { public static UrlInfo getInstance(String url) { UrlInfo object = new UrlInfo(); @@ -46,94 +45,84 @@ return list; } - // private data - - private int _protocol; - - private String _host; - - private int _port; - - private String _objectKey; - - private PropertyMap _properties; - - // internal methods + private int protocol; + private String host; + private int port; + private String objectKey; + private PropertyMap properties; protected void init(String urlString) { int cssPos = urlString.indexOf("://"); if (cssPos == -1) { throw new IllegalArgumentException(urlString); } - _protocol = Protocol.getNumber(urlString.substring(0, cssPos)); + protocol = Protocol.getNumber(urlString.substring(0, cssPos)); try { URL url = new URL("http" + urlString.substring(cssPos)); - _host = url.getHost(); - _port = url.getPort(); - if (_port == -1) { - switch (_protocol) { + host = url.getHost(); + port = url.getPort(); + if (port == -1) { + switch (protocol) { case Protocol.HTTP: - _port = 80; // see http://www.iana.org/assignments/port-numbers + port = 80; // see http://www.iana.org/assignments/port-numbers break; case Protocol.HTTPS: - _port = 443; // see http://www.iana.org/assignments/port-numbers + port = 443; // see http://www.iana.org/assignments/port-numbers break; case Protocol.IIOP: - _port = 683; // see http://www.iana.org/assignments/port-numbers + port = 683; // see http://www.iana.org/assignments/port-numbers break; case Protocol.IIOPS: - _port = 684; // see http://www.iana.org/assignments/port-numbers + port = 684; // see http://www.iana.org/assignments/port-numbers break; default: throw new IllegalStateException("url = " + urlString); } } - _objectKey = url.getFile(); - if (_objectKey == null) { - _objectKey = ""; + objectKey = url.getFile(); + if (objectKey == null) { + objectKey = ""; } - int queryPos = _objectKey.indexOf('?'); + int queryPos = objectKey.indexOf('?'); if (queryPos != -1) { - _objectKey = _objectKey.substring(0, queryPos); + objectKey = objectKey.substring(0, queryPos); } - _objectKey = StringUtil.removePrefix(_objectKey, "/"); - if (_objectKey.length() == 0) { - _objectKey = "NameService"; + objectKey = StringUtil.removePrefix(objectKey, "/"); + if (objectKey.length() == 0) { + objectKey = "NameService"; } String query = url.getQuery(); if (query == null) { query = ""; } String props = StringUtil.removePrefix(query, "?").replace('&', ','); - _properties = new NamedValueList(props).getProperties(); + properties = new NamedValueList(props).getProperties(); } catch (Exception ex) { throw new SystemException(ex); } } - // public methods - public int getProtocol() { - return _protocol; + return protocol; } public String getHost() { - return _host; + return host; } public int getPort() { - return _port; + return port; } public String getObjectKey() { - return _objectKey; + return objectKey; } public PropertyMap getProperties() { - return _properties; + return properties; } public String toString() { - return Protocol.getName(_protocol) + "://" + _host + ":" + _port + "/" + _objectKey; + return Protocol.getName(protocol) + "://" + host + ":" + port + "/" + objectKey; } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java Wed Mar 23 09:56:34 2005 @@ -18,30 +18,30 @@ package org.apache.geronimo.interop.rmi.iiop.client; public class ValueInfo { - public String _nameToBeResolved = null; - public Object _objectToBeBound = null; + public String nameToBeResolved = null; + public Object objectToBeBound = null; public ValueInfo(String nameToBeResolved) { - _nameToBeResolved = nameToBeResolved; + this.nameToBeResolved = nameToBeResolved; } public ValueInfo(Object objectToBeBound) { - _objectToBeBound = objectToBeBound; + this.objectToBeBound = objectToBeBound; } public void setNameToBeResolved(String name) { - _nameToBeResolved = name; + nameToBeResolved = name; } public String getNameToBeResolved() { - return _nameToBeResolved; + return nameToBeResolved; } public void setObjectToBeBound(Object object) { - _objectToBeBound = object; + objectToBeBound = object; } public Object getObjectToBeBound() { - return _objectToBeBound; + return objectToBeBound; } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/Compiler.java Wed Mar 23 09:56:34 2005 @@ -18,97 +18,74 @@ package org.apache.geronimo.interop.rmi.iiop.compiler; import java.lang.reflect.Method; -import java.util.HashMap; +import java.util.*; +import java.io.File; import org.apache.geronimo.interop.generator.GenOptions; import org.apache.geronimo.interop.generator.JParameter; import org.apache.geronimo.interop.generator.JVariable; - public class Compiler { - protected Class _riClass; - protected GenOptions _genOptions; - protected ClassLoader _cl; - protected boolean _simpleIDL = false; - - protected static HashMap _readMethods; - protected static HashMap _writeMethods; - protected static HashMap _overloadTypes; + protected GenOptions genOptions; - static { - _readMethods = new HashMap(); - _readMethods.put("boolean", "readBoolean"); - _readMethods.put("char", "readChar"); - _readMethods.put("byte", "readByte"); - _readMethods.put("short", "readShort"); - _readMethods.put("int", "readInt"); - _readMethods.put("long", "readLong"); - _readMethods.put("float", "readFloat"); - _readMethods.put("double", "readDouble"); - - _writeMethods = new HashMap(); - _writeMethods.put("boolean", "writeBoolean"); - _writeMethods.put("char", "writeChar"); - _writeMethods.put("byte", "writeByte"); - _writeMethods.put("short", "writeShort"); - _writeMethods.put("int", "writeInt"); - _writeMethods.put("long", "writeLong"); - _writeMethods.put("float", "writeFloat"); - _writeMethods.put("double", "writeDouble"); - - _overloadTypes = new HashMap(); - _overloadTypes.put("boolean", "boolean"); - _overloadTypes.put("byte", "octet"); - _overloadTypes.put("char", "wchar"); - _overloadTypes.put("double", "double"); - _overloadTypes.put("float", "float"); - _overloadTypes.put("int", "long"); - _overloadTypes.put("long", "long_long"); - _overloadTypes.put("short", "short"); - _overloadTypes.put("java.lang.Class", "javax_rmi_CORBA.ClassDesc"); - _overloadTypes.put("java.lang.String", "CORBA.WStringValue"); - _overloadTypes.put("org.omg.CORBA.Object", "Object"); - _overloadTypes.put("org.omg.CORBA.Any", "org_omg_boxedIDL_CORBA.Any"); - _overloadTypes.put("org.omg.CORBA.TypeCode", "org_omg_boxedIDL_CORBA.TypeCode"); - } - - public Compiler(Class remoteInterface) { - this(remoteInterface, null); - } - - public Compiler(Class riClass, GenOptions go) { - _riClass = riClass; - - _cl = _riClass.getClassLoader(); - if (_cl == null) { - _cl = ClassLoader.getSystemClassLoader(); - } - - if (go == null) { - go = new GenOptions(); - } - - _genOptions = go; - } - - // - // Properties - // + private ClassLoader classLoader; + + private static HashMap readMethods; + private static HashMap writeMethods; + private static HashMap overloadTypes; - public boolean isSimpleIDL() { - return _simpleIDL; + static { + readMethods = new HashMap(); + readMethods.put("boolean", "readBoolean"); + readMethods.put("char", "readChar"); + readMethods.put("byte", "readByte"); + readMethods.put("short", "readShort"); + readMethods.put("int", "readInt"); + readMethods.put("long", "readLong"); + readMethods.put("float", "readFloat"); + readMethods.put("double", "readDouble"); + + writeMethods = new HashMap(); + writeMethods.put("boolean", "writeBoolean"); + writeMethods.put("char", "writeChar"); + writeMethods.put("byte", "writeByte"); + writeMethods.put("short", "writeShort"); + writeMethods.put("int", "writeInt"); + writeMethods.put("long", "writeLong"); + writeMethods.put("float", "writeFloat"); + writeMethods.put("double", "writeDouble"); + + overloadTypes = new HashMap(); + overloadTypes.put("boolean", "boolean"); + overloadTypes.put("byte", "octet"); + overloadTypes.put("char", "wchar"); + overloadTypes.put("double", "double"); + overloadTypes.put("float", "float"); + overloadTypes.put("int", "long"); + overloadTypes.put("long", "long_long"); + overloadTypes.put("short", "short"); + overloadTypes.put("java.lang.Class", "javax_rmi_CORBA.ClassDesc"); + overloadTypes.put("java.lang.String", "CORBA.WStringValue"); + overloadTypes.put("org.omg.CORBA.Object", "Object"); + overloadTypes.put("org.omg.CORBA.Any", "org_omg_boxedIDL_CORBA.Any"); + overloadTypes.put("org.omg.CORBA.TypeCode", "org_omg_boxedIDL_CORBA.TypeCode"); } - public void setSimpleIDL(boolean simpleIDL) { - _simpleIDL = simpleIDL; + public Compiler(GenOptions go, ClassLoader cl) { + classLoader = cl; + if (classLoader == null) { + classLoader = ClassLoader.getSystemClassLoader(); + } + + genOptions = go; } public GenOptions getGenOptions() { - return _genOptions; + return genOptions; } - public void setGenOptions(GenOptions genOptions) { - _genOptions = genOptions; + public ClassLoader getClassLoader() { + return classLoader; } public JParameter[] getMethodParms(Method m) { @@ -131,7 +108,7 @@ String rc = null; if (v != null) { - rc = (String) _readMethods.get(v.getTypeDecl()); + rc = (String) readMethods.get(v.getTypeDecl()); } return rc; @@ -141,11 +118,191 @@ String rc = null; if (v != null) { - rc = (String) _writeMethods.get(v.getTypeDecl()); + rc = (String) writeMethods.get(v.getTypeDecl()); } return rc; } + protected static void error( String errMsg ) { + System.err.println( "Error: " + errMsg ); + System.exit(1); + } + + protected void error(String msg, Throwable t) { + error(msg); + t.printStackTrace(); + } + + protected static void warn( String warnMsg ) { + System.out.println( "Warning: " + warnMsg ); + } + + protected String adjustPath( String path ) + { + // Maybe it would be easier if GenOptions just made sure that platform path + // separators and file separators were as required on the platform? + + if (File.separatorChar == '/') { + // We're under Unix, change '\\' to '/' + return path.replace( '\\', '/' ); + } else { + // We're under Windows, change '/' to '\\' + return path.replace( '/', '\\' ); + } + } + + protected void addMethodsToList( ArrayList list, Method[] methods ) + { + for(int i=0; list != null && methods != null && i < methods.length; i++ ) + { + list.add( methods[i] ); + } + } + + protected void collectInterfaceMethods( ArrayList list, Class intfClass, boolean simpleIdl ) + { + Method myMethods[] = intfClass.getDeclaredMethods(); + + if (!simpleIdl) + { + addMethodsToList( list, myMethods ); + } + + Class myInterfaces[] = intfClass.getInterfaces(); + if (myInterfaces != null && myInterfaces.length > 0) + { + String opsName = intfClass.getName() + "Operations"; + + for (int i = 0; i < myInterfaces.length; i++) + { + if (simpleIdl) + { + // add interface and its Operations, only if there is a coresponding Operations + if (myInterfaces[i].getName().equals(opsName)) + { + addMethodsToList( list, myMethods ); + addMethodsToList( list, myInterfaces[i].getDeclaredMethods() ); + continue; + } + else + { + collectInterfaceMethods( list, myInterfaces[i], simpleIdl ); + } + } + else + { + // Collect the interface methods for all interfaces .. + collectInterfaceMethods( list, myInterfaces[i], simpleIdl ); + } + } + } + } + + protected Method[] getMethods( Class intfClass, GenOptions go ) + { + Method myMethods[] = intfClass.getDeclaredMethods(); + ArrayList list = new ArrayList( myMethods.length * 2 ); + + collectInterfaceMethods( list, intfClass, go.isSimpleIdl() ); + + Object[] objs = list.toArray(); + Method[] methods = new Method[objs.length]; + System.arraycopy( objs, 0, methods, 0, objs.length ); + return methods; + } + + public MethodOverload[] getMethodOverloads( Method methods[] ) + { + HashMap hm = new HashMap( methods.length ); + + // Put all the methods into the hashmap + for( int i=0; methods != null && i < methods.length; i++ ) + { + ArrayList al = (ArrayList)hm.get( methods[i].getName() ); + if (al == null) + { + al = new ArrayList( methods.length ); + al.add( methods[i] ); + hm.put( methods[i].getName(), al ); + } + else + { + al.add( methods[i] ); + } + } + + Set keySet = hm.keySet(); + ArrayList overloadList = new ArrayList( methods.length ); + for (Iterator keyIt = keySet.iterator(); keyIt != null && keyIt.hasNext(); ) + { + ArrayList al = (ArrayList)hm.get( keyIt.next() ); + if (al.size() == 1) + { + Method m = (Method)al.remove(0); + overloadList.add( new MethodOverload( m.getName(), m ) ); + } + else + { + for( int i=0; i<=al.size(); i++ ) + { + Method m = (Method)al.remove(0); + overloadList.add( new MethodOverload( overloadMethodName(m), m ) ); + } + } + } + + Object obj[] = overloadList.toArray(); + MethodOverload m[] = new MethodOverload[ obj.length ]; + System.arraycopy( obj, 0, m, 0, obj.length ); + + return m; + } + + protected String overloadMethodName( Method m ) + { + Class parms[] = m.getParameterTypes(); + String name = m.getName() + "_"; + for( int i=0; i<parms.length; i++ ) + { + name += "_" + parms[i].getName(); + } + return name.replace( '.', '_' ); + } + + class MethodOverload + { + public Method method; + public String iiop_name; + + public MethodOverload( String iiop_name, Method method ) + { + this.method = method; + this.iiop_name = iiop_name; + } + + public int hashCode() + { + return iiop_name.hashCode(); + } + + public boolean equals( Object other ) + { + if (other instanceof MethodOverload) + { + MethodOverload mother = (MethodOverload)other; + if (iiop_name != null) + { + return iiop_name.equals( mother.iiop_name ); + } + else + { + return iiop_name == mother.iiop_name; + } + } + + return false; + } + } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelCompiler.java Wed Mar 23 09:56:34 2005 @@ -19,55 +19,45 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.io.File; +import java.util.*; -import org.apache.geronimo.interop.generator.GenOptions; -import org.apache.geronimo.interop.generator.JCaseStatement; -import org.apache.geronimo.interop.generator.JCatchStatement; -import org.apache.geronimo.interop.generator.JClass; -import org.apache.geronimo.interop.generator.JCodeStatement; -import org.apache.geronimo.interop.generator.JConstructor; -import org.apache.geronimo.interop.generator.JDeclareStatement; -import org.apache.geronimo.interop.generator.JExpression; -import org.apache.geronimo.interop.generator.JField; -import org.apache.geronimo.interop.generator.JLocalVariable; -import org.apache.geronimo.interop.generator.JMethod; -import org.apache.geronimo.interop.generator.JPackage; -import org.apache.geronimo.interop.generator.JParameter; -import org.apache.geronimo.interop.generator.JReturnType; -import org.apache.geronimo.interop.generator.JSwitchStatement; -import org.apache.geronimo.interop.generator.JTryCatchFinallyStatement; -import org.apache.geronimo.interop.generator.JTryStatement; -import org.apache.geronimo.interop.generator.JVariable; -import org.apache.geronimo.interop.generator.JavaGenerator; - - -public class SkelCompiler - extends Compiler { - protected ValueTypeContext _vtc = new ValueTypeContext(); - protected static JParameter _objInputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.class, "input"); - protected static JParameter _objOutputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.class, "output"); - - public SkelCompiler(Class remoteInterface) { - super(remoteInterface); - } - - public SkelCompiler(Class remoteInterface, GenOptions go) { - super(remoteInterface, go); - } - - // - // Methods - // +import org.apache.geronimo.interop.generator.*; +import org.apache.geronimo.interop.util.JavaClass; +import org.apache.geronimo.interop.util.ProcessUtil; +import org.apache.geronimo.interop.adapter.Adapter; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class SkelCompiler extends Compiler { + private final Log log = LogFactory.getLog(SkelCompiler.class); + + private ValueTypeContext vtc = new ValueTypeContext(); + + private static JParameter objInputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.class, "input"); + private static JParameter objOutputVar = new JParameter(org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.class, "output"); + + private String inStreamName = "getInputStream"; + private String outStreamName = "getOutputStream"; + + private HashMap packages = new HashMap(); + + public SkelCompiler(GenOptions go, ClassLoader cl) { + super(go, cl); + } public void addMethodGetIds(JClass jc) { - /* - public String[] getIds() - { - return _ids; - } - */ + // + // Method Template: + // + // public String[] getIds() + // { + // return _ids; + // } + // - JMethod jm = jc.newMethod(new JReturnType(String.class, true), + JMethod jm = jc.newMethod(new JReturnType(String[].class), "getIds", (JParameter[]) null, (Class[]) null); @@ -76,12 +66,14 @@ } public void addMethodRegisterMethod(JClass jc) { - /* - public void registerMethod( String name, int id ) - { - _methodMap.put( name, new Integer(id) ); - } - */ + // + // Method Template: + // + // public void registerMethod( String name, int id ) + // { + // _methodMap.put( name, new Integer(id) ); + // } + // JMethod jm = jc.newMethod(new JReturnType(void.class), "registerMethod", @@ -93,18 +85,20 @@ } public void addMethodGetObjectRef(JClass jc, Class c) { - /* - public ObjectRef $getObjectRef() - { - ObjectRef or = new ObjectRef(); - or.$setID("RMI:mark.comps.Add:0000000000000000"); - or.$setObjectKey( "mark.comps.Add" ); - return or; - } - */ + // + // Method Template: + // + // public ObjectRef getObjectRef() + // { + // ObjectRef or = new ObjectRef(); + // or.$setID("RMI:mark.comps.Add:0000000000000000"); + // or.$setObjectKey( "mark.comps.Add" ); + // return or; + // } + // - JMethod jm = jc.newMethod(new JReturnType("ObjectRef"), - "$getObjectRef", + JMethod jm = jc.newMethod(new JReturnType(org.apache.geronimo.interop.rmi.iiop.ObjectRef.class), + "getObjectRef", (JParameter[]) null, (Class[]) null); @@ -115,14 +109,16 @@ } public void addMethodGetSkeleton(JClass jc) { - /* - public RemoteInterface $getSkeleton() - { - return this; - } - */ + // + // Method Template + // + // public RemoteInterface $getSkeleton() + // { + // return this; + // } + // - JMethod jm = jc.newMethod(new JReturnType("RemoteInterface"), + JMethod jm = jc.newMethod(new JReturnType(org.apache.geronimo.interop.rmi.iiop.RemoteInterface.class), "$getSkeleton", (JParameter[]) null, (Class[]) null); @@ -143,17 +139,20 @@ return rc; } - public void addMethod(Method m, JClass jc) { + public void addMethod(MethodOverload mo, JClass jc, GenOptions go) { String invokeCall; + Method m = mo.method; String name = m.getName(); JParameter[] sparms = getMethodParms(m); - JParameter[] iparms = new JParameter[]{_objInputVar, _objOutputVar}; + JParameter[] iparms = new JParameter[]{objInputVar, objOutputVar}; + String vtVarName = null; + JCodeStatement codeStmt = null; - if (!isSimpleIDL() && !throwsAnRMIRemoteException(m)) { + if (!go.isSimpleIdl() && !throwsAnRMIRemoteException(m)) { error("Method " + m.getName() + " does not throw java.rmi.RemoteException or subclass, unable to generate its skeleton method."); } - JMethod jm = jc.newMethod(new JReturnType(void.class), name, iparms, null); + JMethod jm = jc.newMethod(new JReturnType(void.class), mo.iiop_name, iparms, null); JVariable jrc = null; String rc = m.getReturnType().getName(); @@ -161,8 +160,8 @@ jrc = jm.newLocalVariable(m.getReturnType(), "rc"); } - JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement(); - JTryStatement ts = tcfs.getTryStatement(); + ArrayList declareStatementList = new ArrayList( 20 ); + JStatement invokeStatement = null; invokeCall = "_servant." + name + "("; @@ -178,7 +177,7 @@ jcs = new JCodeStatement("input." + readMethod + "()"); } else { - String vtVarName = _vtc.getValueTypeVarName(jc, sparms[i]); + vtVarName = vtc.getValueTypeVarName(jc, sparms[i]); if (vtVarName != null) { jcs = new JCodeStatement("(" + sparms[i].getTypeDecl() + ") input.readObject( " + vtVarName + " )"); } else { @@ -186,7 +185,7 @@ } } - ts.addStatement(new JDeclareStatement(sparms[i], new JExpression(jcs))); + declareStatementList.add(new JDeclareStatement(sparms[i], new JExpression(jcs))); invokeCall += " " + sparms[i].getName(); if (i + 1 < sparms.length) { @@ -203,37 +202,118 @@ invokeCall = invokeCall + ";"; - ts.addStatement(new JCodeStatement(invokeCall)); - - JVariable jv = new JVariable(java.lang.Exception.class, "ex"); - JCatchStatement cs = tcfs.newCatch(jv); - cs.addStatement(new JCodeStatement(jv.getName() + ".printStackTrace();")); - - jv = new JVariable(java.lang.Error.class, "er"); - cs = tcfs.newCatch(jv); - cs.addStatement(new JCodeStatement(jv.getName() + ".printStackTrace();")); - - jm.addStatement(tcfs); + invokeStatement = new JCodeStatement(invokeCall); + JStatement writeResultStatement = null; if (jrc != null) { String writeMethod = getWriteMethod(jrc); - JCodeStatement jcs = null; + codeStmt = null; if (writeMethod != null) { // Primitive Type // Cast not needed since each method returns the primitive datatype. - jcs = new JCodeStatement("output." + writeMethod + "( " + jrc.getName() + " );"); + codeStmt = new JCodeStatement("output." + writeMethod + "( " + jrc.getName() + " );"); } else { - String vtVarName = _vtc.getValueTypeVarName(jc, jrc); + vtVarName = vtc.getValueTypeVarName(jc, jrc); + if (vtVarName != null) { + codeStmt = new JCodeStatement("output.writeObject( " + vtVarName + ", " + jrc.getName() + " );"); + } else { + codeStmt = new JCodeStatement("// Code Gen Error: Class '" + jrc.getTypeDecl() + " is not a valid value type."); + } + } + + writeResultStatement = codeStmt; + } + + // + // The exception handling block: + // + // try + // { + // invoke method() + // } + // catch (java.lang.Exception $ex_1) + // { + // Listed here are the individual catches that the method can throw + // if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.NotFound) + // { + // $output.writeException(type$4, $ex_1); + // return; + // } + // if ($ex_1 instanceof com.sybase.djc.org.omg.CosNaming.NamingContextPackage.CannotProceed) + // { + // $output.writeException(type$5, $ex_1); + // return; + // } + // throw $ex_1; + // } + + Class[] excepts = m.getExceptionTypes(); + JVariable jvExcept = null; + JVariable jvTmp = null; + + JCatchStatement catchStmt = null; + + if (excepts != null && excepts.length > 0) + { + JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement(); + JTryStatement ts = tcfs.getTryStatement(); + + if (declareStatementList.size() > 0) + { + for( int i=0; i<declareStatementList.size(); i++ ) + { + ts.addStatement( (JStatement)declareStatementList.get(i) ); + } + } + + ts.addStatement( invokeStatement ); + + jvExcept = new JVariable(java.lang.Exception.class, "ex"); + catchStmt = tcfs.newCatch(jvExcept); + + for( int i=0; excepts != null && i < excepts.length; i++ ) + { + jvTmp = new JVariable( excepts[i], "exvar" ); + vtVarName = vtc.getValueTypeVarName(jc, jvTmp); + codeStmt = null; if (vtVarName != null) { - jcs = new JCodeStatement("output.writeObject( " + vtVarName + ", " + jrc.getName() + " );"); + codeStmt = new JCodeStatement("output.writeException( " + vtVarName + ", " + jvExcept.getName() + ");" ); } else { - jcs = new JCodeStatement("// Code Gen Error: Class '" + jrc.getTypeDecl() + " is not a valid value type."); + codeStmt = new JCodeStatement("// Code Gen Error: Class '" + sparms[i].getTypeDecl() + " is not a valid value type."); + } + + JIfStatement ifs = new JIfStatement( new JExpression( + new JCodeStatement( jvExcept.getName() + " instanceof " + excepts[i].getName() ) )); + ifs.addStatement( codeStmt ); + ifs.addStatement( new JCodeStatement( "return;" )); + catchStmt.addStatement( ifs ); + } + + if (writeResultStatement != null) + { + ts.addStatement( writeResultStatement ); + } + + jm.addStatement(tcfs); + } + else + { + if (declareStatementList.size() > 0) + { + for( int i=0; i<declareStatementList.size(); i++ ) + { + jm.addStatement( (JStatement)declareStatementList.get(i) ); } } - ts.addStatement(jcs); + jm.addStatement( invokeStatement ); + + if (writeResultStatement != null) + { + jm.addStatement( writeResultStatement ); + } } } @@ -288,132 +368,203 @@ return rc; } - protected void error(String msg) { - System.out.println("Error: " + msg); - } - - protected void error(String msg, Throwable t) { - error(msg); - t.printStackTrace(); - } + public void generate() throws GenException { - public void generate() - throws Exception { - _vtc.clear(); + GenOptions go = getGenOptions(); + List interfaces = go.getInterfaces(); + Iterator intf = null; - if (!isSimpleIDL() && !isClassARMIRemote(_riClass)) { - error("Class '" + _riClass.getName() + "' must be an instance of either java.rmi.Remote or of a subclass."); + if (interfaces != null) { + intf = interfaces.iterator(); } - ClassLoader cl = _riClass.getClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); + JavaGenerator jg = new JavaGenerator(genOptions); + + if (go.isSimpleIdl()) { + inStreamName = "getSimpleInputStream"; + outStreamName = "getSimpleOutputStream"; + } else { + inStreamName = "getInputStream"; + outStreamName = "getOutputStream"; } - String fullGenDir = _genOptions.getGenDir(); + String riClassName = ""; + Class riClass = null; + String skelClassName = ""; + String pkgName = ""; + JPackage pkg = null; - JavaGenerator jg = new JavaGenerator(_genOptions); + while (intf != null && intf.hasNext() ) { + // Clear the value type cache. + vtc.clear(); - String className = _riClass.getName(); + riClassName = (String)intf.next(); - JPackage p = new JPackage(""); - if (_riClass.getPackage() != null) { - p = new JPackage(_riClass.getPackage().getName()); - className = className.substring(className.lastIndexOf(".") + 1); - } - JClass jc = p.newClass(className + "_Skeleton"); + try { + riClass = getClassLoader().loadClass( riClassName ); + } catch (Exception ex) { + throw new GenException( "Generate Skels Failed:", ex ); + } - /* - jw.comment( "" ); - jw.comment( "CORBA RMI-IIOP Skeleton Generator" ); - jw.comment( " Interface: " + c.getName() ); - jw.comment( " Date: " + (new Date(System.currentTimeMillis())).toString() ); - jw.comment( "" ); - */ - - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectInputStream"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectOutputStream"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteObject"); - jc.addImport("org.apache.geronimo.interop.rmi.iiop.server", "Adapter"); - jc.addImport("java.util", "HashMap"); - - jc.setExtends("RemoteObject"); - jc.addImplements("RemoteInterface"); - - JField idsField = jc.newField(String[].class, "_ids", new JExpression(new JCodeStatement("{ \"" + _riClass.getName() + "\", \"RMI:" + _riClass.getName() + ":0000000000000000\"}")), true); - JField methodsField = jc.newField(java.util.HashMap.class, "_methods", new JExpression(new JCodeStatement("new HashMap(10)"))); - JField servantField = jc.newField(_riClass, "_servant", new JExpression(new JCodeStatement("null"))); - - JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null); - jcCon.addStatement(new JCodeStatement("super();")); - - addMethodRegisterMethod(jc); - addMethodGetIds(jc); - addMethodGetSkeleton(jc); - addMethodGetObjectRef(jc, _riClass); - - JMethod jmInvoke = jc.newMethod(new JReturnType(void.class), - "$invoke", - new JParameter[]{new JParameter(String.class, "methodName"), - new JParameter(byte[].class, "objectKey"), - new JParameter(Object.class, "instance"), - _objInputVar, - _objOutputVar}, - (Class[]) null); - - jmInvoke.setModifier(Modifier.PUBLIC, true); - - JLocalVariable jvM = jmInvoke.newLocalVariable(Integer.class, "m", new JExpression(new JCodeStatement("(Integer)_methods.get(methodName)"))); - - jmInvoke.addStatement(new JCodeStatement("if (m == null)")); - jmInvoke.addStatement(new JCodeStatement("{")); - jmInvoke.addStatement(new JCodeStatement(" throw new org.omg.CORBA.BAD_OPERATION(methodName);")); - jmInvoke.addStatement(new JCodeStatement("}")); - jmInvoke.addStatement(new JCodeStatement("")); - jmInvoke.addStatement(new JCodeStatement("_servant = (" + _riClass.getName() + ")instance;")); - jmInvoke.addStatement(new JCodeStatement("")); - jmInvoke.addStatement(new JCodeStatement("if (m.intValue() < 0)")); - jmInvoke.addStatement(new JCodeStatement("{")); - jmInvoke.addStatement(new JCodeStatement(" super.invoke( m.intValue(), objectKey, instance, input, output );")); - jmInvoke.addStatement(new JCodeStatement("}")); - jmInvoke.addStatement(new JCodeStatement("")); - - JSwitchStatement ss = new JSwitchStatement(new JExpression(new JCodeStatement("m.intValue()"))); - JCaseStatement cs = null; - jmInvoke.addStatement(ss); + if (!go.isSimpleIdl() && !isClassARMIRemote(riClass)) { + error("Class '" + riClass.getName() + "' must be an instance of either java.rmi.Remote or of a subclass."); + } - Method m[] = null; + pkgName = JavaClass.getNamePrefix(riClassName); + skelClassName = JavaClass.getNameSuffix(riClassName); + pkg = (JPackage) packages.get( pkgName ); + if (pkg == null) + { + pkg = new JPackage( pkgName ); + packages.put( pkgName, pkg ); + } - if (isSimpleIDL()) { - m = _riClass.getMethods(); - } else { - m = _riClass.getDeclaredMethods(); - } + JClass jc = pkg.newClass(skelClassName + "_Skeleton"); - if (m != null && m.length > 0) { - int i; - for (i = 0; i < m.length; i++) { + jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteInterface"); + jc.addImport("org.apache.geronimo.interop.rmi.iiop", "ObjectRef"); + jc.addImport("org.apache.geronimo.interop.rmi.iiop", "RemoteObject"); + + jc.setExtends("RemoteObject"); + jc.addImplements("RemoteInterface"); + + JField idsField = jc.newField(String[].class, "_ids", new JExpression(new JCodeStatement("{ \"" + riClass.getName() + "\", \"RMI:" + riClass.getName() + ":0000000000000000\"}")), true); + idsField.setModifiers(Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL); + + JField servantField = jc.newField(riClass, "_servant", new JExpression(new JCodeStatement("null"))); + servantField.setModifiers(Modifier.PRIVATE); + + JConstructor jcCon = jc.newConstructor((JParameter[]) null, (Class[]) null); + jcCon.addStatement(new JCodeStatement("super();")); + + // Replaced with the method in the RemoteObject parent class + //addMethodRegisterMethod(jc); + + addMethodGetIds(jc); + + // Not used anymore + //addMethodGetSkeleton(jc); + + addMethodGetObjectRef(jc, riClass); + + JMethod jmInvoke = jc.newMethod(new JReturnType(void.class), + "invoke", + new JParameter[]{new JParameter(String.class, "methodName"), + new JParameter(byte[].class, "objectKey"), + new JParameter(Adapter.class, "adapter"), + objInputVar, + objOutputVar}, + (Class[]) null); + + jmInvoke.setModifier(Modifier.PUBLIC); + + JLocalVariable jvM = jmInvoke.newLocalVariable(Integer.class, "m", new JExpression(new JCodeStatement("getMethodId(methodName); // (Integer)_methods.get(methodName)"))); + + JIfStatement jis = new JIfStatement(new JExpression(new JCodeStatement(jvM.getName() + " == null"))); + jis.addStatement(new JCodeStatement("throw new org.omg.CORBA.BAD_OPERATION(methodName);")); + jmInvoke.addStatement(jis); + + jmInvoke.addStatement(new JCodeStatement("_servant = (" + riClass.getName() + ")adapter.getServant(); //instance;")); + + JIfStatement jis2 = new JIfStatement(new JExpression(new JCodeStatement(jvM.getName() + ".intValue() < 0"))); + jis2.addStatement(new JCodeStatement("super.invoke( " + jvM.getName() + ".intValue(), objectKey, adapter, input, output );")); + jmInvoke.addStatement(jis2); + + JTryCatchFinallyStatement tcfs = new JTryCatchFinallyStatement(); + JTryStatement ts = tcfs.getTryStatement(); + + JSwitchStatement switchStmt = new JSwitchStatement(new JExpression(new JCodeStatement("m.intValue()"))); + JCaseStatement caseStmt = null; + ts.addStatement(switchStmt); + + Method m[] = getMethods( riClass, go ); + MethodOverload mo[] = null; + mo = getMethodOverloads( m ); + + for (int i = 0; mo != null && i < mo.length; i++) + { // Enter a new method id in the _methods hashtable. - jcCon.addStatement(new JCodeStatement("registerMethod( \"" + m[i].getName() + "\", " + i + ");")); + jcCon.addStatement(new JCodeStatement("registerMethod( \"" + mo[i].iiop_name + "\", " + i + ");")); // Add a new case statement to the invoke swtich - cs = ss.newCase(new JExpression(new JCodeStatement("" + i))); - cs.addStatement(new JCodeStatement(m[i].getName() + "(input,output);")); + caseStmt = switchStmt.newCase(new JExpression(new JCodeStatement("" + i))); + caseStmt.addStatement(new JCodeStatement(mo[i].iiop_name + "(input,output);")); // Generate the method wrapper - addMethod(m[i], jc); + addMethod(mo[i], jc, go); } + + JCatchStatement catchStmt = null; + JVariable jvExcept = null; + + jvExcept = new JVariable(java.lang.Error.class, "erEx"); + catchStmt = tcfs.newCatch(jvExcept); + catchStmt.addStatement(new JCodeStatement( "throw new org.apache.geronimo.interop.SystemException( " + jvExcept.getName() + " );" ) ); + + jvExcept = new JVariable(java.lang.RuntimeException.class, "rtEx"); + catchStmt = tcfs.newCatch(jvExcept); + catchStmt.addStatement(new JCodeStatement( "throw " + jvExcept.getName() + ";" ) ); + + jvExcept = new JVariable(java.lang.Exception.class, "exEx"); + catchStmt = tcfs.newCatch(jvExcept); + catchStmt.addStatement(new JCodeStatement( "throw new org.apache.geronimo.interop.SystemException( " + jvExcept.getName() + " );" ) ); + + jmInvoke.addStatement( tcfs ); } - jg.generate(p); + Set pkgSet = packages.keySet(); + Iterator pkgIt = pkgSet.iterator(); + String skelPkg = ""; + + while (pkgIt.hasNext()) + { + skelPkg = (String) pkgIt.next(); + pkg = (JPackage)packages.get(skelPkg); + System.out.println("Generating Package: " + skelPkg); + jg.generate(pkg); + } } public void compile() throws Exception { + + Set pkg = packages.keySet(); + Iterator pkgIt = pkg.iterator(); + String skelPkg = ""; + + /* + * Each of the packages were generated under go.getGenSrcDir(). + * + * Go through all the packages and run the compiler on *.java + */ + + GenOptions go = getGenOptions(); + String classpath = adjustPath(go.getClasspath()); + String srcpath = adjustPath(go.getGenSrcDir()); + + String filesToCompile = ""; + String javacCmd = ""; + + while (pkgIt.hasNext()) + { + skelPkg = (String) pkgIt.next(); + skelPkg = skelPkg.replace( '.', File.separatorChar ); + filesToCompile = adjustPath(go.getGenSrcDir() + File.separator + skelPkg + File.separator + "*.java"); + + System.out.println("Compiling Package: " + filesToCompile); + + javacCmd = "javac -d " + go.getGenClassDir() + + ( go.isCompileDebug() ? " -g" : "" ) + + " -classpath " + classpath + " " + + " -sourcepath " + srcpath + " " + filesToCompile; + + System.out.println( "Lauching: " + javacCmd ); + + ProcessUtil pu = ProcessUtil.getInstance(); + pu.setEcho(System.out); + pu.run(javacCmd, (String[]) null, "./" ); + } } public Class getSkelClass() { @@ -429,62 +580,27 @@ return c; } - public static void main(String args[]) - throws Exception { - boolean generate = false; - boolean compile = false; - boolean simpleIDL = false; - String ri = ""; - GenOptions go = new GenOptions(); - - go.setGenDir("./src"); - go.setOverwrite(false); - go.setVerbose(false); - - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-g")) { - generate = true; - } else if (args[i].equals("-c")) { - compile = true; - } else if (args[i].equals("-d") && ((i + 1) < args.length)) { - go.setGenDir(args[++i]); - } else if (args[i].equals("-v")) { - go.setVerbose(true); - } else if (args[i].equals("-o")) { - go.setOverwrite(true); - } else if (args[i].equals("-s")) { - simpleIDL = true; - } else if (args[i].startsWith("-")) { - System.out.println("Warning: Ignoring unrecognized options: '" + args[i] + "'"); - } else { - ri = args[i]; - } - } - - Class riClass = Class.forName(ri); - - SkelCompiler sg = new SkelCompiler(riClass, go); + public static void main(String args[]) throws Exception { + GenOptions go = null; - sg.setSimpleIDL(simpleIDL); + try + { + go = new GenOptions( "./skels", args ); + } + catch( GenWarning gw ) + { + gw.printStackTrace(); + } - if (generate) { - if (go.isVerbose()) { - System.out.println("Generating: " + ri); - } + ClassLoader cl = ClassLoader.getSystemClassLoader(); + SkelCompiler sg = new SkelCompiler( go, cl ); + if (go.isGenerate()) { sg.generate(); } - if (compile) { - if (go.isVerbose()) { - System.out.println("Compiling: " + ri); - } - + if (go.isCompile()) { sg.compile(); } - - // sg.setSimpleIDL( true ); - // sg.generate( "org.apache.geronimo.interop.rmi.iiop.NameServiceOperations"); } } - Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java?view=diff&r1=158813&r2=158814 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/compiler/SkelFactory.java Wed Mar 23 09:56:34 2005 @@ -23,56 +23,27 @@ import org.apache.geronimo.interop.rmi.iiop.RemoteObject; import org.apache.geronimo.interop.util.ThreadContext; - public class SkelFactory { - protected static SkelFactory _sf = new SkelFactory(); + private static SkelFactory sf = new SkelFactory(); protected SkelFactory() { } public static SkelFactory getInstance() { - return _sf; + return sf; } - // private data - - private static HashMap _skelClassMap; - - // internal methods + private static HashMap skelClassMap; protected void init() { - _skelClassMap = new HashMap(); + skelClassMap = new HashMap(); } + /* protected Class loadStub(Class remoteInterface) { String className = remoteInterface.getName(); String skelClassName = className + "_Skeleton"; - /* - StubClass sc = new StubClass(); - if (sc.skelClass == null) - { - // Try generating skel class now. - System.out.println( "TODO: StubFactory.loadStub(): className = " + className ); - StubCompiler skelCompiler = StubCompiler.getInstance(remoteInterface); - sc.skelClass = skelCompiler.getStubClass(); - } - - if (sc.skelClass != null) - { - try - { - sc.getInstance = sc.skelClass.getMethod("$getInstance", ArrayUtil.EMPTY_CLASS_ARRAY); - } - catch (Exception ex) - { - throw new SystemException(ex); - } - } - - return sc; - */ - Class sc = null; try { sc = Class.forName(skelClassName); @@ -84,19 +55,19 @@ return sc; } + */ - // public methods - + /* public RemoteObject getSkel(Class remoteInterface) { System.out.println("SkelFactory.getSkel(): remoteInterface: " + remoteInterface); try { - Class sc = (Class) _skelClassMap.get(remoteInterface); + Class sc = (Class) skelClassMap.get(remoteInterface); if (sc == null) { - synchronized (_skelClassMap) { - sc = (Class) _skelClassMap.get(remoteInterface); + synchronized (skelClassMap) { + sc = (Class) skelClassMap.get(remoteInterface); if (sc == null) { sc = loadStub(remoteInterface); - _skelClassMap.put(remoteInterface, sc); + skelClassMap.put(remoteInterface, sc); } } } @@ -106,8 +77,11 @@ throw new SystemException(ex); } } + */ + /* public Object getSkel(String remoteInterface) { return getSkel(ThreadContext.loadClass(remoteInterface)); } + */ }