List of usage examples for org.springframework.context ApplicationContext getBeansOfType
<T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException;
From source file:org.bigtester.ate.GlobalUtils.java
/** * Gets the case data files.// w w w .ja v a 2 s . c om * * @param appCtx * the app ctx * @return the case data files */ @Nullable public static List<Resource> getCaseDataFiles(ApplicationContext appCtx) { Map<String, Homepage> homepages = appCtx.getBeansOfType(Homepage.class, true, true); Map<String, Lastpage> lastpages = appCtx.getBeansOfType(Lastpage.class); Map<String, RegularPage> regularpages = appCtx.getBeansOfType(RegularPage.class); List<Resource> dataFiles = new ArrayList<Resource>(); for (int i = 0; i < homepages.size(); i++) { if (null != homepages.values().iterator().next().getDataFile()) dataFiles.add(homepages.values().iterator().next().getDataFile()); } for (int i = 0; i < lastpages.size(); i++) { if (null != lastpages.values().iterator().next().getDataFile()) dataFiles.add(lastpages.values().iterator().next().getDataFile()); } for (int i = 0; i < regularpages.size(); i++) { if (null != regularpages.values().iterator().next().getDataFile()) dataFiles.add(regularpages.values().iterator().next().getDataFile()); } return dataFiles; }
From source file:it.scoppelletti.programmerpower.web.security.CompositeDecisionManagerContributor.java
/** * Restituisce la lista dei configurazioni di attributi di controllo che * devono essere considerate da un componente di controllo. * /* w w w . ja v a2 s . c o m*/ * @param beanName Nome del bean. * @param applCtx Contesto dell’applicazione. * @return Collezione. */ static List<FilterInvocationSecurityMetadataSource> listSecurityMetadataSource(String beanName, ApplicationContext applCtx) { String targetName; FilterInvocationSecurityMetadataSource securityMds; List<FilterInvocationSecurityMetadataSource> list; Map<String, CompositeDecisionManagerContributor> contributorMap; if (Strings.isNullOrEmpty(beanName)) { throw new ArgumentNullException("beanName"); } if (applCtx == null) { throw new ArgumentNullException("applCtx"); } list = new ArrayList<FilterInvocationSecurityMetadataSource>(); myLogger.trace("Searching for CompositeDecisionManagerContributor " + "beans with targetName={}.", beanName); contributorMap = applCtx.getBeansOfType(CompositeDecisionManagerContributor.class, true, true); if (contributorMap == null || contributorMap.isEmpty()) { myLogger.warn("No CompositeDecisionManagerContributor bean found."); return list; } for (Map.Entry<String, CompositeDecisionManagerContributor> entry : contributorMap.entrySet()) { targetName = entry.getValue().getTargetName(); if (Strings.isNullOrEmpty(targetName)) { myLogger.warn("Invalid CompositeDecisionManagerContributor bean.", new PropertyNotSetException(entry.getKey(), "targetName")); continue; } if (!beanName.equals(targetName)) { continue; } myLogger.trace("Found CompositeDecisionManagerContributor bean {}" + "for bean {}.", entry.getKey(), beanName); securityMds = entry.getValue().getSecurityMetadataSource(); if (securityMds == null) { myLogger.warn("Invalid CompositeDecisionManagerContributor bean.", new PropertyNotSetException(entry.getKey(), "securityMetadataSource")); continue; } list.add(securityMds); } if (list.isEmpty()) { myLogger.warn("SecurityMetadataSource list is empty for bean {}.", beanName); } return list; }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.ControllerFilterManager.java
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { filters = applicationContext.getBeansOfType(ControllerFilter.class, false, false).values(); }
From source file:com.agileapes.couteau.context.spring.event.SpringEventTranslator.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; schemes.addAll(applicationContext.getBeansOfType(TranslationScheme.class, false, true).values()); Collections.sort(schemes, new OrderedBeanComparator()); Collections.sort(schemes, new Comparator<TranslationScheme>() { @Override//from w w w . j a va 2s .com public int compare(TranslationScheme o1, TranslationScheme o2) { final Integer first = o1 instanceof Ordered ? ((Ordered) o1).getOrder() : 0; final Integer second = o2 instanceof Ordered ? ((Ordered) o2).getOrder() : 0; return first.compareTo(second); } }); }
From source file:com.github.xdcrafts.flower.spring.impl.AbstractActionFactoryBean.java
@Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; this.dataFunctionExtractor = new DefaultDataFunctionExtractor( applicationContext.getBeansOfType(MethodConverter.class, true, false).values()); }
From source file:org.carewebframework.api.spring.FrameworkBeanFactory.java
/** * Creates a bean factory.// w w w.j a va 2s . c om * * @param parentContext Parent application context, if any. When specified, any placeholder * configurers found in the parent context will be registered in this bean factory. * @param parentBeanFactory The parent bean factory, if any. */ public FrameworkBeanFactory(ApplicationContext parentContext, BeanFactory parentBeanFactory) { super(parentBeanFactory); if (parentContext != null) { for (Object configurer : parentContext.getBeansOfType(PlaceholderConfigurerSupport.class, false, false) .values()) { registerSingleton("", configurer); } } }
From source file:it.scoppelletti.programmerpower.web.spring.config.CompositeRequestMatcher.java
/** * Restituisce la lista dei modelli di URL che devono essere gestiti da un * componente.//from w ww .j a v a 2 s.c o m * * @param beanName Nome del bean. * @param applCtx Contesto dell’applicazione. * @return Collezione. */ private List<String> listPatterns(String beanName, ApplicationContext applCtx) { String targetName; List<String> list; List<String> patterns; Map<String, CompositeRequestMatcherContributor> contributorMap; if (Strings.isNullOrEmpty(beanName)) { throw new ArgumentNullException("beanName"); } if (applCtx == null) { throw new ArgumentNullException("applCtx"); } list = new ArrayList<String>(); myLogger.trace("Searching for CompositeRequestMatcherContributor " + "beans with targetName={}.", beanName); contributorMap = applCtx.getBeansOfType(CompositeRequestMatcherContributor.class, true, true); if (contributorMap == null || contributorMap.isEmpty()) { myLogger.trace("No CompositeRequestMatcherContributor bean found."); return list; } for (Map.Entry<String, CompositeRequestMatcherContributor> entry : contributorMap.entrySet()) { targetName = entry.getValue().getTargetName(); if (Strings.isNullOrEmpty(targetName)) { myLogger.warn("Invalid CompositeRequestMatcherContributor bean.", new PropertyNotSetException(entry.getKey(), "targetName")); continue; } if (!targetName.equals(beanName)) { continue; } myLogger.trace("Found CompositeRequestMatcherContributor bean {} " + "for bean {}.", entry.getKey(), beanName); patterns = entry.getValue().getPatterns(); if (patterns == null) { myLogger.warn("Invalid CompositeRequestMatcherContributor bean.", new PropertyNotSetException(entry.getKey(), "patterns")); continue; } list.addAll(patterns); } if (list.isEmpty()) { myLogger.debug("Pattern list is empty for bean {}.", beanName); } return list; }
From source file:it.scoppelletti.programmerpower.web.spring.ApplicationContextListener.java
/** * Inizializzazione di una’applicazione Web. * /* w w w . j ava 2 s . co m*/ * @param event Evento. */ public void contextInitialized(ServletContextEvent event) { UUID applInstanceId; ApplicationContext applCtx; ServletContext servletCtx = event.getServletContext(); AttributeMap servletCtxMap; EventContext eventCtx = null; try { applInstanceId = UUIDGenerator.getInstance().newUUID(); } catch (Exception ex) { myLogger.error("Failed to extract UUID.", ex); applInstanceId = UUIDGenerator.NIL; } try { servletCtxMap = WebUtils.getSynchronizedAttributeMap(servletCtx); servletCtxMap.setAttribute(WebUtils.ATTR_APPLICATIONINSTANCEID, applInstanceId); eventCtx = new EventContext(ApplicationContextListener.THREAD_SERVLETCONTEXT_INIT, servletCtx); mySpringSvc.contextInitialized(event); applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx); myApplListeners = applCtx.getBeansOfType(ServletContextListener.class, false, true); mySessionListeners = applCtx.getBeansOfType(HttpSessionListener.class, false, true); for (Map.Entry<String, ServletContextListener> entry : myApplListeners.entrySet()) { myLogger.trace("Calling method contextInitialized of " + "ServletContextListener {}.", entry.getKey()); try { entry.getValue().contextInitialized(event); } catch (Exception ex) { myLogger.error(entry.getKey(), ex); } } } finally { if (eventCtx != null) { eventCtx.dispose(); eventCtx = null; } } }
From source file:org.springframework.richclient.security.SecurityAwareConfigurer.java
/** * Construct the list of all the beans we need to update. * @param beanType Type of bean to locate * @return List of all beans to udpate.//from w w w .jav a 2s . com */ protected List getBeansToUpdate(Class beanType) { final ApplicationContext ac = getApplicationContext(); final List listeners = new ArrayList(); if (ac != null) { if (logger.isDebugEnabled()) logger.debug("Constructing list of beans to notify; bean type=" + beanType.getName()); final Map map = ac.getBeansOfType(beanType, false, true); if (logger.isDebugEnabled()) logger.debug("bean map: " + map); listeners.addAll(map.values()); listeners.addAll(getNonSingletonListeners(beanType)); } if (logger.isDebugEnabled()) logger.debug("List of beans to notify:" + listeners); return listeners; }