ejbsessionbean.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 607 行 · 第 1/2 页
JAVA
607 行
/* * 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.config.program.ContainerProgram;import com.caucho.config.ConfigException;import com.caucho.config.LineConfigException;import com.caucho.config.types.EnvEntry;import com.caucho.ejb.AbstractServer;import com.caucho.ejb.gen.BeanGenerator;import com.caucho.ejb.gen.SessionGenerator;import com.caucho.ejb.gen.StatefulGenerator;import com.caucho.ejb.gen.StatelessGenerator;import com.caucho.ejb.manager.EjbContainer;import com.caucho.ejb.session.StatefulServer;import com.caucho.ejb.session.StatelessServer;import com.caucho.java.gen.JavaClassGenerator;import com.caucho.util.L10N;import javax.annotation.PostConstruct;import javax.ejb.*;import java.util.ArrayList;import java.lang.reflect.*;/** * Configuration for an ejb entity bean. */public class EjbSessionBean extends EjbBean { private static final L10N L = new L10N(EjbSessionBean.class); private boolean _isStateless; // Default is container managed transaction. private boolean _isContainerTransaction = true; private SessionGenerator _sessionBean; /** * Creates a new session bean configuration. */ public EjbSessionBean(EjbConfig ejbConfig, String ejbModuleName) { super(ejbConfig, ejbModuleName); } /** * Returns the kind of bean. */ public String getEJBKind() { return "session"; } /** * Sets the ejb implementation class. */ @Override public void setEJBClass(Class type) throws ConfigException { super.setEJBClass(type); ApiClass ejbClass = getEJBClassWrapper(); if (ejbClass.isAbstract()) throw error(L.l("'{0}' must not be abstract. Session bean implementations must be fully implemented.", ejbClass.getName())); if (type.isAnnotationPresent(Stateless.class)) { Stateless stateless = (Stateless) type.getAnnotation(Stateless.class); if (getEJBName() == null && ! "".equals(stateless.name())) setEJBName(stateless.name()); _isStateless = true; } else if (ejbClass.isAnnotationPresent(Stateful.class)) { Stateful stateful = (Stateful) type.getAnnotation(Stateful.class); if (getEJBName() == null && ! "".equals(stateful.name())) setEJBName(stateful.name()); _isStateless = false; } if (getEJBName() == null) setEJBName(ejbClass.getSimpleName()); /* if (! ejbClass.isAssignableTo(SessionBean.class) && ! ejbClass.isAnnotationPresent(Stateless.class) && ! ejbClass.isAnnotationPresent(Stateful.class)) throw error(L.l("'{0}' must implement SessionBean or @Stateless or @Stateful. Session beans must implement javax.ejb.SessionBean.", ejbClass.getName())); */ // introspectSession(); } /** * Returns true if it's a stateless session bean. */ public boolean isStateless() { return _isStateless; } /** * Set true if it's a stateless session bean. */ public void setSessionType(String type) throws ConfigException { if (type.equals("Stateful")) _isStateless = false; else if (type.equals("Stateless")) _isStateless = true; else throw new ConfigException(L.l("'{0}' is an unknown session-type. session-type must be 'Stateless' or 'Stateful'.", type)); } /** * Returns true if the container handles transactions. */ public boolean isContainerTransaction() { return _isContainerTransaction; } /** * Set true if the container handles transactions. */ public void setTransactionType(String type) throws ConfigException { if (type.equals("Container")) _isContainerTransaction = true; else if (type.equals("Bean")) _isContainerTransaction = false; else throw new ConfigException(L.l("'{0}' is an unknown transaction-type. transaction-type must be 'Container' or 'Bean'.", type)); } /** * Configure initialization. */ @PostConstruct public void init() throws ConfigException { super.init(); try { if (getRemoteHome() != null) { validateHome(getRemoteHome(), getRemoteList().get(0)); } if (getLocalHome() != null) { validateHome(getLocalHome(), getLocalList().get(0)); } for (ApiClass remoteApi : getRemoteList()) validateRemote(remoteApi); for (ApiClass localApi : getLocalList()) validateRemote(localApi); if (getEJBClass() == null) { throw error(L.l("'{0}' does not have a defined ejb-class. Session beans must have an ejb-class.", getEJBName())); } if (! SessionSynchronization.class.isAssignableFrom(getEJBClassWrapper().getJavaClass())) { } else if (isStateless()) { throw error(L.l("'{0}' must not implement SessionSynchronization. Stateless session beans must not implement SessionSynchronization.", getEJBClass().getName())); } else if (! _isContainerTransaction) { throw error(L.l("'{0}' must not implement SessionSynchronization. Session beans with Bean-managed transactions may not use SessionSynchronization.", getEJBClass().getName())); } } catch (LineConfigException e) { throw e; } catch (ConfigException e) { throw new LineConfigException(getLocation() + e.getMessage(), e); } /* if (isStateless()) J2EEManagedObject.register(new StatelessSessionBean(this)); else J2EEManagedObject.register(new StatefulSessionBean(this)); */ } /** * Creates the bean generator for the session bean. */ @Override protected BeanGenerator createBeanGenerator() { if (_isStateless) _sessionBean = new StatelessGenerator(getEJBName(), getEJBClassWrapper()); else _sessionBean = new StatefulGenerator(getEJBName(), getEJBClassWrapper()); return _sessionBean; } /** * Obtain and apply initialization from annotations. */ public void initIntrospect() throws ConfigException { super.initIntrospect(); ApiClass type = getEJBClassWrapper(); // XXX: ejb/0f78 if (type == null) return; // ejb/0j20 if (! type.isAnnotationPresent(Stateful.class) && ! type.isAnnotationPresent(Stateless.class) && ! isAllowPOJO()) return; /* TCK: ejb/0f6d: bean with local and remote interfaces if (_localHome != null || _localList.size() != 0 || _remoteHome != null || _remoteList.size() != 0) return; */ ArrayList<ApiClass> interfaceList = new ArrayList<ApiClass>(); for (ApiClass localApi : type.getInterfaces()) { Class javaApi = localApi.getJavaClass(); Local local = (Local) javaApi.getAnnotation(Local.class); if (local != null) { setLocalWrapper(localApi); continue; } javax.ejb.Remote remote = (javax.ejb.Remote) javaApi.getAnnotation(javax.ejb.Remote.class); if (remote != null || java.rmi.Remote.class.isAssignableFrom(javaApi)) { setRemoteWrapper(localApi); continue; } if (javaApi.getName().equals("java.io.Serializable")) continue; if (javaApi.getName().equals("java.io.Externalizable")) continue; if (javaApi.getName().startsWith("javax.ejb")) continue; if (javaApi.getName().equals("java.rmi.Remote")) continue; if (! interfaceList.contains(localApi)) interfaceList.add(localApi); } // if (getLocalList().size() != 0 || getRemoteList().size() != 0) { if (_localHome != null || _localList.size() != 0 || _remoteHome != null || _remoteList.size() != 0) { } else if (interfaceList.size() == 0) throw new ConfigException(L.l("'{0}' has no interfaces. Can't currently generate.", type.getName()));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?