📄 ejbobjectfactory.java
字号:
/*
* Copyright 2003-2005 the original author or authors.
* 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.target;
import java.lang.reflect.Method;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import com.jdon.bussinessproxy.TargetMetaDef;
import com.jdon.bussinessproxy.meta.EJBTargetMetaDef;
import com.jdon.servicelocator.ServiceLocatorException;
import com.jdon.servicelocator.web.ServiceLocator;
import com.jdon.util.Debug;
/**
* @author <a href="mailto:banqiao@jdon.com">banq</a>
*
*/
public class EJBObjectFactory {
private final static String module = EJBObjectFactory.class.getName();
private ServiceLocator sl;
/**
* @param sl
*/
public EJBObjectFactory(ServiceLocator sl) {
super();
this.sl = sl;
}
public Object create(TargetMetaDef targetMetaDef) throws Exception{
Object obj = null;
Debug.logVerbose(" enter createObject in EJBTargetService " + targetMetaDef.getClassName(), module);
try {
EJBTargetMetaDef eJBMetaDef = (EJBTargetMetaDef) targetMetaDef;
if (eJBMetaDef.isLocal()) {
EJBLocalHome home = (EJBLocalHome) sl.getLocalHome(eJBMetaDef.getJndiName());
Method createMethod = home.getClass().getMethod("create", null);
obj = (EJBLocalObject) createMethod.invoke(home, null);
} else {
EJBHome home = sl.getRemoteHome(eJBMetaDef.getJndiName(), eJBMetaDef.getHomeClass());
Method createMethod = home.getClass().getMethod("create", null);
obj = (EJBObject) createMethod.invoke(home, null);
}
} catch (ServiceLocatorException sle) {
Debug.logError("locator error: " + sle, module);
throw new Exception("JNID error:" + sle);
} catch (Exception ex) {
Debug.logError("create ejb error: " + ex, module);
throw new Exception(ex);
}
return obj;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -