org.sakaiproject.entitybroker.util.spring.BeanCollectorAutoRegistrar Maven / Gradle / Ivy
/**
* $Id$
* $URL$
* BeanCollectorAutoRegistrar.java - entity-broker - Apr 15, 2008 4:29:18 PM - azeckoski
**************************************************************************
* Copyright (c) 2007, 2008, 2009 The Sakai Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sakaiproject.entitybroker.util.spring;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.sakaiproject.entitybroker.collector.AutoRegister;
import org.sakaiproject.entitybroker.collector.BeanCollector;
import org.sakaiproject.entitybroker.collector.OrderedBean;
import org.sakaiproject.entitybroker.collector.BeanMapCollector;
/**
* This will collect the autoregistered beans and place them into all the locations which requested them
*
* @author Aaron Zeckoski ([email protected])
*/
@Slf4j
public class BeanCollectorAutoRegistrar implements ApplicationListener, ApplicationContextAware, InitializingBean {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public void onApplicationEvent(ApplicationEvent event) {
// We do not actually respond to any events, purpose is to time initialisation only.
}
private Set autoRegistered;
public void init() {
String[] autobeans = applicationContext.getBeanNamesForType(AutoRegister.class, false, false);
autoRegistered = new HashSet();
for (int i = 0; i < autobeans.length; i++) {
autoRegistered.add(autobeans[i]);
}
}
public void afterPropertiesSet() throws Exception {
log.debug("setAC: " + applicationContext.getDisplayName());
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext;
ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) cac.getBeanFactory();
cbf.addBeanPostProcessor(new BeanPostProcessor() {
@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(Object bean, String beanName) {
if (bean instanceof BeanCollector>) {
BeanCollector
© 2015 - 2025 Weber Informatics LLC | Privacy Policy