📄 ejbmethodinvoker.java
字号:
/**
* Copyright 2005 Jdon.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jdon.bussinessproxy.method;
import com.jdon.bussinessproxy.meta.EJBTargetMetaDef;
import com.jdon.bussinessproxy.MethodInvoker;
import com.jdon.bussinessproxy.TargetService;
import com.jdon.bussinessproxy.cache.ComponentCacheVisitor;
import com.jdon.util.Debug;
import java.lang.reflect.Method;
import com.jdon.bussinessproxy.TargetMetaDef;
import com.jdon.bussinessproxy.MyComponentProps;
import com.jdon.controller.ContainerWrapper;
import com.jdon.bussinessproxy.cache.VisitableNames;
import java.rmi.*;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import com.jdon.bussinessproxy.meta.*;
/**
* 动态代理后真正的执行者
*
* 使用ComponentManager(HttpSession)作为EJB session bean的缓冲
* ComponentManager还缓存了ProxyMethodInvocation.java
*
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public class EJBMethodInvoker implements MethodInvoker {
private final static String module = EJBMethodInvoker.class.getName();
private TargetService targetService;
private ComponentCacheVisitor cm;
public void setVisitor(ComponentCacheVisitor cm) {
this.cm = cm;
}
/**
public HttpSessionProxy() {
backService = new EJBProxyHandler();
}
**/
public EJBMethodInvoker(TargetService targetService) {
this.targetService = targetService;
}
/**
* 对后台targetMetaDef实现调用处理
* @param EJBDefinition
* @param m
* @param args
* @return Object
*/
public Object handleInvoker(TargetMetaDef targetMetaDef) throws
Throwable {
EJBTargetMetaDef eJBMetaDef = null;
if (targetMetaDef.isEJB()) {
eJBMetaDef = (EJBTargetMetaDef) targetMetaDef;
} else {
Debug.logError(" targetMetaDef is not EJB,but you call it by EJB", module);
return null;
}
Debug.logVerbose(" now handleInvoker for targetMetaDef " + targetMetaDef.toString(), module);
Object targetObjRef = null;
if (cm == null) { //如无targetObjRef的cache,直接获得home.create
Debug.logVerbose(" NOTE: not active cache !!!!", module);
targetObjRef = targetService.createObject(eJBMetaDef);
} else {
eJBMetaDef.setVisitableName(VisitableNames.EJBTARGETSERVICE_NAME);
Debug.logVerbose(VisitableNames.EJBTARGETSERVICE_NAME + " in action", module);
targetObjRef = cm.visit(eJBMetaDef);
}
MethodMetaArgs methodMetaArgs = targetMetaDef.getMethodMetaArgs();
return ejbInvoker(methodMetaArgs, targetObjRef);
}
/**
* 调用对应的EJB实行处理
*
* @param EJBDefinition
* @param m
* @param args
* @return Object
*/
private Object ejbInvoker(MethodMetaArgs methodMetaArgs, Object targetObjRef) throws
Throwable {
Object result = null;
try {
Method invokedMethod = methodMetaArgs.getMethod();
if (invokedMethod == null) //如果方法为空,构建它
invokedMethod = MethodConstructor.createMethod(targetObjRef,
methodMetaArgs.getMethodName(),
methodMetaArgs.getParamTypes());
Object[] p_args = methodMetaArgs.getArgs();
result = invokedMethod.invoke(targetObjRef, narrowArgs(p_args));
} catch (Exception ex) {
Debug.logError("handleInvoker error: " + ex, module);
throw new Exception(ex);
} catch (Throwable ex) {
throw new Throwable(ex);
}
return result;
}
/**
* 如果参数中有remote EJB,需要从远程序列化过来这些参数
*
*/
public Object[] narrowArgs(Object[] p_args) {
if (p_args == null)
return null;
int length = p_args.length;
Object[] result = new Object[length];
for (int i = 0; i < length; i++) {
if (p_args[i] instanceof Remote)
result[i] = PortableRemoteObject.narrow(p_args[i], EJBObject.class);
else
result[i] = p_args[i];
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -