ejbref.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 622 行 · 第 1/2 页
JAVA
622 行
EjbRefContext context = EjbRefContext.createLocal(); context.add(this); WebBeansContainer webBeans = WebBeansContainer.create(); ComponentImpl comp = null; if (_home != null) { if (comp == null && _ejbLink != null) comp = webBeans.bind(_loc, _home, _ejbLink); if (comp == null) comp = webBeans.bind(_loc, _home, _ejbRefName); if (comp == null) comp = webBeans.bind(_loc, _home); if (comp == null) { comp = new ObjectProxyComponent(webBeans, this, _home); comp.setName(_ejbRefName); comp.addNameBinding(_ejbRefName); // weaker priority comp.setType(webBeans.createComponentType(Standard.class)); webBeans.addComponent(comp); } } else if (_remote != null) { if (comp == null && _ejbLink != null) comp = webBeans.bind(_loc, _home, _ejbLink); if (comp == null) comp = webBeans.bind(_loc, _remote, _ejbRefName); if (comp == null) comp = webBeans.bind(_loc, _remote); if (comp == null) { comp = new ObjectProxyComponent(webBeans, this, _remote); comp.setName(_ejbRefName); comp.addNameBinding(_ejbRefName); // weaker priority comp.setType(webBeans.createComponentType(Standard.class)); webBeans.addComponent(comp); } } String fullEjbRefName = Jndi.getFullName(_ejbRefName); boolean bind = false; try { if (bind) Jndi.rebindDeep(fullEjbRefName, this); } catch (Exception e) { throw e; } } /** * Creates the object from the proxy. * * @return the object named by the proxy. */ public Object createObject(Hashtable env) throws NamingException { if (_target == null) { // ejb/0f6g, TCK if (_foreignName != null) resolve(null); else if (_home != null) resolve(_home); else if (_remote != null) resolve(_remote); else if (getLocal() != null) // ejb/0f6g resolve(getLocal()); else resolve(null); } return _target; } public Object getByType(Class type) { try { if (_home != null && type.isAssignableFrom(_home)) return createObject(null); if (_remote != null && type.isAssignableFrom(_remote)) return createObject(null); if (_foreignName != null) { int pos = _foreignName.indexOf("#"); if (pos > 0) { String intf = _foreignName.substring(++pos).replace("_", "."); // TCK: application-client.xml with multiple business interfaces. if (! type.getName().equals(intf)) return null; } Object target; // XXX: JDK's iiop lookup String foreignName = _foreignName.replace('.', '_'); if (_context != null) { target = _context.lookup(foreignName); } else { target = Jndi.lookup(foreignName); } if (target != null && type != null) return PortableRemoteObject.narrow(target, type); } } catch (Exception e) { // log.log(Level.FINER, e.toString(), e); } return null; } private void resolve(Class type) throws NamingException { if (log.isLoggable(Level.FINEST)) log.log(Level.FINEST, L.l("{0} resolving", this)); if (_foreignName != null) _target = lookupByForeignJndi(_foreignName, type); else if (_ejbLink != null) _target = lookupByLink(_ejbLink, type); else _target = lookupLocal(type); if (log.isLoggable(Level.CONFIG)) log.log(Level.CONFIG, L.l("{0} resolved", this)); } private Object lookupByLink(String link, Class type) throws NamingException { Object target = null; String archiveName; String ejbName; int hashIndex = link.indexOf('#'); if (hashIndex < 0) { archiveName = null; ejbName = link; } else { archiveName = link.substring(0, hashIndex); ejbName = link.substring(hashIndex + 1); } try { Path path = archiveName == null ? _modulePath : _modulePath.lookup(archiveName); if (true) throw new IllegalStateException(); /* EJBServer ejbServer = EJBServer.getLocal(); AbstractServer server = null; if (ejbServer != null) { server = ejbServer.getServer(path, ejbName); if (server == null && archiveName == null) server = ejbServer.getServer(ejbName); } if (server != null) { if (isEjbLocalRef()) { target = server.getEJBLocalHome(); if (target != null) { // ejb/0f6g if (type != null && ! type.isAssignableFrom(target.getClass())) target = null; } if (target == null) { target = server.getLocalObject(type); } } else { target = server.getEJBHome(); if (target != null) { if (type != null && ! type.isAssignableFrom(target.getClass())) target = null; } if (target == null) { target = server.getRemoteObject(type); } } if (target == null) { log.log(Level.FINE, L.l("no home or business interface is available for '{0}'", server)); throw new NamingException(L.l("{0} '{1}' ejb bean found with ejb-link '{2}' has no home or business interface", getTagName(), _ejbRefName, link)); } } else { target = lookupByForeignJndi(_ejbLink, type); } if (target != null && target instanceof ObjectProxy) { ObjectProxy proxy = (ObjectProxy) target; target = proxy.createObject(null); } */ if (false) throw new NamingException(); } catch (NamingException e) { throw e; } catch (Exception e) { log.log(Level.FINER, e.toString(), e); throw new NamingException(L.l("{0} '{1}' ejb-link '{2}' invalid ", getTagName(), _ejbRefName, link)); } return target; } private Object lookupByForeignJndi(String foreignName, Class type) throws NamingException { Object target = Jndi.lookup(foreignName); return target; /* XXX Object target = null; String fullForeignName = Jndi.getFullName(foreignName); String fullEjbName = Jndi.getFullName(_ejbRefName); if (_context != null) { target = _context.lookup(fullForeignName); } else if (fullForeignName.equals(fullEjbName)) { // ejb/0ga0 return null; } else target = Jndi.lookup(foreignName); if (target == null) { if (fullForeignName.equals(fullEjbName)) throw new NamingException(L.l("{0} '{1}' cannot be resolved", getTagName(), _ejbRefName)); else throw new NamingException(L.l("{0} '{1}' foreign-name '{2}' not found", getTagName(), _ejbRefName, foreignName)); } if (type != null) target = PortableRemoteObject.narrow(target, type); return target; */ } private Object lookupLocal(Class type) { /* EjbServerManager manager = EjbServerManager.getLocal(); if (manager != null) { Object value = manager.getLocalByInterface(type); if (value instanceof ObjectProxy) { try { return ((ObjectProxy) value).createObject(null); } catch (Exception e) { throw new RuntimeException(e); } } else if (value != null) return value; else return manager.getRemoteByInterface(type); }*/ /* EjbRefContext context = EjbRefContext.getLocal(); if (context != null) return context.findByType(type); */ return null; } public String toString() { return getClass().getSimpleName() + "[" + _ejbRefName + ", " + _ejbLink + ", " + _foreignName + "]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?