abstractserver.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,057 行 · 第 1/2 页
JAVA
1,057 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Scott Ferguson */package com.caucho.ejb;import com.caucho.config.*;import com.caucho.config.program.ConfigProgram;import com.caucho.config.j2ee.InjectIntrospector;import com.caucho.config.program.ConfigProgram;import com.caucho.ejb.cfg.*;import com.caucho.ejb.manager.EjbContainer;import com.caucho.ejb.protocol.AbstractHandle;import com.caucho.ejb.protocol.EjbProtocolManager;import com.caucho.ejb.protocol.HandleEncoder;import com.caucho.ejb.session.AbstractSessionContext;import com.caucho.ejb.session.SessionServer;import com.caucho.ejb.session.StatelessServer;import com.caucho.ejb.timer.EjbTimerService;import com.caucho.jca.UserTransactionProxy;import com.caucho.lifecycle.Lifecycle;import com.caucho.loader.DynamicClassLoader;import com.caucho.loader.EnvironmentBean;import com.caucho.loader.EnvironmentClassLoader;import com.caucho.util.L10N;import com.caucho.util.Log;import com.caucho.webbeans.context.*;import com.caucho.webbeans.component.*;import javax.ejb.*;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.sql.DataSource;import javax.transaction.UserTransaction;import java.util.ArrayList;import java.util.HashMap;import java.util.logging.Logger;/** * Base server for a single home/object bean pair. */abstract public class AbstractServer implements EnvironmentBean { private final static Logger log = Log.open(AbstractServer.class); private static final L10N L = new L10N(AbstractServer.class); protected final EjbContainer _ejbContainer; protected final UserTransaction _ut = UserTransactionProxy.getInstance(); protected String _filename; protected int _line; protected String _location; protected String _id; protected String _ejbName; protected String _moduleName; protected String _handleServerId; // name for IIOP, Hessian, JNDI protected String _mappedName; private Context _jndiEnv; private ConfigProgram _serverProgram; protected HashMap<String,HandleEncoder> _protocolEncoderMap; protected HandleEncoder _handleEncoder; protected DataSource _dataSource; protected EnvironmentClassLoader _loader; // The original bean implementation class protected Class _ejbClass; // The class for the extended bean protected Class _contextImplClass; protected Class _local21; protected Class _remote21; protected Class _remoteHomeClass; protected Class _remoteObjectClass; protected ArrayList<Class> _remoteApiList = new ArrayList<Class>(); protected Class _primaryKeyClass; protected Class _localHomeClass; protected ArrayList<Class> _localApiList = new ArrayList<Class>(); protected Class _remoteStubClass; protected Class _homeStubClass; protected HomeHandle _homeHandle; protected EJBHome _remoteHome; protected EJBHome _remoteHomeView; protected EJBLocalHome _localHome; protected EJBMetaDataImpl _metaData; protected Class _serviceEndpointClass; protected long _transactionTimeout; protected ComponentImpl _component; private TimerService _timerService; protected ConfigProgram _initProgram; protected ConfigProgram []_initInject; protected ConfigProgram []_destroyInject; private AroundInvokeConfig _aroundInvokeConfig; private PreDestroyConfig _preDestroyConfig; private PostConstructConfig _postConstructConfig; private boolean _isContainerTransaction = true; private final Lifecycle _lifecycle = new Lifecycle();; /** * Creates a new server container * * @param manager the owning server container */ public AbstractServer(EjbContainer container) { _ejbContainer = container; _loader = EnvironmentClassLoader.create(container.getClassLoader()); } /** * Returns the id, module-path#ejb-name. */ public String getId() { return _id; } /** * Sets the id, module-path#ejb-name. */ public void setId(String id) { _id = id; int p = id.lastIndexOf('/'); if (p > 0) _loader.setId(getType() + id.substring(p + 1)); else _loader.setId(getType() + id); } public void setConfigLocation(String filename, int line) { _filename = filename; _line = line; } public void setLocation(String location) { _location = location; } protected String getType() { return "ejb:"; } public void setAroundInvoke(AroundInvokeConfig aroundInvoke) { _aroundInvokeConfig = aroundInvoke; } /** * Sets the ejb name. */ public void setEJBName(String ejbName) { _ejbName = ejbName; } /** * Returns the ejb's name */ public String getEJBName() { return _ejbName; } /** * Set's the module that defined this ejb. */ public void setModuleName(String moduleName) { _moduleName = moduleName; } /** * Returns's the module that defined this ejb. */ public String getModuleName() { return _moduleName; } /** * Sets the mapped name, default is to use the EJBName. This is the name for * both JNDI and the protocols such as IIOP and Hessian. */ public void setMappedName(String mappedName) { if (mappedName == null) { _mappedName = null; return; } while (mappedName.startsWith("/")) mappedName = mappedName.substring(1); while (mappedName.endsWith("/")) mappedName = mappedName.substring(0, mappedName.length() - 1); _mappedName = mappedName; } /** * Returns the mapped name. */ public String getMappedName() { return _mappedName == null ? getEJBName() : _mappedName; } /** * The name to use for remoting protocols, such as IIOP and Hessian. */ public String getProtocolId() { return "/" + getMappedName(); } /** * The name to use for remoting protocols, such as IIOP and Hessian. */ public String getProtocolId(Class cl) { if (cl == null) return getProtocolId(); // XXX TCK: ejb30/bb/session/stateless/callback/defaultinterceptor/descriptor/defaultInterceptorsForCallbackBean1 if (cl.getName().startsWith("java.")) return getProtocolId(); // Adds the suffix "#com_sun_ts_tests_ejb30_common_sessioncontext_Three1IF"; String url = getProtocolId() + "#" + cl.getName().replace(".", "_"); return url; } /** * Sets the ejb class */ public void setEjbClass(Class cl) { _ejbClass = cl; } /** * Sets the ejb class */ protected Class getEjbClass() { return _ejbClass; } /** * Sets the context implementation class. */ public void setContextImplClass(Class cl) { _contextImplClass = cl; } /** * Sets the remote home class. */ public void setRemoteHomeClass(Class cl) { _remoteHomeClass = cl; } /** * Gets the remote home class. */ public Class getRemoteHomeClass() { return _remoteHomeClass; } /** * Gets the 2.1 remote interface. */ public Class getRemote21() { return _remote21; } /** * Sets the remote object list. */ public void setRemoteApiList(ArrayList<Class> list) { _remoteApiList = new ArrayList<Class>(list); if (_remoteApiList.size() > 0) _remoteObjectClass = _remoteApiList.get(0); } /** * Returns the remote object list. */ public ArrayList<Class> getRemoteApiList() { return _remoteApiList; } /** * Returns true if there is any remote object. */ public boolean hasRemoteObject() { if (_remoteApiList == null) return false; if (_remoteApiList.size() == 0) return false; return true; } /** * Sets the remote object class. */ public void setRemoteObjectClass(Class cl) { _remoteObjectClass = cl; if (_remoteApiList == null) { _remoteApiList = new ArrayList<Class>(); _remoteApiList.add(cl); } } /** * Gets the remote object class. */ public Class getRemoteObjectClass() { return _remoteObjectClass; } /** * Sets the local home class. */ public void setLocalHomeClass(Class cl) { _localHomeClass = cl; } /** * Gets the local home class. */ public Class getLocalHomeClass() { return _localHomeClass; } /** * Sets the service endpoint. */ public void setServiceEndpoint(Class cl) { _serviceEndpointClass = cl; } /** * Gets the service endpoint */ public Class getServiceEndpoint() { return _serviceEndpointClass; } /** * Sets the local api class list */ public void setLocalApiList(ArrayList<Class> list) { _localApiList = new ArrayList<Class>(list); } /** * Sets the remote object class. */ public ArrayList<Class> getLocalApiList() { return _localApiList; } public HandleEncoder getHandleEncoder(String protocol) { HandleEncoder encoder; if (_protocolEncoderMap != null) { encoder = _protocolEncoderMap.get(protocol); if (encoder != null) return encoder; } try { Class keyClass = getPrimaryKeyClass(); encoder = _ejbContainer.getProtocolManager().createHandleEncoder(this, keyClass, protocol); } catch (Exception e) { throw EJBExceptionWrapper.createRuntime(e); } if (_protocolEncoderMap == null) _protocolEncoderMap = new HashMap<String,HandleEncoder>(8); _protocolEncoderMap.put(protocol, encoder); return encoder; } /** * Returns the encoded id. */ public String encodeId(Object primaryKey) { return String.valueOf(primaryKey); } public HandleEncoder addHandleEncoder(String protocol, String serverId) { HandleEncoder encoder; if (_protocolEncoderMap != null) { encoder = _protocolEncoderMap.get(protocol); if (encoder != null) return encoder; } try { Class keyClass = getPrimaryKeyClass(); encoder = new HandleEncoder(this, serverId + _ejbName); } catch (Exception e) { throw EJBExceptionWrapper.createRuntime(e); } if (_protocolEncoderMap == null) _protocolEncoderMap = new HashMap<String,HandleEncoder>(8); _protocolEncoderMap.put(protocol, encoder); return encoder; } public HandleEncoder getHandleEncoder() { return getHandleEncoder(EjbProtocolManager.getThreadProtocol()); } public void setHandleEncoder(HandleEncoder encoder) { if (_homeHandle != null) _homeHandle = null; _handleEncoder = encoder; } public String getHandleServerId() { if (_handleServerId == null) _handleServerId = getHandleEncoder().getServerId(); return _handleServerId; } /** * Looks up the JNDI object. */ public Object lookup(String jndiName) { try { if (_jndiEnv == null) _jndiEnv = (Context) new InitialContext().lookup("java:comp/env");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?