List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:org.apache.ftpserver.main.CommandLine.java
/** * Get the configuration object.// w w w .j a v a2 s . c om */ protected FtpServer getConfiguration(String[] args) throws Exception { FtpServer server = null; if (args.length == 0) { System.out.println("Using default configuration"); server = new FtpServerFactory().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 FtpServerFactory().createServer(); } else if ((args.length == 1) && args[0].equals("--default")) { System.out.println("Using default configuration"); server = new FtpServerFactory().createServer(); } else if ((args.length == 1) && args[0].equals("--help")) { usage(); } else if ((args.length == 1) && args[0].equals("-?")) { 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 = (FtpServer) ctx.getBean("server"); } else { String[] beanNames = ctx.getBeanNamesForType(FtpServer.class); if (beanNames.length == 1) { server = (FtpServer) ctx.getBean(beanNames[0]); } else if (beanNames.length > 1) { System.out .println("Using the first server defined in the configuration, named " + beanNames[0]); server = (FtpServer) ctx.getBean(beanNames[0]); } else { System.err.println("XML configuration does not contain a server configuration"); } } } else { usage(); } return server; }
From source file:org.bigtester.ate.model.casestep.CaseTypeService.java
/** * {@inheritDoc}/* ww w .j a v a 2 s. c o m*/ */ @Override public void doStep() throws StepExecutionException2, PageValidationException2, RuntimeDataException { String testCaseFileName = getTestCaseFileName(); WebDriver mainDriver; ApplicationContext context; context = new FileSystemXmlApplicationContext(testCaseFileName); IMyWebDriver myWebD = (IMyWebDriver) GlobalUtils.findMyWebDriver(context); mainDriver = myWebD.getWebDriverInstance(); try { super.setCurrentWebDriver(myWebD); setStepThinkTime(getParentTestCase().getStepThinkTime()); /* remove all the asserters */ TestCase newTestcase = (TestCase) GlobalUtils.findTestCaseBean(context); newTestcase.cleanUpAsserters(); newTestcase.goSteps(); /* transfer all the dataholders value to parent test case */ for (int j = 0; j < getDataHolders().size(); j++) { IDataParser parentDataHolder = getDataHolders().get(j); if (parentDataHolder instanceof ICaseServiceParsedDataParser) { ICaseServiceParsedDataParser parentDataHolderTemp = (ICaseServiceParsedDataParser) parentDataHolder; parentDataHolderTemp.setStrDataValue( ((IStepInputData) context.getBean(parentDataHolderTemp.getSubCaseMappedDataHolderID())) .getStrDataValue()); } } } catch (Throwable t) { // NOPMD mainDriver.quit(); throw t; } }
From source file:org.danann.cernunnos.runtime.web.CernunnosPortlet.java
@SuppressWarnings("unchecked") @Override/* w w w. ja v a 2 s . co m*/ public void init() throws PortletException { PortletConfig config = getPortletConfig(); // Load the context, if present... try { // Bootstrap the portlet Grammar instance... final Grammar root = XmlGrammar.getMainGrammar(); final InputStream inpt = CernunnosPortlet.class.getResourceAsStream("portlet.grammar"); // Can't rely on classpath:// protocol handler... final Document doc = new SAXReader().read(inpt); final Task k = new ScriptRunner(root).compileTask(doc.getRootElement()); final RuntimeRequestResponse req = new RuntimeRequestResponse(); final ReturnValueImpl rslt = new ReturnValueImpl(); req.setAttribute(Attributes.RETURN_VALUE, rslt); k.perform(req, new RuntimeRequestResponse()); Grammar g = (Grammar) rslt.getValue(); runner = new ScriptRunner(g); // Choose a context location & load it if it exists... String defaultLoc = "/WEB-INF/" + config.getPortletName() + "-portlet.xml"; URL defaultUrl = getPortletConfig().getPortletContext().getResource(defaultLoc); URL u = Settings.locateContextConfig( getPortletConfig().getPortletContext().getResource("/").toExternalForm(), config.getInitParameter(CONFIG_LOCATION_PARAM), defaultUrl); if (u != null) { // There *is* a resource mapped to this path name... spring_context = new FileSystemXmlApplicationContext(u.toExternalForm()); } if (log.isTraceEnabled()) { log.trace("Loaction of spring context (null means none): " + u); } // Load the Settings... Map<String, String> settingsMap = new HashMap<String, String>(); // default... if (spring_context != null && spring_context.containsBean("settings")) { settingsMap = (Map<String, String>) spring_context.getBean("settings"); } settings = Settings.load(settingsMap); } catch (Throwable t) { String msg = "Failure in CernunnosPortlet.init()"; throw new PortletException(msg, t); } }
From source file:edu.harvard.i2b2.workplace.util.WorkplaceUtil.java
/** * Return the ontology spring config/* w w w . j a v a2 s .co m*/ * @return */ public BeanFactory getSpringBeanFactory() { if (beanFactory == null) { String appDir = null; try { //read application directory property file via classpath Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME); //read directory property appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES); } catch (I2B2Exception e) { log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath "); } if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + "WorkplaceApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "WorkplaceApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:WebApp.Action.BookAction.java
public String Search_Book_WebService() throws Exception { String type = ServletActionContext.getRequest().getParameter("type"); String role = ServletActionContext.getRequest().getParameter("role"); String search = ServletActionContext.getRequest().getParameter("search"); ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:WebApp/WebService/WebService.xml"); IWebService web_service = (IWebService) ctx.getBean("WebService"); List<Book> book_list = web_service.Query(type, search, role); ServletActionContext.getRequest().setAttribute("book_list", book_list); return SUCCESS; }
From source file:edu.harvard.i2b2.im.util.IMUtil.java
/** * Return the ontology spring config// ww w . j av a 2 s. c om * @return */ public BeanFactory getSpringBeanFactory() { if (beanFactory == null) { String appDir = null; try { //read application directory property file via classpath Properties loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME); //read directory property appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES); } catch (I2B2Exception e) { log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath "); } if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + "IMApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "IMApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:org.pentaho.plugin.j2ee.ServletAdapterContentGenerator.java
private ConfigurableApplicationContext getSpringBeanFactory() { final PluginClassLoader loader = (PluginClassLoader) pm.getClassLoader(PLUGIN_ID); File f = new File(loader.getPluginDir(), "plugin.spring.xml"); //$NON-NLS-1$ if (f.exists()) { logger.debug("Found plugin spring file @ " + f.getAbsolutePath()); //$NON-NLS-1$ ConfigurableApplicationContext context = new FileSystemXmlApplicationContext( "file:" + f.getAbsolutePath()) { //$NON-NLS-1$ @Override//from w w w. j a v a2s . co m protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) { beanDefinitionReader.setBeanClassLoader(loader); } @Override protected void prepareBeanFactory(ConfigurableListableBeanFactory clBeanFactory) { super.prepareBeanFactory(clBeanFactory); clBeanFactory.setBeanClassLoader(loader); } /** Critically important to override this and return the desired CL **/ @Override public ClassLoader getClassLoader() { return loader; } }; return context; } throw new IllegalStateException("no plugin.spring.xml file found"); //$NON-NLS-1$ }
From source file:org.trpr.platform.runtime.impl.bootstrapext.spring.ApplicationContextFactory.java
/** * Returns the common Spring beans application context that is intended as parent of all application contexts created by the runtime * @return the AbstractApplicationContext for the XML identified by {@link RuntimeConstants#COMMON_SPRING_BEANS_CONFIG} * TODO : Need a better way than to expose this than as a static method. *///from ww w . j a v a 2 s .c o m public static AbstractApplicationContext getCommonBeansContext() { // commonBeansContext is the base context for all application contexts, so load it if not loaded already. AbstractApplicationContext commonBeansContext = (AbstractApplicationContext) ApplicationContextFactory.appContextMap .get((COMMON_BEANS_CONTEXT_NAME).toLowerCase()); if (commonBeansContext == null) { File springBeansFile = FileLocator.findUniqueFile(RuntimeConstants.COMMON_SPRING_BEANS_CONFIG); // add the "file:" prefix to file names to get around strange behavior of FileSystemXmlApplicationContext that converts absolute path // to relative path commonBeansContext = new FileSystemXmlApplicationContext( FILE_PREFIX + springBeansFile.getAbsolutePath()); ApplicationContextFactory.appContextMap.put(COMMON_BEANS_CONTEXT_NAME.toLowerCase(), commonBeansContext); } return commonBeansContext; }
From source file:edu.harvard.i2b2.plugin.pb.util.QueryProcessorUtil.java
/** * Function to create spring bean factory * /*from w w w. j a v a 2 s .c o m*/ * @return BeanFactory */ public BeanFactory getSpringBeanFactory() { if (beanFactory == null) { String appDir = null; try { // read application directory property file via classpath loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME); // read directory property appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES); } catch (I2B2Exception e) { log.error(APPLICATION_DIRECTORY_PROPERTIES_FILENAME + "could not be located from classpath "); } String springContextFileName = loadProperties .getProperty(APPLICATION_SPRINGCONTEXT_FILENAME_PROPERTIES); if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + springContextFileName); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + springContextFileName); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:com.apporiented.hermesftp.FtpServerApp.java
private static ApplicationContext getApplicationContext(String beanRes, File file) { ApplicationContext appContext;//from www .j av a 2 s . co m if (file.exists()) { appContext = new FileSystemXmlApplicationContext(new String[] { beanRes }); } else { log.error("Hermes FTP application context not found: " + file + ". Trying to read context from classpath..."); appContext = new ClassPathXmlApplicationContext(new String[] { "/" + FtpConstants.DEFAULT_BEAN_RES }); } return appContext; }