Example usage for org.springframework.beans.factory.xml XmlBeanFactory getBean

List of usage examples for org.springframework.beans.factory.xml XmlBeanFactory getBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlBeanFactory getBean.

Prototype

@SuppressWarnings("unchecked")
    @Override
    public <T> T getBean(Class<T> requiredType, @Nullable Object... args) throws BeansException 

Source Link

Usage

From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java

public static void addAdmin(String naConfigurationFile, String naProperties, String adminUser)

        throws InvalidIdentifierException, URISyntaxException, NamingAuthorityConfigurationException,
        NamingAuthoritySecurityException, InvalidIdentifierValuesException {

    FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile);
    FileSystemResource naPropertiesResource = new FileSystemResource(naProperties);

    XmlBeanFactory factory = new XmlBeanFactory(naConfResource);
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(naPropertiesResource);
    cfg.postProcessBeanFactory(factory);

    NamingAuthorityImpl na = (NamingAuthorityImpl) factory.getBean("NamingAuthority",
            MaintainerNamingAuthority.class);
    na.getIdentifierDao().createInitialAdministrator(adminUser);

    //        KeyData kd = na.getKeyData(null, na.getSystemIdentifier(), Keys.ADMIN_USERS);
    //        if (kd == null) {
    //           System.err.println("KD IS NULL");
    //           kd = new KeyData();
    //        }/* ww  w.ja v a  2s  . c o m*/
    //        
    //        List<String> values = kd.getValues();
    //        if (values == null) {
    //           System.err.println("VALUES IS NULL");
    //           values = new ArrayList<String>();
    //        }
    //        
    //        if (values.contains(adminUser)) {
    //           throw new NamingAuthorityConfigurationException("Provided identity [" + adminUser + "] is already an administrator");
    //        }
    //        
    //        values.add(adminUser);
    //        
    //        IdentifierValues ivalues = new IdentifierValues();
    //        ivalues.put(Keys.ADMIN_USERS, kd);
    //        na.replaceKeys(null, na.getSystemIdentifier(), ivalues);
}

From source file:gov.nih.nci.cagrid.identifiers.service.IdentifiersNAServiceImpl.java

public IdentifiersNAServiceImpl() throws RemoteException {
    super();//from   www  . j a v a  2  s  .  c o  m

    try {
        String naConfigurationFile = getConfiguration().getNaConfigurationFile();
        String naProperties = getConfiguration().getNaPropertiesFile();
        FileSystemResource naConfResource = new FileSystemResource(naConfigurationFile);
        FileSystemResource naPropertiesResource = new FileSystemResource(naProperties);

        XmlBeanFactory factory = new XmlBeanFactory(naConfResource);
        PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
        cfg.setLocation(naPropertiesResource);
        cfg.postProcessBeanFactory(factory);

        this.namingAuthority = (MaintainerNamingAuthority) factory.getBean(NA_BEAN_NAME,
                MaintainerNamingAuthority.class);

    } catch (Exception e) {
        String message = "Problem inititializing NamingAuthority while loading configuration:" + e.getMessage();
        LOG.error(message, e);
        throw new RemoteException(message, e);
    }
}

From source file:gda.data.metadata.icat.XMLIcat.java

@Override
protected String getValue(String visitIDFilter, String userNameFilter, String accessName) throws Exception {

    String filepath = "file:" + LocalProperties.get(URL_PROP);
    Resource xmlfile = new FileSystemResourceLoader().getResource(filepath);
    XmlBeanFactory bf = new XmlBeanFactory(xmlfile);

    long tolerance = LocalProperties.getAsInt(SHIFT_TOL_PROP, 1440);

    // if not filtering on visit ID
    if (visitIDFilter == null || visitIDFilter.isEmpty()) {

        //loop over all the beans
        String values = "";
        Map<String, XMLIcatEntry> beans = bf.getBeansOfType(XMLIcatEntry.class);
        for (XMLIcatEntry bean : beans.values()) {
            // filter on username
            String names[] = bean.getUsernames().split(",");
            if (ArrayUtils.contains(names, userNameFilter)) {

                // filter on date
                Date now;//w  w  w .j  a v a  2  s. c om
                if (operatingDate != null) {
                    now = operatingDate;
                } else {
                    now = new Date();
                }

                Date start = formatter.parse(bean.getExperimentStart());
                Date end = formatter.parse(bean.getExperimentStart());
                start.setTime(start.getTime() - tolerance * 60000);// tolerance is in minutes but getTime returns in
                // ms
                end.setTime(end.getTime() + tolerance * 60000); // tolerance is in minutes but getTime returns in ms

                if (now.after(start) && now.before(end)) {

                    // add to return string
                    try {
                        if (values.isEmpty()) {
                            values = BeanUtils.getProperty(bean, accessName);
                        } else {
                            values += "," + BeanUtils.getProperty(bean, accessName);
                        }
                    } catch (Exception e) {
                        logger.warn("Exception trying to get property " + accessName + " from bean.", e);
                    }
                }
            }
        }

        // return the values string
        if (values.isEmpty()) {
            return null;
        }
        return values;
    }

    // else find the experiment for that visit and get its property
    XMLIcatEntry visit = bf.getBean(visitIDFilter, XMLIcatEntry.class);
    String names[] = visit.getUsernames().split(",");
    if (ArrayUtils.contains(names, userNameFilter)) {
        try {
            return BeanUtils.getProperty(visit, accessName);
        } catch (Exception e) {
            logger.warn("Exception trying to get property " + accessName + " from bean.", e);
        }
    }

    // else 
    return null;

}

From source file:org.springframework.amqp.rabbit.config.AdminParserTests.java

private void doTest() throws Exception {
    // Create context
    XmlBeanFactory beanFactory = loadContext();
    if (beanFactory == null) {
        // Context was invalid
        return;/*  w ww. j  a va  2  s  .  c om*/
    }

    // Validate values
    RabbitAdmin admin;
    if (StringUtils.hasText(adminBeanName)) {
        admin = beanFactory.getBean(adminBeanName, RabbitAdmin.class);
    } else {
        admin = beanFactory.getBean(RabbitAdmin.class);
    }
    assertEquals(expectedAutoStartup, admin.isAutoStartup());
    assertEquals(beanFactory.getBean(ConnectionFactory.class),
            admin.getRabbitTemplate().getConnectionFactory());

    if (initialisedWithTemplate) {
        assertEquals(beanFactory.getBean(RabbitTemplate.class), admin.getRabbitTemplate());
    }

}