abstractserver.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,057 行 · 第 1/2 页
JAVA
1,057 行
// XXX: not tested return _jndiEnv.lookup(jndiName); } catch (NamingException e) { throw new IllegalArgumentException(e); } } public UserTransaction getUserTransaction() { return _ut; } /** * Returns the owning container. */ public EjbContainer getEjbContainer() { return _ejbContainer; } /** * Sets the server program. */ public void setServerProgram(ConfigProgram serverProgram) { _serverProgram = serverProgram; } /** * Sets the server program. */ public ConfigProgram getServerProgram() { return _serverProgram; } /** * Sets the transaction timeout. */ public void setTransactionTimeout(long timeout) { _transactionTimeout = timeout; } /** * Gets the transaction timeout. */ public long getTransactionTimeout() { return _transactionTimeout; } /** * Returns the timer service. */ public TimerService getTimerService() { // ejb/0fj0 if (_timerService == null) { _timerService = EjbTimerService.getLocal(_ejbContainer.getClassLoader(), getContext()); } return _timerService; } /** * Invalidates caches. */ public void invalidateCache() { } /** * Remove an object. */ public Object remove(AbstractHandle handle) { throw new UnsupportedOperationException(); } /** * Remove an object. */ public void remove(Object primaryKey) { //throw new UnsupportedOperationException(); } /** * Gets the class loader */ public DynamicClassLoader getClassLoader() { return _loader; } /** * Gets the generated skeleton class */ public Class getBeanSkelClass() { return _contextImplClass; } public Class getRemoteStubClass() { return _remoteStubClass; } public Class getHomeStubClass() { return _homeStubClass; } /** * Returns the meta data */ public EJBMetaData getEJBMetaData() { if (_metaData == null) { try { EJBHome home = getEJBHome(); _metaData = new EJBMetaDataImpl(home, getRemoteHomeClass(), getRemoteObjectClass(), getPrimaryKeyClass()); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new EJBException(e); } if (this instanceof StatelessServer) { _metaData.setSession(true); _metaData.setStatelessSession(true); } else if (this instanceof SessionServer) { _metaData.setSession(true); } } return _metaData; } /** * Returns the home handle for the container */ public HomeHandle getHomeHandle() { if (_homeHandle == null) _homeHandle = getHandleEncoder().createHomeHandle(); return _homeHandle; } void setEJBHome(EJBHome remoteHome) { _remoteHome = remoteHome; } /** * Returns the EJBHome stub for the container */ public EJBHome getEJBHome() { if (_remoteHome != null) return _remoteHome; else { EJBHome home = (EJBHome) getRemoteObject(getRemoteHomeClass(), null); return home; } } /** * Returns the EJBHome stub for the container */ EJBHome getClientHome() { return getEJBHome(); } /** * Returns the session context. */ public AbstractSessionContext getSessionContext() { return null; } /** * Returns the EJBLocalHome stub for the container */ public EJBLocalHome getEJBLocalHome() { return _localHome; } /** * Returns the remote skeleton for the given API * * @param api the bean's api to return a value for * @param protocol the remote protocol */ abstract public Object getRemoteObject(Class api, String protocol); /** * Returns the a new local stub for the given API * * @param api the bean's api to return a value for */ abstract public Object getLocalObject(Class api); /** * Returns the local jndi proxy for the given API * * @param api the bean's api to return a value for */ abstract public Object getLocalProxy(Class api); /** * Returns the object key from a handle. */ public Class getPrimaryKeyClass() { return _primaryKeyClass; } public EJBObject getEJBObject(Object key) throws FinderException { return getContext(key).getEJBObject(); } /** * Returns the remote object. */ public Object getRemoteObject(Object key) throws FinderException { // XXX TCK: ejb30/.../remove return getContext(key).createRemoteView(); } public AbstractContext getContext() { return null; } public AbstractContext getContext(Object key) throws FinderException { return getContext(key, true); } public AbstractContext getContext(long key) throws FinderException { return getContext(new Long(key)); } /** * Returns the context with the given key */ abstract public AbstractContext getContext(Object key, boolean forceLoad) throws FinderException; /** * Sets the init program. */ public void setInitProgram(ConfigProgram init) { _initProgram = init; } /** * Gets the init program. */ public ConfigProgram getInitProgram() { return _initProgram; } /** * Initialize an instance */ public void initInstance(Object instance) { initInstance(instance, new ConfigContext()); } /** * Initialize an instance */ public void initInstance(Object instance, ConfigContext env) { /* if (scope != null) scope.put(_component, scope); */ if (_initInject != null) { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_loader); if (env == null) env = new ConfigContext(); for (ConfigProgram inject : _initInject) inject.inject(instance, env); } finally { thread.setContextClassLoader(oldLoader); } } } /** * Remove an object. */ public void destroyInstance(Object instance) { if (_destroyInject != null) { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_loader); ConfigContext env = null; if (env == null) env = new ConfigContext(); for (ConfigProgram inject : _destroyInject) inject.inject(instance, env); } finally { thread.setContextClassLoader(oldLoader); } } } public void init() throws Exception { _loader.init(); // _loader.setId("EnvironmentLoader[ejb:" + getId() + "]"); } public boolean start() throws Exception { if (! _lifecycle.toActive()) return false; Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(_loader); _loader.start(); bindContext(); if (_serverProgram != null) _serverProgram.configure(this); bindInjection(); log.config(this + " active"); } finally { thread.setContextClassLoader(oldLoader); } return true; } protected void bindContext() { } protected void bindInjection() { // Injection binding occurs in the start phase ArrayList<ConfigProgram> injectList = new ArrayList<ConfigProgram>(); InjectIntrospector.introspectInject(injectList, getEjbClass()); // XXX: add inject from xml here if (_initProgram != null) injectList.add(_initProgram); InjectIntrospector.introspectInit(injectList, getEjbClass()); // XXX: add init from xml here ConfigProgram []injectArray = new ConfigProgram[injectList.size()]; injectList.toArray(injectArray); if (injectArray.length > 0) _initInject = injectArray; injectList = new ArrayList<ConfigProgram>(); introspectDestroy(injectList, getEjbClass()); injectArray = new ConfigProgram[injectList.size()]; injectList.toArray(injectArray); if (injectArray.length > 0) _destroyInject = injectArray; } protected void introspectDestroy(ArrayList<ConfigProgram> injectList, Class ejbClass) { InjectIntrospector.introspectDestroy(injectList, getEjbClass()); } /** * Returns true if container transaction is used. */ public boolean isContainerTransaction() { return _isContainerTransaction; } /** * Sets true if container transaction is used. */ public void setContainerTransaction(boolean isContainerTransaction) { _isContainerTransaction = isContainerTransaction; } /** * Returns true is there is a local home or local client object for the bean. */ public boolean isLocal() { return (_localHome != null || _localApiList != null && _localApiList.size() > 0); } /** * Returns true is there is a remote home or remote client object * for the bean. */ public boolean isRemote() { return _remoteHome != null || _remoteHomeView != null; } /** * Returns true if the server is dead. */ public boolean isDead() { return ! _lifecycle.isActive(); } /** * Cleans up the server on shutdown */ public void destroy() { _lifecycle.toDestroy(); } public PostConstructConfig getPostConstruct() { return _postConstructConfig; } public PreDestroyConfig getPreDestroy() { return _preDestroyConfig; } public void setPostConstruct(PostConstructConfig postConstruct) { _postConstructConfig = postConstruct; } public void setPreDestroy(PreDestroyConfig preDestroy) { _preDestroyConfig = preDestroy; } /** * Client information for connecting to the server. */ public void addClientRemoteConfig(StringBuilder sb) { if (_remoteApiList != null && _remoteApiList.size() > 0) { sb.append("<ejb-ref>\n"); sb.append("<ejb-ref-name>" + getEJBName() + "</ejb-ref-name>\n"); if (_remoteHomeClass != null) sb.append("<home>" + _remoteHomeClass.getName() + "</home>\n"); sb.append("<remote>" + _remoteApiList.get(0).getName() + "</remote>\n"); sb.append("</ejb-ref>\n"); } } public ConfigException error(String msg) { if (_filename != null) throw new LineConfigException(_filename, _line, msg); else throw new ConfigException(msg); } public String toString() { if (getMappedName() != null) return getClass().getSimpleName() + "[" + getEJBName() + "," + getMappedName() + "]"; else return getClass().getSimpleName() + "[" + getEJBName() + "]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?