List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException
From source file:org.apache.oodt.cas.catalog.cli.action.LoadCatalogRepositoryCliAction.java
@Override public void execute(ActionMessagePrinter printer) throws CmdLineActionException { try {/*from w w w. ja v a2s. c o m*/ Validate.notNull(catalogRepositoryId, "Must specify catalogRepositoryId"); Validate.notNull(beanRepo, "Must specify beanRepo"); FileSystemXmlApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { this.beanRepo }, false); appContext.setClassLoader(new Serializer().getClassLoader()); appContext.refresh(); CatalogRepositoryFactory factory = (CatalogRepositoryFactory) appContext .getBean(this.catalogRepositoryId, CatalogRepositoryFactory.class); CatalogRepository catalogRepository = factory.createRepository(); Set<Catalog> catalogs = catalogRepository.deserializeAllCatalogs(); printer.println("Deserialized Catalogs: " + catalogs.toString()); for (Catalog catalog : catalogs) { printer.println("Adding Catalog: " + catalog); getClient().addCatalog(catalog); } } catch (Exception e) { throw new CmdLineActionException("Failed to load catalogs from bean repo : " + e.getMessage(), e); } }
From source file:org.apache.oodt.cas.catalog.cli.action.LoadCatalogsCliAction.java
@Override public void execute(ActionMessagePrinter printer) throws CmdLineActionException { try {//from w w w . j a va 2 s .c o m Validate.notNull(beanRepo, "Must specify beanRepo"); FileSystemXmlApplicationContext repoAppContext = new FileSystemXmlApplicationContext( new String[] { this.beanRepo }, false); repoAppContext.setClassLoader(new Serializer().getClassLoader()); repoAppContext.refresh(); @SuppressWarnings("unchecked") Map<String, Catalog> catalogs = repoAppContext.getBeansOfType(Catalog.class); for (Catalog catalog : catalogs.values()) { printer.println("Adding catalog: " + catalog.getId()); getClient().addCatalog(catalog); } } catch (Exception e) { throw new CmdLineActionException("Failed to load catalogs : " + e.getMessage(), e); } }
From source file:org.marketcetera.client.ClientImpl.java
private void connect() throws ConnectionException { if (mParameters.getURL() == null || mParameters.getURL().trim().isEmpty()) { throw new ConnectionException(Messages.CONNECT_ERROR_NO_URL); }//from w ww . j av a 2 s .c o m if (mParameters.getUsername() == null || mParameters.getUsername().trim().isEmpty()) { throw new ConnectionException(Messages.CONNECT_ERROR_NO_USERNAME); } if (mParameters.getHostname() == null || mParameters.getHostname().trim().isEmpty()) { throw new ConnectionException(Messages.CONNECT_ERROR_NO_HOSTNAME); } if (mParameters.getPort() < 1 || mParameters.getPort() > 0xFFFF) { throw new ConnectionException( new I18NBoundMessage1P(Messages.CONNECT_ERROR_INVALID_PORT, mParameters.getPort())); } try { StaticApplicationContext parentCtx = new StaticApplicationContext(); SpringUtils.addStringBean(parentCtx, "brokerURL", //$NON-NLS-1$ mParameters.getURL()); SpringUtils.addStringBean(parentCtx, "runtimeUsername", mParameters.getUsername()); //$NON-NLS-1$ SpringUtils.addStringBean(parentCtx, "runtimePassword", mParameters == null //$NON-NLS-1$ ? null : String.valueOf(mParameters.getPassword())); parentCtx.refresh(); AbstractApplicationContext ctx; try { ctx = new FileSystemXmlApplicationContext( new String[] { "file:" + ApplicationBase.CONF_DIR + "client.xml" }, //$NON-NLS-1$ parentCtx); } catch (BeansException e) { ctx = new ClassPathXmlApplicationContext(new String[] { "client.xml" }, //$NON-NLS-1$ parentCtx); } ctx.registerShutdownHook(); ctx.start(); setContext(ctx); SpringConfig cfg = SpringConfig.getSingleton(); if (cfg == null) { throw new ConnectionException(Messages.CONNECT_ERROR_NO_CONFIGURATION); } mServiceClient = new org.marketcetera.util.ws.stateful.Client(mParameters.getHostname(), mParameters.getPort(), ClientVersion.APP_ID); mServiceClient.login(mParameters.getUsername(), mParameters.getPassword()); mService = mServiceClient.getService(Service.class); mJmsMgr = new JmsManager(cfg.getIncomingConnectionFactory(), cfg.getOutgoingConnectionFactory(), this); startJms(); mServerAlive = true; notifyServerStatus(true); mHeart = new Heart(); mHeart.start(); ClientIDFactory idFactory = new ClientIDFactory(mParameters.getIDPrefix(), this); idFactory.init(); Factory.getInstance().setOrderIDFactory(idFactory); } catch (Throwable t) { internalClose(); ExceptUtils.interrupt(t); if (t.getCause() instanceof RemoteProxyException) { RemoteProxyException ex = (RemoteProxyException) t.getCause(); if (IncompatibleComponentsException.class.getName().equals(ex.getServerName())) { throw new ConnectionException(t, new I18NBoundMessage1P(Messages.ERROR_CONNECT_INCOMPATIBLE_DEDUCED, ex.getMessage())); } } else if (t.getCause() instanceof IncompatibleComponentsException) { IncompatibleComponentsException ex = (IncompatibleComponentsException) t.getCause(); throw new ConnectionException(t, new I18NBoundMessage2P(Messages.ERROR_CONNECT_INCOMPATIBLE_DIRECT, ClientVersion.APP_ID, ex.getServerVersion())); } throw new ConnectionException(t, new I18NBoundMessage4P(Messages.ERROR_CONNECT_TO_SERVER, mParameters.getURL(), mParameters.getUsername(), mParameters.getHostname(), mParameters.getPort())); } mLastConnectTime = new Date(); }
From source file:org.marketcetera.core.ApplicationContainer.java
/** * Generates the base application context with which to run. * * @return a <code>ConfigurableApplicationContext</code> value *///from w w w . j a v a 2 s .c om protected ConfigurableApplicationContext generateContext() { return new FileSystemXmlApplicationContext(new String[] { "file:" + CONF_DIR + contextFilename }, //$NON-NLS-1$ null); }
From source file:org.red5.server.ContextLoader.java
/** * Loads context (Red5 application) and stores it in context map, then adds * it's beans to parent (that is, Red5) * * @param name Context name/*from w ww .j a v a2 s . c o m*/ * @param config Filename */ protected void loadContext(String name, String config) { ApplicationContext context = new FileSystemXmlApplicationContext(new String[] { config }, parentContext); contextMap.put(name, context); // add the context to the parent, this will be red5.xml ConfigurableBeanFactory factory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); // Register context in parent bean factory factory.registerSingleton(name, context); }
From source file:org.robospring.RoboSpring.java
private static AbstractXmlApplicationContext createContext(String contextConfigLocation) { String scheme;//from www .java 2s . co m String resourceName; try { URI url = new URI(contextConfigLocation); scheme = url.getScheme(); if (scheme == null) { scheme = "classpath"; } resourceName = url.getPath(); } catch (URISyntaxException e) { log.warn("ContextConfigLocation does not contain a scheme identifier - using classpath:/ as default."); // Trying to load from class path with this name scheme = "classpath"; resourceName = contextConfigLocation; } if ("classpath".equals(scheme)) { if (parentContext != null) { String[] configLocations = new String[] { resourceName }; return new ClassPathXmlApplicationContext(configLocations, parentContext) { protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new AndroidContextAwareProcessor(androidAppContext)); super.prepareBeanFactory(beanFactory); }; }; } else { return new ClassPathXmlApplicationContext(resourceName); } } else if ("file".equals(scheme)) { if (parentContext != null) { String[] configLocations = new String[] { resourceName }; return new FileSystemXmlApplicationContext(configLocations, parentContext) { protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new AndroidContextAwareProcessor(androidAppContext)); super.prepareBeanFactory(beanFactory); }; }; } else { return new FileSystemXmlApplicationContext(resourceName); } } else { throw new IllegalArgumentException( "Cannot handle scheme '" + scheme + "' for loading Spring configuration."); } }
From source file:org.springframework.xd.dirt.stream.FileSourceModuleTests.java
@Test public void testSplitterUsesIterator() throws Exception { System.out.println(System.getProperty("user.dir")); ConfigurableApplicationContext ctx = new FileSystemXmlApplicationContext( new String[] { "../modules/common/file-source-common-context.xml", "classpath:org/springframework/xd/dirt/stream/ppc-context.xml" }, false);//from w w w.j a v a 2 s .c o m StandardEnvironment env = new StandardEnvironment(); Properties props = new Properties(); props.setProperty("fixedDelay", "5"); props.setProperty("timeUnit", "SECONDS"); props.setProperty("initialDelay", "0"); props.setProperty("withMarkers", "false"); PropertiesPropertySource pps = new PropertiesPropertySource("props", props); env.getPropertySources().addLast(pps); env.setActiveProfiles("use-contents-with-split"); ctx.setEnvironment(env); ctx.refresh(); FileSplitter splitter = ctx.getBean(FileSplitter.class); File foo = File.createTempFile("foo", ".txt"); final AtomicReference<Method> splitMessage = new AtomicReference<>(); ReflectionUtils.doWithMethods(FileSplitter.class, new MethodCallback() { @Override public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { method.setAccessible(true); splitMessage.set(method); } }, new MethodFilter() { @Override public boolean matches(Method method) { return method.getName().equals("splitMessage"); } }); Object result = splitMessage.get().invoke(splitter, new GenericMessage<File>(foo)); assertThat(result, instanceOf(Iterator.class)); ctx.close(); foo.delete(); }