private TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { TransactionSynchronizationRegistry transactionSynchronizationRegistry; try { InitialContext initialContext = new InitialContext(); transactionSynchronizationRegistry = (TransactionSynchronizationRegistry) initialContext.lookup(TRANSACTION_SYNCHRONIZATION_REGISTRY_JNDI_NAME); } catch (NamingException ne) { throw new ContextNotActiveException("Could not get TransactionSynchronizationRegistry", ne); } int status = transactionSynchronizationRegistry.getTransactionStatus(); if (status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_PREPARED || status == Status.STATUS_UNKNOWN || status == Status.STATUS_PREPARING || status == Status.STATUS_COMMITTING || status == Status.STATUS_ROLLING_BACK) { return transactionSynchronizationRegistry; } throw new ContextNotActiveException("TransactionSynchronizationRegistry status is not active."); }
@SuppressWarnings("unchecked") public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get(); if (ctx == null) { // Thread local not set - context is not active! throw new ContextNotActiveException(); } ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual); if (instance == null && creationalContext != null) { // Bean instance does not exist - create one if we have CreationalContext instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual); ctx.put(contextual, instance); } return instance != null ? instance.get() : null; }
@SuppressWarnings("unchecked") @Override public <T> T get(Contextual<T> contextual) { Map<Contextual<?>, Object> store = contextualStore.get(); if (store == null) { throw new ContextNotActiveException(); } return (T) store.get(contextual); }
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); throw ContextLogger.LOG.contextualIsNull(); T instance = contextual.create(creationalContext); if (instance != null) { beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
@Override public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); } if (contextual == null) { throw new RuntimeException(jtaLogger.i18NLogger.get_contextual_is_null()); } PassivationCapable bean = (PassivationCapable) contextual; TransactionSynchronizationRegistry tsr = this.transactionSynchronizationRegistrySupplier.get(); Object resource = tsr.getResource(bean.getId()); if (resource != null) { return (T) resource; } else if (creationalContext != null) { Transaction currentTransaction = getCurrentTransaction(); T t = contextual.create(creationalContext); tsr.putResource(bean.getId(), t); synchronized (transactions) { TransactionScopeCleanup synch = transactions.get(currentTransaction); if (synch == null) { synch = new TransactionScopeCleanup(this, currentTransaction); transactions.put(currentTransaction, synch); } synch.registerBean(contextual, creationalContext, t); } return t; } else { return null; } }
@Override public void destroy(Contextual<?> contextual) { if (!isActive()) { throw new ContextNotActiveException(); } checkContextInitialized(); if (contextual == null) { throw ContextLogger.LOG.contextualIsNull(); } final BeanStore beanStore = getBeanStore(); if (beanStore == null) { throw ContextLogger.LOG.noBeanStoreAvailable(this); } BeanIdentifier id = getId(contextual); ContextualInstance<?> beanInstance = beanStore.remove(id); if (beanInstance != null) { RequestScopedCache.invalidate(); destroyContextualInstance(beanInstance); } }
org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage.Development) e.printStackTrace();
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());
@SuppressWarnings("unchecked") public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get(); if (ctx == null) { // Thread local not set - context is not active! throw new ContextNotActiveException(); } ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual); if (instance == null && creationalContext != null) { // Bean instance does not exist - create one if we have CreationalContext instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual); ctx.put(contextual, instance); } return instance != null ? instance.get() : null; }
@Produces @RequestScoped public FacesContext getFacesContext() { FacesContext ctx = FacesContext.getCurrentInstance(); if (ctx == null) { throw new ContextNotActiveException("FacesContext is not active"); } return ctx; } }
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); throw ContextLogger.LOG.contextualIsNull(); T instance = contextual.create(creationalContext); if (instance != null) { beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
@Override public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); } if (contextual == null) { throw new RuntimeException(jtaLogger.i18NLogger.get_contextual_is_null()); } PassivationCapable bean = (PassivationCapable) contextual; TransactionSynchronizationRegistry tsr = this.transactionSynchronizationRegistrySupplier.get(); Object resource = tsr.getResource(bean.getId()); if (resource != null) { return (T) resource; } else if (creationalContext != null) { Transaction currentTransaction = getCurrentTransaction(); T t = contextual.create(creationalContext); tsr.putResource(bean.getId(), t); synchronized (transactions) { TransactionScopeCleanup synch = transactions.get(currentTransaction); if (synch == null) { synch = new TransactionScopeCleanup(this, currentTransaction); transactions.put(currentTransaction, synch); } synch.registerBean(contextual, creationalContext, t); } return t; } else { return null; } }
@Override public void destroy(Contextual<?> contextual) { if (!isActive()) { throw new ContextNotActiveException(); } checkContextInitialized(); if (contextual == null) { throw ContextLogger.LOG.contextualIsNull(); } final BeanStore beanStore = getBeanStore(); if (beanStore == null) { throw ContextLogger.LOG.noBeanStoreAvailable(this); } BeanIdentifier id = getId(contextual); ContextualInstance<?> beanInstance = beanStore.remove(id); if (beanInstance != null) { RequestScopedCache.invalidate(); destroyContextualInstance(beanInstance); } }
org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage.Development) e.printStackTrace();
@SuppressWarnings("unchecked") public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { Map<Contextual<?>, ContextualInstance<?>> ctx = currentContext.get(); if (ctx == null) { // Thread local not set - context is not active! throw new ContextNotActiveException(); } ContextualInstance<T> instance = (ContextualInstance<T>) ctx.get(contextual); if (instance == null && creationalContext != null) { // Bean instance does not exist - create one if we have CreationalContext instance = new ContextualInstance<T>(contextual.create(creationalContext), creationalContext, contextual); ctx.put(contextual, instance); } return instance != null ? instance.get() : null; }
@Produces @RequestScoped public FacesContext getFacesContext() { FacesContext ctx = FacesContext.getCurrentInstance(); if (ctx == null) { throw new ContextNotActiveException("FacesContext is not active"); } return ctx; } }
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); throw ContextLogger.LOG.contextualIsNull(); T instance = contextual.create(creationalContext); if (instance != null) { beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
@Override public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { if (!isActive()) { throw new ContextNotActiveException(); } if (contextual == null) { throw new RuntimeException(jtaLogger.i18NLogger.get_contextual_is_null()); } PassivationCapable bean = (PassivationCapable) contextual; TransactionSynchronizationRegistry tsr = this.transactionSynchronizationRegistrySupplier.get(); Object resource = tsr.getResource(bean.getId()); if (resource != null) { return (T) resource; } else if (creationalContext != null) { Transaction currentTransaction = getCurrentTransaction(); T t = contextual.create(creationalContext); tsr.putResource(bean.getId(), t); synchronized (transactions) { TransactionScopeCleanup synch = transactions.get(currentTransaction); if (synch == null) { synch = new TransactionScopeCleanup(this, currentTransaction); transactions.put(currentTransaction, synch); } synch.registerBean(contextual, creationalContext, t); } return t; } else { return null; } }
@Override public void destroy(Contextual<?> contextual) { if (!isActive()) { throw new ContextNotActiveException(); } checkContextInitialized(); if (contextual == null) { throw ContextLogger.LOG.contextualIsNull(); } final BeanStore beanStore = getBeanStore(); if (beanStore == null) { throw ContextLogger.LOG.noBeanStoreAvailable(this); } BeanIdentifier id = getId(contextual); ContextualInstance<?> beanInstance = beanStore.remove(id); if (beanInstance != null) { RequestScopedCache.invalidate(); destroyContextualInstance(beanInstance); } }
org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage.Development) e.printStackTrace();