| import oracle.oas.jco.*; import oracle.oas.jndi.*; import oracle.oas.jndi.oas.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.util.Hashtable; import javax.naming.*; import myStack.ServerStackRemote; public class StackClient { public static void main(String args[]) { int stackSize; String buf, stackElement; int n = 0; String _host = "localhost"; ServerStackRemote s = null; try { String _urlStr = args[0]; if (_urlStr != null) { URL _contactURL = new URL(_urlStr); _host = _contactURL.getHost(); int _port = _contactURL.getPort(); if (_port != -1) _host = _host + ":" + String.valueOf(_port); } Hashtable _env = new Hashtable(); _env.put(Context.URL_PKG_PREFIXES, "oracle.oas.jndi"); // Initial Context Context _initialContext = new InitialContext(_env); // Lookup String _name = "oas://" + _host + "/myStack/ServerStack"; s = (ServerStackRemote) _initialContext.lookup(_name); System.out.println(); System.out.print("Enter server stack size: "); BufferedReader d = new BufferedReader( new InputStreamReader(System.in)); buf = d.readLine(); stackSize = Integer.parseInt(buf); s.setStackSize(stackSize); System.out.println("---> Server stack size is currently " + s.getStackSize()); for(n = 0;;n++) { System.out.print("Enter stack element (RET to quit): "); stackElement = d.readLine(); if (stackElement.length() == 0) break; s.push(stackElement); } System.out.println("---> Server stack currently has the following " + n + " elements:"); System.out.println(); for (int i = n-1; i >= 0; i--) System.out.println(" " + s.pop()); } // end try catch (myStack.StackException se) { System.out.println("Stack exception occurred."); System.out.println(se); } catch (java.io.IOException ioe) { System.out.println("The following error occurred while trying to read input."); System.out.println(ioe); } catch (NamingException ne) { System.out.print("Communication error: "); System.out.println(ne.getMessage()); ne.printStackTrace(); } finally { if (s != null) s.destroy(); // from JCORemote } System.exit(0); } } |
关注此文的读者还看过: