⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessioncmpclient.java

📁 使用J2EE编写的网上商店系统
💻 JAVA
字号:
/*
 * Created on 1999-5-18
 */
package testClient;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import cmp.ItemData;
import cmp.SupplierData;

import bmp.CustomerData;
import bmp.ManagerData;

/**
 * @author 28-9
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class SessionCMPClient {
	private stateless.StoreAccessHome getHome() throws NamingException {
		return (stateless.StoreAccessHome) getContext().lookup(
				stateless.StoreAccessHome.JNDI_NAME);
	}
	private InitialContext getContext() throws NamingException {
		Hashtable props = new Hashtable();
		props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
		// This establishes the security for authorization/authentication
		// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
		// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
		InitialContext initialContext = new InitialContext(props);
		return initialContext;
	}
	public void testBean() {
		Iterator itemsIterator=null;
		ArrayList items=null;
		try {
			stateless.StoreAccess myBean = getHome().create();
			//--------------------------------------
			//This is the place you make your calls.
			//System.out.println(myBean.callYourMethod());
			System.out.println("Request from client : ");
			String userID = myBean.loginUser("danny", "swdandy");
			System.out.println("Reply from Server: Your userid is " + userID );
			CustomerData cd = myBean.getCustomerData(userID); 
			System.out.println ("Andy your details with MyStore are " + cd );
		

			String suppID =   myBean.loginUser("TUSX","PASSWD");
			System.out.println("Reply from Server: Your supplierID is " + suppID );			
			SupplierData sd = myBean.getSupplierData(suppID);
			System.out.println ("TUSX your details with MyStore are  " + sd );			
			
			String mgrID =   myBean.loginUser("RUSTY","PASSWD");
			System.out.println("Reply from Server: Your mgrid is " + mgrID );
			ManagerData md = myBean.getManagerData(mgrID);			
			System.out.println ("Rusty your details with MyStore are  " + md );			
			System.out.println("Manager Request : List items out of stock ");
						
			items = myBean.getOutOfStockItems();
			itemsIterator = items.iterator();
			System.out.println("List Of Out Of stock Items ");			
			while ( itemsIterator.hasNext() ) {			
				ItemData itemData= ( ItemData ) itemsIterator.next();
				System.out.println ("Item Data " + itemData );
			}				
			
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (CreateException e) {
			e.printStackTrace();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		SessionCMPClient test = new SessionCMPClient();
		test.testBean();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -