ejbref.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 622 行 · 第 1/2 页

JAVA
622
字号
/* * 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 Sam */package com.caucho.config.types;import com.caucho.bytecode.*;import com.caucho.config.j2ee.*;import com.caucho.ejb.*;import com.caucho.ejb.cfg.EjbConfig;import com.caucho.ejb.manager.EjbContainer;import com.caucho.ejb.protocol.EjbProtocolManager;import com.caucho.naming.Jndi;import com.caucho.naming.ObjectProxy;import com.caucho.util.BeanUtil;import com.caucho.util.L10N;import com.caucho.vfs.JarPath;import com.caucho.vfs.Path;import com.caucho.vfs.Vfs;import com.caucho.webbeans.component.*;import com.caucho.webbeans.manager.*;import javax.annotation.PostConstruct;import javax.naming.Context;import javax.naming.NamingException;import javax.rmi.PortableRemoteObject;import javax.webbeans.*;import java.lang.reflect.Field;import java.lang.reflect.Method;import java.util.Hashtable;import java.util.Iterator;import java.util.logging.Level;import java.util.logging.Logger;/** * Configuration for the ejb-ref. * * An ejb-ref is used to make an ejb available within the environment * in which the ejb-ref is declared. */public class EjbRef extends BaseRef implements ObjectProxy {  private static final L10N L = new L10N(EjbRef.class);  private static final Logger log    = Logger.getLogger(EjbRef.class.getName());  private String _loc;    private Context _context;  private String _ejbRefName;  private String _type;  private Class _home;  private Class _remote;  private String _foreignName;  private String _ejbLink;  private String _typeName;  private Object _target;  private boolean _isInitBinding;  private String _clientClassName;  public EjbRef()  {  }  public EjbRef(Context context)  {    _context = context;  }  public EjbRef(Path modulePath)  {    super(modulePath);  }  public EjbRef(Path modulePath, String sourceEjbName)  {    super(modulePath, sourceEjbName);  }  public void setConfigLocation(String loc)  {    _loc = loc;  }  public boolean isEjbLocalRef()  {    return false;  }  /**   * Gets the injection-target   */  public InjectionTarget getInjectionTarget()  {    return _injectionTarget;  }  public Class getLocal()  {    return null;  }  protected String getTagName()  {    return "<ejb-ref>";  }  public void setId(String id)  {  }  public void setDescription(String description)  {  }  public void setClientClassName(String clientClassName)  {    _clientClassName = clientClassName;  }  /**   * Sets the name to use in the local jndi context.   * This is the jndi lookup name that code uses to obtain the home for   * the bean when doing a jndi lookup.   *   * <pre>   *   <ejb-ref-name>ejb/Gryffindor</ejb-ref-name>   *   ...   *   (new InitialContext()).lookup("java:comp/env/ejb/Gryffindor");   * </pre>   */  public void setEjbRefName(String name)  {    _ejbRefName = name;  }  /**   * Sets the injection-target   */  public void setInjectionTarget(InjectionTarget injectionTarget)  {    _injectionTarget = injectionTarget;  }  /**   * Returns the ejb name.   */  public String getEjbRefName()  {    return _ejbRefName;  }  public void setEjbRefType(String type)  {    _type = type;  }  public void setHome(Class home)  {    _home = home;  }  /**   * Returns the home class.   */  public Class getHome()  {    return _home;  }  public void setRemote(Class remote)  {    _remote = remote;  }  /**   * Returns the remote class.   */  public Class getRemote()  {    // XXX: should distinguish    return _remote;  }  /**   * Sets the canonical jndi name to use to find the bean that   * is the target of the reference.   * For remote beans, a &lt;jndi-link> {@link com.caucho.naming.LinkProxy} is   * used to link the local jndi context referred to in this name to   * a remote context.   */  public void setForeignName(String foreignName)  {    _foreignName = foreignName;  }  /**   * Set the target of the reference, an alternative to {@link #setJndiName(String)}.   * The format of the ejbLink is "bean", or "jarname#bean", where <i>bean</i> is the   * ejb-name of a bean within the same enterprise application, and <i>jarname</i>   * further qualifies the identity of the target.   */  public void setEjbLink(String ejbLink)  {    _ejbLink = ejbLink;  }  /**   * Merges duplicated information in application-client.xml / resin-application-client.xml   */  public void mergeFrom(EjbRef other)  {    if (_foreignName == null)      _foreignName = other._foreignName;    if (_ejbLink == null)      _ejbLink = other._ejbLink;    if (_type == null)      _type = other._type;    if (_home == null)      _home = other._home;    if (_remote == null)      _remote = other._remote;    if (_injectionTarget == null)      _injectionTarget = other._injectionTarget;  }  // XXX TCK, needs QA  @PostConstruct  public void init()    throws Exception  {    // TCK, needsQA, ejb30/bb/session/stateless/sessioncontext/descriptor/getBusinessObjectLocal1    // Cannot do initialization here as there might be duplicated ejb-ref's in    // application-client.xml and resin-application-client.xml or even additional    // configuration files (TCK).    // application-client: <ejb-ref> initialization    // if (_clientClassName != null)    //  initBinding(null);    if (log.isLoggable(Level.FINER))      log.log(Level.FINER, L.l("{0} init", this));  }  public void bind()    throws Exception  {    initBinding(null);  }  // XXX TCK, needs QA @PostConstruct, called from EjbConfig.deployBeans()  public void initBinding(AbstractServer ejbServer)    throws Exception  {    if (_isInitBinding)      return;    _isInitBinding = true;        if (_foreignName != null) {      int pos = _foreignName.indexOf("#");      // TCK/IIOP for multiple interfaces 2.1/3.0 home/remote, needs QA      // TCK: ejb30/bb/session/stateful/sessioncontext/descriptor/getBusinessObjectLocal1      if (pos < 0) {        // TCK, needs QA: ejb30/bb/session/stateless/migration/twothree/descriptor        // The EJB 2.1 home is bound to the foreign name. No need to append the interface.        if (_home == null) {          if (_remote != null)            _foreignName += "#" + _remote.getName().replace(".", "_");          else if (getLocal() != null)            _foreignName += "#" + getLocal().getName().replace(".", "_");        }      }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?