/** * Called when exiting portlet handling for this thread. The bean holders are deregistered from the thread and any * beans contained are destroyed. */ @Override public void removeContext() { PortletSessionBeanHolder.removeBeanHolder(); PortletStateScopedBeanHolder.removeBeanHolder(null); PortletRequestScopedBeanHolder.removeBeanHolder(); PortletArtifactProducer.remove(); }
/** * Returns an instance for the contextual type, or null if none available. * * @param bean * Contextual type (Bean) for which an instance is desired * @return The instance, or null if none exists */ public <T> T getBean(Contextual<T> bean) { String id = null; if (config.isPortletScoped(bean)) { id = windowId; } return beans.getBeanInstance(id, bean); }
/** * Construct for given portlet name. */ public PortletInvoker(AnnotatedConfigBean acb, String portletName) { this.methodStore = acb.getMethodStore(); this.portletName = portletName; }
/** * To be called before bean method invocation begins */ private void beforeInvoke(PortletRequest req, PortletResponse resp, PortletConfig config) { if (acb != null) { // Set the portlet session bean holder for the thread & session PortletRequestScopedBeanHolder.setBeanHolder(); // Set the portlet session bean holder for the thread & session PortletSessionBeanHolder.setBeanHolder(req, acb.getSessionScopedConfig()); // Set the render state scoped bean holder PortletStateScopedBeanHolder.setBeanHolder(req, acb.getStateScopedConfig()); // Set up the artifact producer with request, response, and portlet config PortletArtifactProducer.setPrecursors(req, resp, config); if (LOG.isTraceEnabled()) { LOG.trace("CDI context is now set up."); } } else { if (LOG.isTraceEnabled()) { LOG.trace("CDI contextual support not available"); } } }
/** * To be called by the CDI extension afterDeploymentValidation method to * verify that the stored methods are consistent and to create the bean references. * * @param bm BeanManager needed to activate the beans. * @throws InvalidAnnotationException If the deployment is inconsistent or if the * beans cannot be instantiated. */ @Override protected void activateCustomScopes(BeanManager bm) { // Activate the custom scoped beans stateScopedConfig.activate(bm); sessionScopedConfig.activate(bm); }
@Override public <T> T get(Contextual<T> bean) { PortletRequestScopedBeanHolder holder = PortletRequestScopedBeanHolder.getBeanHolder(); if (holder == null) { throw new ContextNotActiveException("The portlet request context is not active."); } return holder.getBean(bean); }
/** * Scans the servlet context classes and libraries for portlet method * annotations. * * @param ctx the servlet context */ public void scanContext(ServletContext ctx) { Set<File> files; files = getClassFilesForPath(ctx, CLASSDIR); scanFiles(files); files = getLibFilesForPath(ctx, LIBDIR); scanFiles(files); }
/** * Scans servlet context for method annotations. * * @param ctx the servlet context */ public void scanMethodAnnotations(ServletContext ctx) { MethodAnnotationRecognizer mar = new MethodAnnotationRecognizer(methodStore, configSummary); mar.scanContext(ctx); LOG.debug("Scan complete: \n" + methodStore.getMethodsAsString()); }
/** * Scans list of files for method annotations. * (unit test execution path) * * @param files the set of files to scan */ public void scanMethodAnnotations(Set<File> files) { MethodAnnotationRecognizer mar = new MethodAnnotationRecognizer(methodStore, configSummary); mar.scanFiles(files); LOG.debug("Scan complete: \n" + methodStore.getMethodsAsString()); }
/** * Add the context for the custom scope implementations. * * @param abd */ void addPortletCustomScopeContexts(@Observes AfterBeanDiscovery abd) { PortletSessionScopedContext pssc = new PortletSessionScopedContext(); abd.addContext(pssc); PortletStateScopedContext pstsc = new PortletStateScopedContext(); abd.addContext(pstsc); PortletRequestScopedContext prsc = new PortletRequestScopedContext(); abd.addContext(prsc); }
@Override public boolean isActive() { PortletRequestScopedBeanHolder holder = PortletRequestScopedBeanHolder.getBeanHolder(); return (holder != null); }
/** * Adds a bean instance with associated creational context to the store for the given contextual object (bean). * * @param bean * The bean type * @param crco * The creational context * @param instance * The bean instance */ public <T> void putBeanInstance(Contextual<T> bean, CreationalContext<T> crco, T instance) { String id = null; if (config.isPortletScoped(bean)) { id = windowId; } beans.putBeanInstance(id, bean, crco, instance); } }
@Override public <T> T get(Contextual<T> bean) { PortletStateScopedBeanHolder holder = PortletStateScopedBeanHolder.getBeanHolder(); if (holder == null) { throw new ContextNotActiveException("The render state context is not active."); } return holder.getBean(bean); }
@Override public boolean isActive() { PortletStateScopedBeanHolder holder = PortletStateScopedBeanHolder.getBeanHolder(); return (holder != null); }
@Override public boolean isActive() { PortletSessionBeanHolder holder = PortletSessionBeanHolder.getBeanHolder(); return (holder != null); }
public String getParameterName(Class<?> beanClass) { return config.getParamName(beanClass); }
/** * Remove & destroy all beans. * * @param resp The state aware response */ protected void removeAll() { for (Contextual<?> bean : beans.keySet()) { remove(bean); } } }
/** * shows all info about this description */ public String toString() { StringBuilder txt = new StringBuilder(128); txt.append(getExpectedSignature(false)); txt.append("/ type=").append(type); txt.append(", variant=").append(variant); txt.append(", checkExceptions=").append(checkExceptions); txt.append(", allowMultiple=").append(allowMultiple); return txt.toString(); }
@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; }