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

📄 proxyhandler.java

📁 该HttpProxy用于从Applet或Swing界面中访问Ejb和服务端的JavaBean。
💻 JAVA
字号:
/**
 * @作者: 胡俊
 * @创建时间: 2008-03-05
 * @更新时间: 2008-03-05
 * @描述: 
 * 
 */
package com.nari.pmos.proxy.client;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import com.nari.pmos.proxy.common.ApplicationException;
import com.nari.pmos.proxy.common.EjbInvoke;
import com.nari.pmos.proxy.common.InvokeEnv;



/**
 * @author hujun
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ProxyHandler implements InvocationHandler {

	private String usrAccount = "";

	private String usrPwd = "";

	private InvokeEnv invokeEnv = null;

	private EjbInvoke ejbInvoke = null;

	private Class classInterface = null;

	/**
	 * 
	 */
	public ProxyHandler(Class classInterface, InvokeEnv invokeEnv,
			String usrAccount, String usrPwd) {
		super();
		// TODO Auto-generated constructor stub
		this.usrAccount = usrAccount;
		this.usrPwd = usrPwd;
		this.invokeEnv = invokeEnv;
		this.classInterface = classInterface;
	}

	public void setUsrAccount(String usrAccount) {
		this.usrAccount = usrAccount;
	}

	public void setUsrPwd(String usrPwd) {
		this.usrPwd = usrPwd;
	}

	public void setInvokeEnv(InvokeEnv invokeEnv) {
		this.invokeEnv = invokeEnv;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
	 *      java.lang.reflect.Method, java.lang.Object[])
	 */
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		// TODO Auto-generated method stub
		String interfaceName = classInterface.getName(); // 被调用的EJB对应的JNDI名称
		String methodName = method.getName(); // 被调用的EJB对应的方法名
		Object r = null;
		Class[] Classes = method.getParameterTypes();
		String[] Classes_type = new String[Classes.length];
		// === 因jboss323无法正确转换 int double,所以作如下处理 ===
		int N = Classes.length;
		int I = 0;
		for (I = 0; I < N; I++) {
			Classes_type[I] = "";
			if (Classes[I].getName().equals("int")) {
				Classes[I] = Integer.class;
				Classes_type[I] = "int";
			} else if (Classes[I].getName().equals("double")) {
				Classes[I] = Double.class;
				Classes_type[I] = "double";
			}
			if (Classes[I].getName().equals("boolean")) {
				Classes[I] = Boolean.class;
				Classes_type[I] = "boolean";
			}
		}
		// ===========================================================
		try {
			// 采用local方式
			if (ejbInvoke == null) {
				ejbInvoke = new EjbInvoke();
				ejbInvoke.setInvokeEnv(invokeEnv);
			}
			r = ejbInvoke.executeLocalMethod(usrAccount, usrPwd, interfaceName,
					methodName, Classes, args, Classes_type);
		} catch (ApplicationException ae) {
			System.out.println("--- EjbProxy ApplicationException : " + ae
					+ " ---");
			ae.printStackTrace();
		} catch (Exception e) {
			System.out.println("--- EjbProxy Exception : " + e + " ---");
			e.printStackTrace();
		}
		return r;
	}

}

⌨️ 快捷键说明

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