@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); }
@Produces @RequestScoped public FacesContext getFacesContext() { FacesContext ctx = FacesContext.getCurrentInstance(); if (ctx == null) { throw new ContextNotActiveException("FacesContext is not active"); } return ctx; } }
private void verifyConversationContextActive() { if (!isContextActive()) { throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this); } }
private void verifyConversationContextActive() { if (!isContextActive()) { throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this); } }
/** * Assert the context is active, otherwise throw ContextNotActiveException. */ @SuppressWarnings({"FinalPrivateMethod"}) private final void assertNotReleased() { if (!isActive()) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Trying to access ViewScope CDI context while it is not active"); } throw new ContextNotActiveException(); } }
private void verifyConversationContextActive() { if (!isContextActive()) { throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this); } }
private void verifyConversationContextActive() { if (!isContextActive()) { throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this); } }
private void verifyConversationContextActive() { if (!isContextActive()) { throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this); } }
private void assertActive() { if (!isActive()) { throw new ContextNotActiveException( "Context with scope annotation @ProjectScoped is not active with respect to the current directory."); } }
private void assertActive() { if (!isActive()) { throw new ContextNotActiveException("Seam context with scope annotation @ViewScoped is not active with respect to the current thread"); } }
/** * Assert the context is active, otherwise throw ContextNotActiveException. */ @SuppressWarnings({"FinalPrivateMethod"}) private final void assertNotReleased() { if (!isActive()) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Trying to access ViewScope CDI context while it is not active"); } throw new ContextNotActiveException(); } }
private void assertActive() { if (!isActive()) { throw new ContextNotActiveException( "Context with scope annotation @CommandScoped is not active since no command is in execution."); } }
private void assertActive() { if (!isActive()) { throw new ContextNotActiveException( "Context with scope annotation @ProjectScoped is not active with respect to the current directory."); } }
@Override public final <T> T get(final Contextual<T> contextual, final CreationalContext<T> creationalContext) { if (!this.isActive()) { throw new ContextNotActiveException(); } @SuppressWarnings("unchecked") final T temp = (T)this.instances.computeIfAbsent(contextual, c -> new Instance<>(Objects.requireNonNull(contextual), creationalContext)).getInstance(); return temp; }
/** * Make sure that the Context is really active. * * @throws ContextNotActiveException if there is no active * Context for the current Thread. */ protected void checkActive() { if (!isActive()) { throw new ContextNotActiveException("CDI context with scope annotation @" + getScope().getName() + " is not active with respect to the current thread"); } }
@Override protected void checkActive() { if (!isActive()) { throw new ContextNotActiveException("Context with scope annotation @" + getScope().getName() + " is not active"); } }
@Override protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean createIfNotExist) { String windowId = getCurrentWindowId(); if (windowId == null) { throw new ContextNotActiveException("WindowContext: no windowId set for the current Thread yet!"); } return windowBeanHolder.getContextualStorage(beanManager, windowId, createIfNotExist); }
@Override public <T> T get(Contextual<T> bean, CreationalContext<T> crco) { PortletRequestScopedBeanHolder holder = PortletRequestScopedBeanHolder.getBeanHolder(); if (holder == null) { throw new ContextNotActiveException("The portlet request context is not active."); } // The bean holder will return an existing bean instance or create a new one // if no existing instance is available. T inst = holder.getBean(bean, crco); return inst; }
public static <T extends Context> T getActiveContext(WeldManager beanManager, Class<T> type) { for (T context : beanManager.instance().select(type)) { if (context.isActive()) { return context; } } throw new ContextNotActiveException(); }
@Test public void testNotLoggedUserName() { doThrow(new ContextNotActiveException()).when(sessionInfo).getIdentity(); final String username = serverUsernameProvider.get(); verify(sessionInfo).getIdentity(); assertEquals("not-logged-user", username); } }