Example usage for org.springframework.beans.factory ListableBeanFactory getBean

List of usage examples for org.springframework.beans.factory ListableBeanFactory getBean

Introduction

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

Prototype

Object getBean(String name) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:com.laxser.blitz.util.SpringUtils.java

public static <T> T getBean(ListableBeanFactory bf, String beanName) {
    @SuppressWarnings("unchecked")
    T bean = (T) (bf.containsBean(beanName) ? bf.getBean(beanName) : null);
    return bean;/*from  ww w  .  j  a v  a2 s .c o m*/
}

From source file:com.laxser.blitz.util.SpringUtils.java

public static <T> T getBean(ListableBeanFactory bf, Class<?> beanClass) {
    String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(bf, beanClass);
    @SuppressWarnings("unchecked")
    T bean = (T) ((names.length == 0) ? null : bf.getBean(names[0]));
    return bean;//from  w  w  w .  j  ava 2  s.  c  o m
}

From source file:com.laxser.blitz.util.SpringUtils.java

@SuppressWarnings("unchecked")
public static <T> List<T> getBeans(ListableBeanFactory bf, Class<T> beanClass) {
    String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(bf, beanClass);
    List<T> beans = new ArrayList<T>(names.length);
    for (String name : names) {
        beans.add((T) bf.getBean(name));
    }/*w  w  w .j  a v a 2s  .  c  om*/
    return beans;
}

From source file:edu.psu.citeseerx.disambiguation.CsxDisambiguation.java

public static void disambiguate(ListableBeanFactory factory, String infile, String outfile) throws Exception {

    CsxAuthorBlock block = (CsxAuthorBlock) factory.getBean("csxAuthorBlock");
    block.loadAuthors(infile);//from ww  w. ja  v  a  2 s .c o m

    int min_pts = MIN_PTS;
    if (block.points.size() <= 3)
        min_pts = 1;
    DBScan dbscan = new DBScan(block, EPS, min_pts);
    dbscan.run();
    dbscan.printResults(outfile);
}

From source file:edu.psu.citeseerx.disambiguation.CsxDisambiguation.java

public static void createBlocks(ListableBeanFactory factory) throws Exception {
    String dirpath = "data/csauthors/blocks";

    DataSource dataSource = (DataSource) factory.getBean("csxDataSource");

    PreparedStatement st = dataSource.getConnection().prepareStatement("SELECT * FROM authors",
            ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    st.setFetchSize(Integer.MIN_VALUE);
    ResultSet rs = st.executeQuery();

    initDirectories(dirpath);//from   w  ww .ja v  a 2s . c o m

    CsxAuthorFilter filter = (CsxAuthorFilter) factory.getBean("csxAuthorFilter");
    //new CsxAuthorFilter("data/csauthors/name_stopwords.txt");
    BufferedWriter skip = new BufferedWriter(new FileWriter("skip.txt"));

    int count = 0;
    Map<String, List<String>> blocks = new HashMap<String, List<String>>();
    while (rs.next()) {
        count++;
        if ((count % 10000) == 0)
            System.out.println("#Auth:" + count);
        String rsname = rs.getString("name");
        if (!filter.isStopword(rsname) && !filter.isInstitute(rsname) && !filter.isPosition(rsname)) {

            CsxAuthor auth = new CsxAuthor(rs);
            String lname = auth.getLastName();
            String fname = auth.getFirstName();

            if ((lname != null) && (fname != null)) {
                if ((lname.charAt(0) >= 'A') && (lname.charAt(0) <= 'Z') && (fname.charAt(0) >= 'A')
                        && (fname.charAt(0) <= 'Z') && !((fname.length() == 1) && (lname.length() == 1))
                        && !(lname.matches(".*/.*"))) {

                    String l_init = lname.substring(0, 1).toUpperCase();
                    String f_init = fname.substring(0, 1).toUpperCase();
                    String key = l_init + f_init + "/" + lname.toLowerCase() + "_" + f_init.toLowerCase()
                            + ".txt";

                    List<String> list;
                    if (!blocks.containsKey(key)) {
                        list = new ArrayList<String>();
                        blocks.put(key, list);
                    } else {
                        list = blocks.get(key);
                    }
                    list.add(auth.getId());
                } else {
                    skip.write("SKIP: [" + rsname + "]\n");
                }
            }
        }
    }
    skip.close();

    for (String key : blocks.keySet()) {
        List<String> aids = blocks.get(key);
        // only care about cluster with more than one document
        if (aids.size() > 1) {
            BufferedWriter out = new BufferedWriter(new FileWriter(dirpath + "/" + key));
            for (String aid : aids) {
                out.write(aid + "\n");
            }
            out.close();
        }
    }
}

From source file:edu.psu.citeseerx.disambiguation.CsxDisambiguation.java

public static void disambiguateFile(ListableBeanFactory factory, String infile) throws Exception {
    //CsxAuthorBlock block = new CsxAuthorBlock(conn, rconn, "jian_huang2.block");
    //CsxAuthorBlock block = new CsxAuthorBlock(conn, rconn, "data/csauthors/blocks/MP/mitra_p.txt");
    //CsxAuthorBlock block = new CsxAuthorBlock(conn, rconn, "data/csauthors/blocks/BK/borner_k.txt");

    CsxAuthorBlock block = (CsxAuthorBlock) factory.getBean("csxAuthorBlock");
    block.loadAuthors(infile);/*  www . j av a  2 s .c  o  m*/

    int min_pts = MIN_PTS;
    if (block.points.size() <= 3)
        min_pts = 1;
    DBScan dbscan = new DBScan(block, EPS, min_pts);
    dbscan.run();
    dbscan.printResults();
}

From source file:wsconfig.WebServiceConfigPays.java

@Bean
public XsdSchema countriesSchema() {
    ClassPathResource cpr = new ClassPathResource("applicationContext.xml");

    ListableBeanFactory bf = new XmlBeanFactory(cpr);
    WsConfig conf = (WsConfig) bf.getBean("config");

    //return new SimpleXsdSchema(new ClassPathResource("pays.xsd"));
    return new SimpleXsdSchema(new ClassPathResource(conf.getSchema()));
}

From source file:wsconfig.WebServiceConfigPays.java

@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {

    ClassPathResource cpr = new ClassPathResource("applicationContext.xml");
    ListableBeanFactory bf = new XmlBeanFactory(cpr);
    WsConfig conf = (WsConfig) bf.getBean("config");

    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    /*return new ServletRegistrationBean(servlet, "/ws/*");*/
    return new ServletRegistrationBean(servlet, conf.getLocationUri() + "/*");
}

From source file:wsconfig.WebServiceConfigPays.java

@Bean(name = "pays")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema paysSchema) {

    ClassPathResource cpr = new ClassPathResource("applicationContext.xml");
    ListableBeanFactory bf = new XmlBeanFactory(cpr);
    WsConfig conf = (WsConfig) bf.getBean("config");

    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    /*wsdl11Definition.setPortTypeName("PaysPort");
    wsdl11Definition.setLocationUri("/ws");
    wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");*/

    wsdl11Definition.setPortTypeName(conf.getPortTypeName());
    wsdl11Definition.setLocationUri(conf.getLocationUri());
    wsdl11Definition.setTargetNamespace(conf.getTargetNamespace());
    wsdl11Definition.setSchema(paysSchema);
    return wsdl11Definition;
}

From source file:CommentTest.java

@Test
public void ValidationCommentTest() {

    ListableBeanFactory bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    ICommentaireDao m = (ICommentaireDao) bf.getBean("commentaireDao");
    Commentaire co = new Commentaire();
    m.updateCommentaire(2);//  www .jav a 2s .c  om

}