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:org.jasig.portal.groups.smartldap.SmartLdapGroupStore.java

private SmartLdapGroupStore() {

    // Spring tech...
    URL u = getClass().getResource("/properties/groups/SmartLdapGroupStoreConfig.xml");
    spring_context = new FileSystemXmlApplicationContext(u.toExternalForm());

    // Interval between tree rebuilds
    if (spring_context.containsBean("groupsTreeRefreshIntervalSeconds")) {
        groupsTreeRefreshIntervalSeconds = (Long) spring_context.getBean("groupsTreeRefreshIntervalSeconds");
    }/*from  w  w w  .j  av  a 2 s. c o  m*/

    // Cernunnos tech...
    runner = new ScriptRunner();
    initTask = runner.compileTask(getClass().getResource("init.crn").toExternalForm());

}

From source file:org.kuali.mobility.news.dao.NewsDaoImplTest.java

@BeforeClass
public static void createApplicationContext() {
    NewsDaoImplTest.setApplicationContext(new FileSystemXmlApplicationContext(getConfigLocations()));
}

From source file:org.kuali.student.common.test.spring.AbstractTransactionalDaoTest.java

/**
 * Loads the application context defined in the @Dao testDataFile
 * attribute. Then uses the EntityManager em to persist the beans in
 * persistList/*from w  w  w . j a v  a  2 s .  c o  m*/
 */
@Before
public void preLoadBeans() {
    for (Field f : this.getClass().getDeclaredFields()) {
        if (f.isAnnotationPresent(Dao.class)) {
            Dao dao = f.getAnnotation(Dao.class);
            if (dao.testDataFile().length() > 0) {
                ConfigurableApplicationContext ac = new FileSystemXmlApplicationContext(dao.testDataFile());
                List<?> persistList = (List<?>) ac.getBean("persistList");
                ac.close();
                for (Object o : persistList) {
                    em.persist(o);
                }
                em.flush();
            }
        }
    }
}

From source file:org.kuali.student.common.test.spring.LoadDataBean.java

public void loadData() {
    if (daoAnnotations == null || loaded || daoAnnotations.trim().isEmpty()) {
        return;/*from   w ww .ja v  a  2  s.co  m*/
    }

    // Load all the beans
    String[] classes = daoAnnotations.split(",");
    for (String line : classes) {
        try {
            String[] split = line.split("\\|");

            // Invoke the data loader for this dao
            invokeDataLoader(split[0]);

            // Load data bean file for this dao
            if (split.length > 1 && !split[1].isEmpty()) {
                String testDataFile = split[1];

                ConfigurableApplicationContext ac = new FileSystemXmlApplicationContext(testDataFile);
                List<?> persistList = (List<?>) ac.getBean("persistList");
                ac.close();
                for (Object bean : persistList) {
                    if (!em.contains(bean)) {
                        em.persist(bean);
                    }
                }
            }
            // Load sql file for this dao
            if (split.length > 2 && !split[2].isEmpty()) {

                String testDataFile = split[2];
                File sqlFile;
                if (testDataFile.startsWith("classpath:")) {
                    sqlFile = new ClassPathResource(testDataFile.substring("classpath:".length())).getFile();
                } else {
                    sqlFile = new File(testDataFile);
                }
                BufferedReader in = new BufferedReader(new FileReader(sqlFile));
                try {
                    String ln = "";
                    int lnNr = 0;

                    try {
                        while ((ln = in.readLine()) != null) {
                            lnNr++;
                            if (!ln.startsWith("/") && !ln.startsWith("--") && StringUtils.isNotBlank(ln)) {
                                ln = ln.replaceFirst("[;/]\\s*$", "");
                                em.createNativeQuery(ln).executeUpdate();
                            }
                        }
                    } catch (PersistenceException e) {
                        LOG.error("Failed statement at line " + lnNr + ": " + ln);
                        throw e;
                    }
                } finally {
                    in.close();
                }
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    loaded = true;

}

From source file:org.marketcetera.orderloader.Main.java

/**
 * Reads the orders from the supplied and sends them to the server.
 *
 * @throws Exception if there were errors.
 *//*from  w w w .  ja v  a 2  s. c om*/
protected void doProcessing() throws Exception {
    //Create the order processor
    StaticApplicationContext context = new StaticApplicationContext(
            new FileSystemXmlApplicationContext(CFG_BASE_FILE_NAME));
    String clientURL = (String) context.getBean("clientURL"); //$NON-NLS-1$
    String clientWSHost = (String) context.getBean("clientWSHost"); //$NON-NLS-1$
    Integer clientWSPort = (Integer) context.getBean("clientWSPort"); //$NON-NLS-1$
    String clientIDPrefix = (String) context.getBean("clientIDPrefix"); //$NON-NLS-1$
    ClientParameters parameters = new ClientParameters(mAuthentication.getUser(), mAuthentication.getPassword(),
            clientURL, clientWSHost, clientWSPort, clientIDPrefix);
    OrderProcessor processor = createProcessor(parameters);
    //Run the order loader and display the summary of results.
    try {
        displaySummary(new OrderLoader(mMode, mBrokerID, processor, new File(mFileName)));
    } finally {
        processor.done();
    }
}

From source file:org.marketcetera.util.spring.SpringUtilsTest.java

@Test
public void propertiesConfigurerStringSet() {
    GenericApplicationContext context = new GenericApplicationContext(
            new FileSystemXmlApplicationContext(TEST_SPRING_FILE));
    SpringUtils.addPropertiesConfigurer(context, TEST_CONFIGURER_BEAN, TEST_PROPERTIES_FILE_BEAN);
    SpringUtils.addStringBean(context, TEST_NAME_BEAN, "${" + TEST_NAME_PROP + "}");
    context.refresh();//from ww  w  .jav  a 2  s  .c o m
    assertEquals(TEST_VALUE_PROP, context.getBean(TEST_NAME_BEAN));
}

From source file:org.marketcetera.util.spring.SpringUtilsTest.java

@Test
public void propertiesConfigurerStringUnset() {
    GenericApplicationContext context = new GenericApplicationContext(
            new FileSystemXmlApplicationContext(TEST_SPRING_FILE));
    SpringUtils.addPropertiesConfigurer(context, TEST_CONFIGURER_BEAN, TEST_PROPERTIES_FILE_BEAN);
    SpringUtils.addStringBean(context, TEST_NAME_BEAN, "${" + TEST_NAME_PROP_BLANK + "}");
    context.refresh();/*w  ww . j ava  2s.  com*/
    assertEquals(StringUtils.EMPTY, context.getBean(TEST_NAME_BEAN));
}

From source file:org.marketcetera.util.spring.SpringUtilsTest.java

@Test
public void propertiesConfigurerList() {
    GenericApplicationContext context = new GenericApplicationContext(
            new FileSystemXmlApplicationContext(TEST_SPRING_FILE));
    SpringUtils.addPropertiesConfigurer(context, TEST_CONFIGURER_BEAN, TEST_PROPERTIES_FILES_BEAN);
    SpringUtils.addStringBean(context, TEST_NAME_BEAN, "${" + TEST_NAME_PROP + "}");
    context.refresh();/*from   ww  w . j a  va2s.  co  m*/
    assertEquals(TEST_VALUE_PROP_OVERRIDE, context.getBean(TEST_NAME_BEAN));
}

From source file:org.openlegacy.designtime.mains.DesignTimeExecuterImpl.java

/**
 * Get or create a project Spring application context If the project has it's own designtime context (done using
 * copyDesigntimeContext) then use it, otherwise use default according to preferences (default/rtl for now)
 * //from   w  ww .j  av a  2 s .  com
 * @param projectPath
 *            The project file system path
 * @return
 */
private synchronized ApplicationContext getOrCreateApplicationContext(File projectPath) {

    if (defaultDesigntimeApplicationContext == null) {
        defaultDesigntimeApplicationContext = new ClassPathXmlApplicationContext(
                "/openlegacy-default-designtime-context.xml");
    }

    // no project path specified - return default context
    if (projectPath == null) {
        return defaultDesigntimeApplicationContext;
    }

    ApplicationContext projectApplicationContext = projectsDesigntimeAplicationContexts
            .get(projectPath.getAbsolutePath());

    if (projectApplicationContext == null) {
        File designtimeContextFile = new File(projectPath,
                DesignTimeExecuter.CUSTOM_DESIGNTIME_CONTEXT_RELATIVE_PATH);
        if (designtimeContextFile.exists()) {
            // in windows add / to the file path (http://www.ehour.nl/forum/viewtopic.php?t=1113)
            // #453 - in linux need throws an error when having only single /
            String prefix = OsUtils.isWindows() && designtimeContextFile.getAbsolutePath().startsWith("/") ? ""
                    : "/";
            projectApplicationContext = new FileSystemXmlApplicationContext(
                    prefix + designtimeContextFile.getAbsolutePath());
        } else {
            String embeddedDesigntimeContextFile = getEmbeddedDesigntimeContextFile(projectPath);
            String designtimeContextType = getPreferences(projectPath)
                    .get(PreferencesConstants.DESIGNTIME_CONTEXT);
            // don't re-initialize the default context on project level if exists on root level
            // (defaultDesigntimeApplicationContext)
            if (designtimeContextType == null || designtimeContextType.equals(DEFAULT_CONTEXT)) {
                projectApplicationContext = defaultDesigntimeApplicationContext;
            } else {
                projectApplicationContext = new ClassPathXmlApplicationContext(embeddedDesigntimeContextFile);
            }
        }
        projectsDesigntimeAplicationContexts.put(projectPath.getAbsolutePath(), projectApplicationContext);
    }
    return projectApplicationContext;

}

From source file:org.opens.tanaguru.cli.Tanaguru.java

/**
 *
 * @param tanaguruHome/*from   www. j ava2  s  .c  om*/
 */
private void initServices(String tanaguruHome) {
    ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext(
            tanaguruHome + "/" + APPLICATION_CONTEXT_FILE_PATH);
    BeanFactory springBeanFactory = springApplicationContext;
    auditService = (AuditService) springBeanFactory.getBean("auditService");
    auditDataService = (AuditDataService) springBeanFactory.getBean("auditDataService");
    webResourceDataService = (WebResourceDataService) springBeanFactory.getBean("webResourceDataService");
    webResourceStatisticsDataService = (WebResourceStatisticsDataService) springBeanFactory
            .getBean("webResourceStatisticsDataService");
    processResultDataService = (ProcessResultDataService) springBeanFactory.getBean("processResultDataService");
    processRemarkDataService = (ProcessRemarkDataService) springBeanFactory.getBean("processRemarkDataService");
    parameterDataService = (ParameterDataService) springBeanFactory.getBean("parameterDataService");
    parameterElementDataService = (ParameterElementDataService) springBeanFactory
            .getBean("parameterElementDataService");
    auditService.add(this);
}