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

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

Introduction

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

Prototype

public XmlBeanFactory(Resource resource) throws BeansException 

Source Link

Document

Create a new XmlBeanFactory with the given resource, which must be parsable using DOM.

Usage

From source file:com.milkdairy.admin.MilkDairyManagement.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Resource resource = new ClassPathResource("applicationContext.xml");
            BeanFactory factory = new XmlBeanFactory(resource);

            JPanel milkDairyManagementJPanel = (MilkDairyManagementJPanel) factory
                    .getBean("milkDairyManagementJPanel");

            UIManager.put("swing.boldmetal", Boolean.FALSE);

            new LoginJFrame(milkDairyManagementJPanel, (LoggingService) factory.getBean("loggingService"))
                    .setVisible(true);/*  w ww  .j a  v  a2s  .  c o m*/

        }

    });
}

From source file:net.ab0oo.aprs.clients.JmsBroker.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("web/WEB-INF/classes/broker.xml"));
    factory.getBean("broker");
    System.out.println("JMS Broker starting up");
    while (true) {
        try {//w  w  w. j a v  a2 s  .  com
            Thread.sleep(10000);
        } catch (InterruptedException iex) {

        }
    }
}

From source file:net.ab0oo.aprs.big.BIG.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("big.xml"));
    Server server = (Server) factory.getBean("WebServer");
    server.start();// w  w  w .j a v a 2s. com
}

From source file:net.ab0oo.aprs.SpringServer.java

public static void main(String[] args) throws Exception {
    BeanFactory factory = null;/*from ww w.  j  a va 2  s  .  co  m*/
    if (args.length > 0) {
        factory = new XmlBeanFactory(new FileSystemResource(args[0]));
        factory.getBean("tcpClient");

    } else {
        factory = new XmlBeanFactory(new FileSystemResource("web/WEB-INF/classes/wedjat.xml"));
        factory.getBean("tcpClient");
    }
}

From source file:com.cazcade.billabong.image.impl.ImageMain.java

public static void main(String[] args) throws URISyntaxException {
    BeanFactory factory = new XmlBeanFactory(new ClassPathResource("/spring/image-service.xml"));
    ImageService service = (ImageService) factory.getBean("imageService");
    //        sendRequest(service, "http://c0021791.cdn1.cloudfiles.rackspacecloud.com/12bd4a28-8e01-4662-8faf-ca5dee21449b.png");
    //        sendImageRequest(service, "http://c0021791.cdn1.cloudfiles.rackspacecloud.com/12bd4a28-8e01-4662-8faf-ca5dee21449b.png");
    sendRequest(service, "http://www.msn.com");
    sendRequest(service, "http://www.google.com");
    sendRequest(service, "http://www.amazon.com");
    sendRequest(service, "http://www.theregister.co.uk");
    sendRequest(service, "http://www.slashdot.org");
    sendRequest(service, "http://news.bbc.co.uk");
}

From source file:org.restlet.example.book.restlet.ch03.sec3.server.MailServerSpring.java

public static void main(String[] args) throws Exception {
    // Load the Spring container
    ClassPathResource resource = new ClassPathResource(
            "org/restlet/example/book/restlet/ch04/sec3/server/component-spring.xml");
    BeanFactory factory = new XmlBeanFactory(resource);

    // Start the Restlet component
    Component component = (Component) factory.getBean("component");
    component.start();/*w w w.ja va  2  s  .c om*/
}

From source file:org.guicerecipes.spring.converter.SpringConverter.java

public static void main(String[] args) {
    if (args.length == 0) {
        System.out.println("Usage: springXmlFile [outputDirectory] [outputClassName]");
    } else {//from  w  w w  .j  a  va2 s . c  o m
        String springFile = args[0];
        XmlBeanFactory beanFactory = null;
        try {
            beanFactory = new XmlBeanFactory(new FileSystemResource(springFile));
        } catch (BeansException e) {
            System.out.println("Failed to open: " + springFile + ". Reason: " + e);
            e.printStackTrace();
            return;
        }
        try {
            SpringConverter converter = new SpringConverter(beanFactory);
            converter.convert();
        } catch (Exception e) {
            System.out.println("Failed to file from: " + springFile);
            System.out.println(e);
            e.printStackTrace();
        }
    }
}

From source file:com.yarsquidy.x12.example.exampleSpringParseX12FileOne.java

public static void main(String[] args) {
    X12 x12 = null;//  www . ja va  2s . c o m

    Resource xmlResource = new FileSystemResource("./target/classes/cf/appContext_835_004010X091.xml");
    BeanFactory factory = new XmlBeanFactory(xmlResource);
    Cf cf = (Cf) factory.getBean("bean_X12");

    Double totalChargeAmount = 0.0;

    URL url = exampleSpringParseX12FileOne.class.getClass()
            .getResource("/org/pb/x12/example/example835One.txt");
    File f1 = new File(url.getFile());

    Parser parser = new X12Parser(cf);

    try {

        x12 = (X12) parser.parse(f1);

        // calculate the total charge amount
        List<Loop> loops = x12.findLoop("2100");
        for (Loop loop : loops) {
            for (Segment s : loop) {
                if (s.getElement(0).equals("CLP")) {
                    totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3));
                }
            }
        }
        System.out.println("Total Charged Amount = " + totalChargeAmount.toString());

        // calculate the total charge amount - alternate method
        totalChargeAmount = 0.0;
        List<Segment> segments = x12.findSegment("CLP");
        for (Segment s : segments) {
            totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3));
        }
        System.out.println("Total Charged Amount = " + totalChargeAmount.toString());

    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:ch.tatool.app.service.export.DataImportTest.java

public static void main(String[] args) {
    // get the httpentity containing the data
    HttpEntity httpEntity = getHttpEntity();
    // Create a httpclient instance
    DefaultHttpClient httpclient = new DefaultHttpClient();
    // setup a POST call
    HttpGet httpGet = new HttpGet(serverUrl);

    try {/* w w w  . j  a v  a 2 s. c o  m*/
        HttpResponse response = httpclient.execute(httpGet);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            System.out.println("Unable to download data: " + response.getStatusLine().getReasonPhrase());
            System.out.println(response.getStatusLine().getStatusCode());
        } else {
            // all ok
            HttpEntity enty = response.getEntity();
            InputStream is = enty.getContent();

            XmlBeanFactory beanFactory = null;
            try {

                beanFactory = new XmlBeanFactory(new InputStreamResource(is));

            } catch (BeansException be) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("Unable to load module configuration", be);
            }

            // check whether we have the mandatory beans (rootElement)
            if (!beanFactory.containsBean("rootElement")) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("No rootElement bean found in the module configuration file");
            }

            // fetch the rootElement
            Node rootElement = (Node) beanFactory.getBean("rootElement");

            System.out.println(rootElement.getId());

        }
    } catch (IOException ioe) {

    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:org.esupportail.lecture.domain.DomainTest.java

/**
 * @param args non argumet needed//from  w w  w.  j  a v  a 2  s  .c o m
 * @throws InternalDomainException 
 */
public static void main(final String[] args) throws InternalDomainException {
    ClassPathResource res = new ClassPathResource("properties/applicationContext.xml");
    XmlBeanFactory factory = new XmlBeanFactory(res);
    //      org.springframework.beans.factory.config.PropertyPlaceholderConfigurer prop = (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) factory.getBean("propertyConfigurer");
    facadeService = (FacadeService) factory.getBean("facadeService");

    try {
        /* Test alternative behavior */

        /* Test normal behavior */
        testGetConnectedUser();
        testGetContext();
        testGetDisplayedCategories();
        testGetVisibleCategories();
        testGetDisplayedSources();
        testGetVisibleSources();
        testGetItems();

        /* small actions */
        //         testMarkItemReadMode();
        //         testSetTreeSize();
        //         testFoldCategory();
        //         testSetItemDisplayMode();

        /* test mode EDIT */
        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetVisibleCategories();
        //         testGetVisibleSources();
        //         testSubUnSubscribeToSource();

        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetVisibleCategories();
        //         testSubUnSubscribeToCategory();

        /* test timeout values */
        //         testGetConnectedUser();
        //         testGetContext();
        //         testGetDisplayedCategories();
        //         testGetDisplayedSources();
        //         testTimeOutValues();

        // TODO (GB later) : tester pour un user OBLIGED et ALLOWED opour une source : 
        // le OBLIGED est prioritaire

    } catch (InternalExternalException e) {
        System.out.println("\n!!! EXCEPTION !!!");
        System.out.println("\n!!! Catching InternalExternalException");
        e.printStackTrace();
    } catch (InfoDomainException e) {
        System.out.println("\n!!! EXCEPTION !!!");
        System.out.println("\n!!! Catching InfoDomainException");
        e.printStackTrace();
    }
}