ejbbean.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,224 行 · 第 1/4 页
JAVA
2,224 行
/* * 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.cfg;import com.caucho.bytecode.*;import com.caucho.config.program.ConfigProgram;import com.caucho.config.program.ContainerProgram;import com.caucho.config.ConfigException;import com.caucho.config.LineConfigException;import com.caucho.config.DependencyBean;import com.caucho.config.types.*;import com.caucho.ejb.AbstractServer;import com.caucho.ejb.gen.*;import com.caucho.ejb.manager.EjbContainer;import com.caucho.java.gen.CallChain;import com.caucho.java.gen.GenClass;import com.caucho.java.gen.JavaClassGenerator;import com.caucho.loader.EnvironmentBean;import com.caucho.loader.EnvironmentLocal;import com.caucho.make.ClassDependency;import com.caucho.util.L10N;import com.caucho.vfs.Depend;import com.caucho.vfs.Path;import com.caucho.vfs.PersistentDependency;import com.caucho.vfs.Vfs;import javax.annotation.PostConstruct;import javax.ejb.*;import javax.interceptor.*;import java.lang.annotation.Annotation;import java.lang.ref.SoftReference;import java.util.ArrayList;import java.util.HashMap;import java.util.Map;import java.util.logging.Level;import java.util.logging.Logger;import java.lang.reflect.*;/** * Configuration for an ejb bean. */public class EjbBean extends DescriptionGroupConfig implements EnvironmentBean, DependencyBean{ private static Logger log = Logger.getLogger(EjbBean.class.getName()); private static L10N L = new L10N(EjbBean.class); private static EnvironmentLocal<Map<Class,SoftReference<ApiMethod[]>>> _methodCache = new EnvironmentLocal<Map<Class,SoftReference<ApiMethod[]>>>(); private final EjbConfig _ejbConfig; private final String _ejbModuleName; private ClassLoader _loader; protected ClassLoader _jClassLoader; private String _ejbName; // The published name as used by IIOP, Hessian, and // jndi-remote-prefix/jndi-local-prefix private String _mappedName; private String _location = ""; private String _filename; private int _line; private boolean _isInit; // used for error messsage line # // these classes are loaded with the parent (configuration) loader, not // the server loader private ApiClass _ejbClass; protected ApiClass _remoteHome; protected ArrayList<ApiClass> _remoteList = new ArrayList<ApiClass>(); protected ApiClass _localHome; protected ArrayList<ApiClass> _localList = new ArrayList<ApiClass>(); protected BeanGenerator _bean; private boolean _isAllowPOJO = true; protected boolean _isContainerTransaction = true; ArrayList<PersistentDependency> _dependList = new ArrayList<PersistentDependency>(); ArrayList<PersistentDependency> _configDependList = new ArrayList<PersistentDependency>(); ArrayList<String> _beanDependList = new ArrayList<String>(); protected ArrayList<EjbMethodPattern> _methodList = new ArrayList<EjbMethodPattern>(); private HashMap<String,EjbBaseMethod> _methodMap = new HashMap<String,EjbBaseMethod>(); private ContainerProgram _initProgram; private ArrayList<ConfigProgram> _postConstructList = new ArrayList<ConfigProgram>(); private ContainerProgram _serverProgram; private ArrayList<Interceptor> _interceptors = new ArrayList<Interceptor>(); private String _aroundInvokeMethodName; private Method _aroundInvokeMethod; private String _timeoutMethodName; private long _transactionTimeout; private AroundInvokeConfig _aroundInvokeConfig; private ArrayList<RemoveMethod> _removeMethods = new ArrayList<RemoveMethod>(); /** * Creates a new entity bean configuration. */ public EjbBean(EjbConfig ejbConfig, String ejbModuleName) { _ejbConfig = ejbConfig; _ejbModuleName = ejbModuleName; _loader = ejbConfig.getEjbContainer().getClassLoader(); } public EjbConfig getConfig() { return _ejbConfig; } public EjbContainer getEjbContainer() { return _ejbConfig.getEjbContainer(); } public String getAroundInvokeMethodName() { return _aroundInvokeMethodName; } public void setAroundInvokeMethodName(String aroundInvokeMethodName) { _aroundInvokeMethodName = aroundInvokeMethodName; } public void setAroundInvoke(AroundInvokeConfig aroundInvoke) { _aroundInvokeConfig = aroundInvoke; // ejb/0fbb _aroundInvokeMethodName = aroundInvoke.getMethodName(); } /** * Returns the remove-method for the given method. */ public RemoveMethod getRemoveMethod(Method method) { for (RemoveMethod removeMethod : _removeMethods) { if (removeMethod.isMatch(method)) return removeMethod; } return null; } /** * Returns the remove-method list. */ public ArrayList<RemoveMethod> getRemoveMethods() { return _removeMethods; } /** * Returns the timeout method name. */ public String getTimeoutMethodName() { return _timeoutMethodName; } /** * Adds a new remove-method */ public void addRemoveMethod(RemoveMethod removeMethod) { _removeMethods.add(removeMethod); } /** * Returns the interceptors. */ public ArrayList<Interceptor> getInterceptors() { return _interceptors; } /** * Returns the interceptors. */ public ArrayList<Interceptor> getInvokeInterceptors(String methodName) { ArrayList<Interceptor> matchList = null; for (Interceptor interceptor : _interceptors) { if (methodName.equals(interceptor.getAroundInvokeMethodName())) { if (matchList == null) matchList = new ArrayList<Interceptor>(); matchList.add(interceptor); } } return matchList; } /** * Adds a new interceptor. */ public void addInterceptor(Interceptor interceptor) { _interceptors.add(interceptor); } /** * Returns true if the interceptor is already configured. */ public boolean containsInterceptor(String interceptorClassName) { return getInterceptor(interceptorClassName) != null; } /** * Returns the interceptor for a given class name. */ public Interceptor getInterceptor(String interceptorClassName) { for (Interceptor interceptor : _interceptors) { String className = interceptor.getInterceptorClass(); if (className.equals(interceptorClassName)) return interceptor; } return null; } public String getEJBModuleName() { return _ejbModuleName; } /** * Returns the class loader. */ public ClassLoader getClassLoader() { return _loader; } protected Class loadClass(String className) { try { return Class.forName(className, false, _loader); } catch (ClassNotFoundException e) { throw ConfigException.create(e); } } /** * Sets the location */ public void setConfigLocation(String filename, int line) { if (_filename == null) { _filename = filename; _line = line; } if (_location == null) _location = filename + ":" + line + ": "; } /** * Sets the location */ public void setLocation(String location) { _location = location; } /** * Gets the location */ public String getLocation() { return _location; } /** * Gets the file name */ public String getFilename() { return _filename; } /** * Gets the line */ public int getLine() { return _line; } /** * Sets true if POJO are allowed. */ public void setAllowPOJO(boolean allowPOJO) { _isAllowPOJO = allowPOJO; } /** * Return true if POJO are allowed. */ public boolean isAllowPOJO() { return _isAllowPOJO; } /** * Sets the ejbName */ public void setEJBName(String ejbName) { _ejbName = ejbName; } /** * Gets the ejbName */ public String getEJBName() { return _ejbName; } /** * The mapped-name is the remote published name * used by IIOP, Hessian, and jndi-remote-prefix, jndi-local-prefix. * The default is the EJBName. */ public void setMappedName(String mappedName) { _mappedName = mappedName; } /** * The mapped-name is the published name * used by IIOP, Hessian, and jndi-remote-prefix, jndi-local-prefix. */ public String getMappedName() { return _mappedName == null ? getEJBName() : _mappedName; } /** * Returns the kind of bean. */ public String getEJBKind() { return "unknown"; } /** * Sets the ejb implementation class. */ public void setEJBClass(Class ejbClass) throws ConfigException { setEJBClassWrapper(new ApiClass(ejbClass)); } /** * Sets the ejb implementation class. */ public void setEJBClassWrapper(ApiClass ejbClass) throws ConfigException { if (_ejbClass != null && ! _ejbClass.getName().equals(ejbClass.getName())) throw error(L.l("ejb-class '{0}' cannot be redefined. Old value is '{1}'.", _ejbClass.getName(), ejbClass.getName())); _ejbClass = ejbClass; if (! _ejbClass.isPublic()) throw error(L.l("'{0}' must be public. Bean implementations must be public.", ejbClass.getName())); if (_ejbClass.isFinal()) throw error(L.l("'{0}' must not be final. Bean implementations must not be final.", ejbClass.getName())); if (_ejbClass.isInterface()) throw error(L.l("'{0}' must not be an interface. Bean implementations must be classes.", ejbClass.getName())); // ejb/02e5 Constructor constructor = null; try { constructor = ejbClass.getConstructor(new Class[0]); } catch (Exception e) { log.log(Level.FINE, e.toString(), e); } if (constructor == null) throw error(L.l("'{0}' needs a public zero-arg constructor. Bean implementations need a public zero-argument constructor.", ejbClass.getName())); for (Class exn : constructor.getExceptionTypes()) { if (! RuntimeException.class.isAssignableFrom(exn)) { throw error(L.l("{0}: constructor must not throw '{1}'. Bean constructors must not throw checked exceptions.", ejbClass.getName(), exn.getName())); } } ApiMethod method = ejbClass.getMethod("finalize", new Class[0]); if (method != null && ! method.getDeclaringClass().equals(Object.class)) throw error(L.l("'{0}' may not implement finalize(). Bean implementations may not implement finalize().", ejbClass.getName())); } /** * Gets the ejb implementation class. */ public Class getEJBClass() { try { if (_ejbClass == null) return null; return Class.forName(_ejbClass.getName(), false, getClassLoader()); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw ConfigException.create(e); } } /** * Gets the ejb implementation class. */ public ApiClass getEJBClassWrapper() { return _ejbClass; } /** * Gets the ejb implementation class. */ public String getEJBFullClassName() { return _ejbClass.getName(); } /** * Gets the ejb implementation class. */ public String getEJBClassName() { String s = _ejbClass.getName(); int p = s.lastIndexOf('.'); if (p > 0) return s.substring(p + 1); else return s; } /** * Gets the implementation class name. */ public String getFullImplName() { return getEJBFullClassName(); } /** * Sets the remote home interface class. */ public void setHome(Class homeClass) throws ConfigException { ApiClass home = new ApiClass(homeClass); setRemoteHomeWrapper(home); } /** * Sets the remote home interface class. */ public void setRemoteHomeWrapper(ApiClass remoteHome) throws ConfigException { _remoteHome = remoteHome; if (! remoteHome.isPublic()) throw error(L.l("'{0}' must be public. <home> interfaces must be public.", remoteHome.getName())); if (! remoteHome.isInterface()) throw error(L.l("'{0}' must be an interface. <home> interfaces must be interfaces.", remoteHome.getName())); if (EJBHome.class.isAssignableFrom(remoteHome.getJavaClass())) { } else if (! isAllowPOJO()) { // XXX: does descriptor still have this requirement? // i.e. annotations act differently throw new ConfigException(L.l("'{0}' must extend EJBHome. <home> interfaces must extend javax.ejb.EJBHome.", remoteHome.getName())); } } /** * Gets the ejb implementation class. */ public ApiClass getRemoteHome() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?