Example usage for org.springframework.context ApplicationContext getBeanNamesForType

List of usage examples for org.springframework.context ApplicationContext getBeanNamesForType

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBeanNamesForType.

Prototype

String[] getBeanNamesForType(ResolvableType type);

Source Link

Document

Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:edu.internet2.middleware.shibboleth.idp.profile.IdPProfileHandlerManager.java

/**
 * Reads the new error handler from the newly created application context and loads it into this manager.
 * /*from   www  .jav  a2s  .  c  o m*/
 * @param newServiceContext newly created application context
 */
protected void loadNewErrorHandler(ApplicationContext newServiceContext) {
    String[] errorBeanNames = newServiceContext.getBeanNamesForType(AbstractErrorHandler.class);
    log.debug("{}: Loading {} new error handler.", getId(), errorBeanNames.length);

    errorHandler = (AbstractErrorHandler) newServiceContext.getBean(errorBeanNames[0]);
    log.debug("{}: Loaded new error handler of type: {}", getId(), errorHandler.getClass().getName());
}

From source file:edu.internet2.middleware.shibboleth.idp.profile.IdPProfileHandlerManager.java

/**
 * Reads the new authentication handlers from the newly created application context and loads it into this manager.
 * //  w w w. j  a  va2s . c om
 * @param newServiceContext newly created application context
 */
protected void loadNewLoginHandlers(ApplicationContext newServiceContext) {
    String[] authnBeanNames = newServiceContext.getBeanNamesForType(LoginHandler.class);
    log.debug("{}: Loading {} new authentication handlers.", getId(), authnBeanNames.length);

    Map<String, LoginHandler> newLoginHandlers = new HashMap<String, LoginHandler>();
    LoginHandler authnHandler;
    for (String authnBeanName : authnBeanNames) {
        authnHandler = (LoginHandler) newServiceContext.getBean(authnBeanName);
        log.debug("{}: Loading authentication handler of type supporting authentication methods: {}", getId(),
                authnHandler.getSupportedAuthenticationMethods());

        for (String authnMethod : authnHandler.getSupportedAuthenticationMethods()) {
            newLoginHandlers.put(authnMethod, authnHandler);
        }
    }
    loginHandlers = newLoginHandlers;
}

From source file:edu.internet2.middleware.shibboleth.idp.profile.IdPProfileHandlerManager.java

/**
 * Reads the new profile handlers from the newly created application context and loads it into this manager.
 * /*from w  ww.  j a  v a  2s . c  o  m*/
 * @param newServiceContext newly created application context
 */
protected void loadNewProfileHandlers(ApplicationContext newServiceContext) {
    String[] profileBeanNames = newServiceContext
            .getBeanNamesForType(AbstractRequestURIMappedProfileHandler.class);
    log.debug("{}: Loading {} new profile handlers.", getId(), profileBeanNames.length);

    Map<String, AbstractRequestURIMappedProfileHandler> newProfileHandlers = new HashMap<String, AbstractRequestURIMappedProfileHandler>();
    AbstractRequestURIMappedProfileHandler<?, ?> profileHandler;
    for (String profileBeanName : profileBeanNames) {
        profileHandler = (AbstractRequestURIMappedProfileHandler) newServiceContext.getBean(profileBeanName);
        for (String requestPath : profileHandler.getRequestPaths()) {
            newProfileHandlers.put(requestPath, profileHandler);
            log.debug("{}: Loaded profile handler for handling requests to request path {}", getId(),
                    requestPath);
        }
    }
    profileHandlers = newProfileHandlers;
}

From source file:org.spring.guice.injector.SpringInjector.java

public SpringInjector(ApplicationContext context) {
    this.beanFactory = (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory();
    if (context.getBeanNamesForType(Injector.class).length > 0) {
        this.injector = context.getBean(Injector.class);
    }/*from   www  .j a v  a 2  s.  c  o m*/
}

From source file:it.cilea.osd.jdyna.utils.ImportUtils.java

/**
 * Effettua l'import di una specifica tipologia di oggetti a partire dalla
 * loro definizione xml (Spring)/* w w w.ja v  a  2 s  .  c  o m*/
 * 
 * @param <T>
 *            la classe di oggetti da importare
 * @param importFilePath
 *            il path al file (sul server) contenente la definizione xml
 *            degli oggetti
 * @param clazz
 *            la classe di oggetti da importare
 * @return il risultato dell'importazione (num. successi, num. fallimenti,
 *         eccezioni occorse)
 */
public <T extends Identifiable> ImportResult importSingolaClasseOggetti(String importFilePath, Class<T> clazz) {

    ImportResult importResult = new ImportResult();

    ApplicationContext context = new FileSystemXmlApplicationContext(new String[] { "file:" + importFilePath },
            appContext);

    String[] definitions = context.getBeanNamesForType(clazz);

    for (String definition : definitions) {
        try {
            T oggettoDaImportare = (T) context.getBean(definition);

            if (clazz.isAssignableFrom(AnagraficaSupport.class)) {
                AnagraficaObject oggetto = (AnagraficaObject) oggettoDaImportare;
                applicationService.fitAnagrafica(oggetto);
                //formulaManager.ricalcolaFormule(oggetto);
                oggetto.pulisciAnagrafica();
            }
            applicationService.saveOrUpdate(clazz, oggettoDaImportare);
            importResult.addSuccess();
        } catch (Exception ecc) {
            logger.warn("Errore nel salvataggio della definizione di " + clazz.getSimpleName() + " - bean id: "
                    + definition, ecc);

            importResult.addFail(ecc);
        }
    }
    return importResult;
}

From source file:org.gwtwidgets.server.spring.GWTHandler.java

/**
 * Scans the application context and its parents for service beans that
 * implement the {@link GWTRequestMapping}
 * /*from  w  ww .  ja  v  a  2  s .com*/
 * @param appContext
 *            Application context
 */
private void scanForAnnotatedBeans(final ApplicationContext appContext) {
    if (appContext == null) {
        return;
    }
    for (String beanName : appContext.getBeanNamesForType(RemoteService.class)) {
        Object service = appContext.getBean(beanName);
        if (service == null)
            continue;
        final Class<?> beanClass = service.getClass();

        final RemoteServiceRelativePath requestMapping = ReflectionUtils.findAnnotation(beanClass,
                RemoteServiceRelativePath.class);
        if (requestMapping == null) {
            continue;
        }

        // Create serviceExporter to bind to
        String mapping = requestMapping.value();
        if (mapping.contains("/")) {
            mapping = mapping.substring(mapping.lastIndexOf("/"));
        }
        if (getMappings().containsKey(mapping))
            logger.warn("Bean '" + mapping + "' already in mapping, skipping.");
        else
            getMappings().put(mapping, service);
    }
    if (scanParentApplicationContext)
        scanForAnnotatedBeans(appContext.getParent());
}

From source file:org.geoserver.web.admin.GlobalSettingsPage.java

public GlobalSettingsPage() {
    final IModel globalInfoModel = getGlobalInfoModel();
    final IModel loggingInfoModel = getLoggingInfoModel();

    CompoundPropertyModel compoundPropertyModel = new CompoundPropertyModel(globalInfoModel);
    Form form = new Form("form", compoundPropertyModel);

    add(form);//from  w w w  .j  a v  a 2 s  .com

    form.add(new CheckBox("verbose"));
    form.add(new CheckBox("verboseExceptions"));
    form.add(new CheckBox("globalServices"));
    form.add(new TextField<Integer>("numDecimals").add(new MinimumValidator<Integer>(0)));
    form.add(new DropDownChoice("charset", AVAILABLE_CHARSETS));
    form.add(new DropDownChoice<ResourceErrorHandling>("resourceErrorHandling",
            Arrays.asList(ResourceErrorHandling.values()), new ResourceErrorHandlingRenderer()));
    form.add(new TextField("proxyBaseUrl").add(new UrlValidator()));

    logLevelsAppend(form, loggingInfoModel);
    form.add(new CheckBox("stdOutLogging", new PropertyModel(loggingInfoModel, "stdOutLogging")));
    form.add(new TextField("loggingLocation", new PropertyModel(loggingInfoModel, "location")));

    TextField xmlPostRequestLogBufferSize = new TextField("xmlPostRequestLogBufferSize",
            new PropertyModel(globalInfoModel, "xmlPostRequestLogBufferSize"));
    xmlPostRequestLogBufferSize.add(new MinimumValidator<Integer>(0));
    form.add(xmlPostRequestLogBufferSize);

    form.add(new CheckBox("xmlExternalEntitiesEnabled"));

    form.add(new TextField<Integer>("featureTypeCacheSize").add(new MinimumValidator<Integer>(0)));

    IModel<String> lockProviderModel = new PropertyModel<String>(globalInfoModel, "lockProviderName");
    ApplicationContext applicationContext = GeoServerApplication.get().getApplicationContext();
    List<String> providers = new ArrayList<String>(
            Arrays.asList(applicationContext.getBeanNamesForType(LockProvider.class)));
    providers.remove("lockProvider"); // remove the global lock provider
    Collections.sort(providers);
    ;

    DropDownChoice<String> lockProviderChoice = new DropDownChoice<String>("lockProvider", lockProviderModel,
            providers, new LocalizedChoiceRenderer(this));

    form.add(lockProviderChoice);

    // Extension plugin for Global Settings
    // Loading of the settings from the Global Info
    IModel<SettingsInfo> settingsModel = new PropertyModel<SettingsInfo>(globalInfoModel, "settings");
    ListView extensions = SettingsPluginPanelInfo.createExtensions("extensions", settingsModel,
            getGeoServerApplication());
    form.add(extensions);

    Button submit = new Button("submit", new StringResourceModel("submit", this, null)) {
        @Override
        public void onSubmit() {
            GeoServer gs = getGeoServer();
            gs.save((GeoServerInfo) globalInfoModel.getObject());
            gs.save((LoggingInfo) loggingInfoModel.getObject());
            doReturn();
        }
    };
    form.add(submit);

    Button cancel = new Button("cancel") {
        @Override
        public void onSubmit() {
            doReturn();
        }
    };
    form.add(cancel);
}

From source file:com.clican.pluto.fsm.engine.impl.EngineContextImpl.java

@Transactional

public Session newSession(String sessionName, String userId) {
    Session session = new Session();
    Integer lastVersion = this.lastVersionMap.get(sessionName);
    if (log.isDebugEnabled()) {
        log.debug("Create new session, sessionName=[" + sessionName + "],sessionVersion=[" + lastVersion
                + "],userId=[" + userId + "]");
    }/*from ww  w .  jav  a2  s. co  m*/
    ApplicationContext context = sessionSpringMap.get(sessionName).get(lastVersion);

    String[] names = context.getBeanNamesForType(StartStateImpl.class);
    if (names.length != 1) {
        throw new RuntimeException("There must be only one StartState in the session description file");
    }
    IState istate = (IState) context.getBean(names[0]);
    session.setStateSet(new HashSet<State>());
    session.setSponsor(userId);
    session.setStartTime(new Date());
    session.setLastUpdateTime(new Date());
    session.setStatus(Status.ACTIVE.getStatus());
    session.setName(sessionName);
    session.setVersion(lastVersionMap.get(sessionName));
    session.setVariableSet(new HashSet<Variable>());
    sessionDao.save(session);
    sessionDao.setVariable(session, Parameters.SPONSOR.getParameter(), userId);
    istate.onStart(session, null, null);
    return session;
}

From source file:com.gisgraphy.webapp.listener.StartupListener.java

@SuppressWarnings({ "unchecked" })
public void contextInitialized(ServletContextEvent event) {
    log.debug("initializing context...");

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);

    if (config == null) {
        config = new HashMap<String, Object>();
    }/*from  w  w  w.j a va 2 s.co  m*/

    if (context.getInitParameter(Constants.CSS_THEME) != null) {
        config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME));
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    boolean encryptPassword = true;

    try {
        ProviderManager provider = (ProviderManager) ctx
                .getBean(ctx.getBeanNamesForType(ProviderManager.class)[0]);
        for (Object o : provider.getProviders()) {
            AuthenticationProvider p = (AuthenticationProvider) o;
            if (p instanceof RememberMeAuthenticationProvider) {
                config.put("rememberMeEnabled", Boolean.TRUE);
            }
            config.put(Constants.ENCRYPT_PASSWORD, Boolean.TRUE);
            config.put(Constants.ENC_ALGORITHM, "SHA");
        }
    } catch (NoSuchBeanDefinitionException n) {
        log.debug("authenticationManager bean not found, assuming test and ignoring...");
        // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
        log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
        log.debug("Encrypt Passwords? " + encryptPassword);
        if (encryptPassword) {
            log.debug("Encryption Algorithm: " + config.get(Constants.ENC_ALGORITHM));
        }
        log.debug("Populating drop-downs...");
    }

    setupContext(context);
}