Example usage for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext

List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext.

Prototype

public FileSystemXmlApplicationContext(String... configLocations) throws BeansException 

Source Link

Document

Create a new FileSystemXmlApplicationContext, loading the definitions from the given XML files and automatically refreshing the context.

Usage

From source file:com.github.weikengc.spring.jpdl.config.JpdlNamespaceHandlerTest.java

private static ApplicationContext newApplicationContextFor(File springXmlFile) {
    return new FileSystemXmlApplicationContext(springXmlFile.getAbsolutePath());
}

From source file:org.danann.cernunnos.spring.ApplicationContextTask.java

private synchronized ApplicationContext getApplicationContext(URL config, boolean useCache) {

    if (!useCache || !config.equals(prevUrl)) {
        prevBeans = new FileSystemXmlApplicationContext(config.toExternalForm());
        prevUrl = config;//from ww w . j a  v  a  2 s  .  com
    }

    return prevBeans;

}

From source file:example.hibernatetool.SpringComponentConfiguration.java

protected ApplicationContext constructContext(String[] appContextResources) {
    return new FileSystemXmlApplicationContext(appContextResources);
}

From source file:com.qualogy.qafe.business.resource.java.spring.SpringContext.java

private org.springframework.context.ApplicationContext getQafeSpringContext(ApplicationContext context,
        SpringContextResource springContextResource) {
    org.springframework.context.ApplicationContext springContext = null;
    String configFiles = springContextResource.getConfigFiles();
    String[] xmlConfigFiles = configFiles.split(",");
    for (int i = 0; i < xmlConfigFiles.length; i++) {
        String xmlConfigFile = xmlConfigFiles[i];
        if (!xmlConfigFile.startsWith("classpath")) {
            xmlConfigFiles[i] = resolveXMLConfigFile(context.getRoot(), xmlConfigFile);
        }//from w  ww .  j  av  a 2s  .  c o  m
        Logger.getLogger(this.getClass().getName()).log(Level.INFO, "XMLFile " + xmlConfigFiles[i]);
    }

    springContext = new FileSystemXmlApplicationContext(xmlConfigFiles);
    return springContext;
}

From source file:org.jbpm.formbuilder.server.RESTFormServiceTest.java

public void testSetContextOK() throws Exception {
    RESTFormService restService = new RESTFormService();
    URL pathToClasses = getClass().getResource("/FormBuilder.properties");
    String filePath = pathToClasses.toExternalForm();
    //assumes compilation is in target/classes
    filePath = filePath.replace("target/classes/FormBuilder.properties", "src/main/webapp");
    filePath = filePath + "/WEB-INF/springComponents.xml";
    FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(filePath);
    ServiceFactory.getInstance().setBeanFactory(ctx);
    ServletContext context = EasyMock.createMock(ServletContext.class);

    EasyMock.replay(context);/*from w ww.  j  a v a2  s.  co  m*/
    restService.setContext(context);
    EasyMock.verify(context);

    FormDefinitionService service = restService.getFormService();
    assertNotNull("service shouldn't be null", service);
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.core.ResourceFactory.java

/**
 * Constructor parameterized by the path to the configuration file.
 *
 * @param location location of the configuration file.
 *///from w w  w  . j a  v a  2 s . c  o m
public ResourceFactory(String location) {
    context = new FileSystemXmlApplicationContext(location);
}

From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationManager.java

private void loadMadStoreConfigurationFromFilesystem() {
    String contextPath = "file:" + madStoreHome + SEPARATOR + "conf" + SEPARATOR + MADSTORE_CONFIGURATION_NAME;
    try {/*from  w w w  .j  a v  a2 s . com*/
        ApplicationContext context = new FileSystemXmlApplicationContext(contextPath);
        Map configurations = context.getBeansOfType(MadStoreConfigurationBean.class);
        if (configurations.size() != 1) {
            LOG.warn("Error loading MadStore configuration from path: {}", contextPath);
            madStoreConfiguration = null;
        } else {
            LOG.info("MadStore configuration successfully loaded from path: {}", contextPath);
            madStoreConfiguration = (MadStoreConfigurationBean) configurations.values().iterator().next();
        }
    } catch (Exception ex) {
        LOG.warn(ex.getMessage(), ex);
        LOG.warn("Error loading MadStore configuration from path: {}", contextPath);
        throw new MadStoreConfigurationException(ex.getMessage(), ex);
    }
}

From source file:it.cilea.osd.jdyna.web.controller.ImportAnagraficaObject.java

/** Performa l'import da file xml di configurazioni di oggetti;
 *  Sull'upload del file la configurazione dell'oggetto viene caricato come contesto di spring
 *  e salvate su db./*from  w w w . java2  s  .c  om*/
 */
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object,
        BindException errors) throws RuntimeException, IOException {

    FileUploadConfiguration bean = (FileUploadConfiguration) object;
    MultipartFile file = (CommonsMultipartFile) bean.getFile();
    File a = null;

    //creo il file temporaneo che sara' caricato come contesto di spring per caricare la configurazione degli oggetti
    a = File.createTempFile("jdyna", ".xml", new File(path));
    file.transferTo(a);

    ApplicationContext context = null;
    try {
        context = new FileSystemXmlApplicationContext(new String[] { "file:" + a.getAbsolutePath() });
    } catch (XmlBeanDefinitionStoreException exc) {
        //cancello il file dalla directory temporanea
        logger.warn("Error during the configuration import from file: " + file.getOriginalFilename(), exc);
        a.delete();
        saveMessage(request, getText("action.file.nosuccess.upload", new Object[] { exc.getMessage() },
                request.getLocale()));
        return new ModelAndView(getErrorView());
    }
    //cancello il file dalla directory temporanea
    a.delete();
    String[] tpDefinitions = context.getBeanDefinitionNames(); //getBeanNamesForType(tpClass);
    AnagraficaObject<P, TP> anagraficaObject = null;

    String idStringAnagraficaObject = request.getParameter("id");
    Integer pkey = Integer.parseInt(idStringAnagraficaObject);
    anagraficaObject = applicationService.get(modelClass, pkey);

    //la variabile i conta le tipologie caricate con successo
    int i = 0;
    //la variabile j conta le tipologie non caricate
    int j = 0;

    for (String tpNameDefinition : tpDefinitions) {
        try {
            ImportPropertyAnagraficaUtil importBean = (ImportPropertyAnagraficaUtil) context
                    .getBean(tpNameDefinition);
            anagraficaUtils.importProprieta(anagraficaObject, importBean);
        } catch (Exception ecc) {
            saveMessage(request, getText("action.file.nosuccess.metadato.upload",
                    new Object[] { ecc.getMessage() }, request.getLocale()));
            j++;
            i--;
        }
        i++;
    }
    //pulisco l'anagrafica
    anagraficaObject.pulisciAnagrafica();
    applicationService.saveOrUpdate(modelClass, anagraficaObject);

    saveMessage(request,
            getText("action.file.success.upload", new Object[] { new String("Totale Oggetti Caricati:" + (i + j)
                    + "" + "[" + i + " caricate con successo/" + j + " fallito caricamento]") },
                    request.getLocale()));

    return new ModelAndView(getDetailsView());
}

From source file:org.mapfish.print.ShellMapPrinter.java

public ShellMapPrinter(String[] args) throws IOException {
    try {/*from   www  . ja v  a  2 s.c om*/
        GetOptions.parse(args, this);
    } catch (InvalidOption invalidOption) {
        help(invalidOption.getMessage());
    }
    configureLogs();
    this.context = new ClassPathXmlApplicationContext(DEFAULT_SPRING_CONTEXT);

    if (springConfig != null) {
        this.context = new FileSystemXmlApplicationContext(
                new String[] { "classpath:/" + DEFAULT_SPRING_CONTEXT, springConfig });
    }
}

From source file:org.apache.smscserver.main.CommandLine.java

/**
 * Get the configuration object./*from ww  w  . j  a  v a 2 s .  c o m*/
 */
protected SmscServer getConfiguration(String[] args) throws Exception {

    SmscServer server = null;
    if (args.length == 0) {
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("-default")) {
        // supported for backwards compatibility, but not documented
        System.out.println("The -default switch is deprecated, please use --default instead");
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--default")) {
        System.out.println("Using default configuration");
        server = new SmscServerFactory().createServer();
    } else if ((args.length == 1) && args[0].equals("--help")) {
        this.usage();
    } else if ((args.length == 1) && args[0].equals("-?")) {
        this.usage();
    } else if (args.length == 1) {
        System.out.println("Using XML configuration file " + args[0] + "...");
        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[0]);

        if (ctx.containsBean("server")) {
            server = (SmscServer) ctx.getBean("server");
        } else {
            String[] beanNames = ctx.getBeanNamesForType(SmscServer.class);
            if (beanNames.length == 1) {
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else if (beanNames.length > 1) {
                System.err
                        .println("Using the first server defined in the configuration, named " + beanNames[0]);
                server = (SmscServer) ctx.getBean(beanNames[0]);
            } else {
                System.err.println("XML configuration does not contain a server configuration");
            }
        }
    } else {
        this.usage();
    }

    return server;
}