List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:com.snp.site.init.SystemInit.java
public static void initSystemStaitcData(ServletContextEvent sce) { try {//from w ww .j a v a 2s .co m // siteStrMap = getMapFromePropFile(getClassPath() + "/lang", // "txt"); // snpStrMap = getMapFromePropFile(getClassPath() + "/lang", "txt"); FtpServer ftpserver = null; String config = "conf/ftp/conf/ftpd-typical.xml"; FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(config); String[] beanNames = ctx.getBeanNamesForType(FtpServer.class); ftpserver = (FtpServer) ctx.getBean(beanNames[0]); ftpserver.start(); DefaultFtpServer defaultFtpServer = (DefaultFtpServer) ftpserver; System.out.println(defaultFtpServer); // PropertiesUserManager propertiesUserManager = // (PropertiesUserManager) defaultFtpServer.getUserManager(); SystemInit.serverFtp = defaultFtpServer; } catch (Exception e) { log.error("", e); } }
From source file:edu.harvard.i2b2.crc.util.QueryProcessorUtil.java
/** * Function to create spring bean factory * /*from w ww.java2s .com*/ * @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 "); } if (appDir != null) { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "file:" + appDir + "/" + "CRCApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } else { FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( "classpath:" + "CRCApplicationContext.xml"); beanFactory = ctx.getBeanFactory(); } } return beanFactory; }
From source file:com.revolsys.gis.tools.ProcessorPipelineTool.java
private void processFile(final File sourceFile, final File targetFile, final File logFile) { final long startTime = System.currentTimeMillis(); if (this.excludePattern != null) { try {/* www .jav a 2 s .c om*/ if (sourceFile.getCanonicalPath().matches(this.excludePattern)) { return; } } catch (final IOException e) { log.error(e.getMessage(), e); } } final ThreadLocalFileAppender localAppender = ThreadLocalFileAppender.getAppender(); if (localAppender != null) { final File parentFile = logFile.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } localAppender.setLocalFile(logFile.getAbsolutePath()); } log.info("Processing file '" + sourceFile + "' to '" + targetFile + "'"); System.out.println("Processing file '" + sourceFile + "' to '" + targetFile + "'"); System.setProperty("sourceFile", sourceFile.getAbsolutePath()); System.setProperty("targetFile", targetFile.getAbsolutePath()); final BeanFactory beans = new FileSystemXmlApplicationContext("file:" + this.scriptFile.getAbsolutePath()); try { final File parentFile = targetFile.getParentFile(); if (parentFile != null) { parentFile.mkdirs(); } final Object bean = beans.getBean("pipeline"); final ProcessNetwork pipeline = (ProcessNetwork) bean; pipeline.startAndWait(); } catch (final BeanCreationException e) { final Throwable cause = getBeanExceptionCause(e); cause.printStackTrace(); } final long endTime = System.currentTimeMillis(); final long time = endTime - startTime; long seconds = time / 1000; final long minutes = seconds / 60; seconds = seconds % 60; log.info(minutes + " minutes " + seconds + " seconds"); System.out.println(minutes + " minutes " + seconds + " seconds"); }
From source file:org.usapi.BaseSeleniumTest.java
private AbstractXmlApplicationContext getElements() { AbstractXmlApplicationContext elements = null; String appElementsXML = PropertyHelper.getApplicationElementsXML(); data = PropertyHelper.getData();//from w w w .j a v a 2 s. co m if (data != null) { // 'file:' prefix is needed to work around spring issue, where spring will change // any absolute Unix file path (beginning with '/') to resource path by stripping // the leading '/'. appElementsXML = "file:" + DataInjector.inject(appElementsXML, data); log.info("Loading application elements from " + appElementsXML); elements = new FileSystemXmlApplicationContext(appElementsXML); } else { try { log.info("Loading application elements from " + appElementsXML); elements = new ClassPathXmlApplicationContext(appElementsXML); } catch (Exception e) { log.error(e.getMessage()); } } return elements; }
From source file:com.doculibre.constellio.services.ConnectorManagerServicesImpl.java
@Override public void synchronizeWithDatabase(ConnectorManager connectorManager) { ConnectorTypeServices connectorTypeServices = ConstellioSpringUtils.getConnectorTypeServices(); // Add missing connector types List<String> connectorTypeNames = getConnectorTypes(connectorManager); for (String connectorTypeName : connectorTypeNames) { ConnectorType connectorType = connectorTypeServices.get(connectorTypeName); if (connectorType == null) { connectorType = new ConnectorType(); connectorType.setName(connectorTypeName); File connectorsDir = ConstellioSpringUtils.getGoogleConnectorsDir(); File connectorTypeDir = new File(connectorsDir, connectorType.getName()); File iconFile = new File(connectorTypeDir, "icon.gif"); if (iconFile.exists()) { try { byte[] iconBytes = FileUtils.readFileToByteArray(iconFile); connectorType.setIconFileContent(iconBytes); } catch (IOException e) { throw new RuntimeException(e); }//w w w . ja v a2s. co m } File connectorTypeMetaXmlFile = new File(connectorTypeDir, "connectorTypeMeta.xml"); if (connectorTypeMetaXmlFile.exists()) { String path = connectorTypeMetaXmlFile.toURI().toString(); BeanFactory connectorTypeMeta = new FileSystemXmlApplicationContext(path); if (connectorTypeMeta.containsBean("searchResultPanelClassName")) { String searchResultPanelClassName = (String) connectorTypeMeta .getBean("searchResultPanelClassName"); connectorType.setSearchResultPanelClassName(searchResultPanelClassName); } if (connectorTypeMeta.containsBean("initInstanceHandlerClassName")) { String initInstancePluginClassName = (String) connectorTypeMeta .getBean("initInstanceHandlerClassName"); connectorType.setInitInstanceHandlerClassName(initInstancePluginClassName); } } connectorType.setConnectorManager(connectorManager); connectorTypeServices.makePersistent(connectorType); } } // Remove deleted connector types List<ConnectorType> dbConnectorType = connectorTypeServices.list(); for (ConnectorType connectorType : dbConnectorType) { if (!connectorTypeNames.contains(connectorType.getName())) { connectorTypeServices.makeTransient(connectorType); } } ConnectorInstanceServices connectorInstanceServices = ConstellioSpringUtils.getConnectorInstanceServices(); BackupServices backupServices = ConstellioSpringUtils.getBackupServices(); List<ConnectorInstance> connectorInstances = connectorInstanceServices.list(); for (ConnectorInstance connectorInstance : connectorInstances) { String connectorName = connectorInstance.getName(); String connectorTypeName = connectorInstance.getConnectorType().getName(); boolean existingConnector = isExistingConnector(connectorManager, connectorName); boolean hasConfigBackup = backupServices.hasConfigBackup(connectorName, connectorTypeName); if (!existingConnector && hasConfigBackup) { backupServices.restoreConfigBackup(connectorName, connectorTypeName); } else if (existingConnector && !hasConfigBackup) { backupServices.backupConfig(connectorName, connectorTypeName); } } }
From source file:ome.services.ldap.LdapTest.java
/** * old etc/omero.properties:/*w w w. j a va 2 s . com*/ * ===================== * omero.ldap.config=false * omero.ldap.urls=ldap://localhost:389 * omero.ldap.username= * omero.ldap.password= * omero.ldap.base=ou=example,o=com * omero.ldap.new_user_group=default * omero.ldap.groups= * omero.ldap.attributes=objectClass * omero.ldap.values=person * # for ssl connection on ldaps://localhost:636 * omero.ldap.protocol= * omero.ldap.keyStore= * omero.ldap.keyStorePassword= * omero.ldap.trustStore= * omero.ldap.trustStorePassword= */ protected Fixture createFixture(File ctxFile) throws Exception { Fixture fixture = new Fixture(); fixture.ctx = new FileSystemXmlApplicationContext("file:" + ctxFile.getAbsolutePath()); fixture.config = (LdapConfig) fixture.ctx.getBean("config"); Map<String, LdapContextSource> sources = fixture.ctx.getBeansOfType(LdapContextSource.class); LdapContextSource source = sources.values().iterator().next(); String[] urls = source.getUrls(); assertEquals(1, urls.length); /* AuthenticationSource auth = source.getAuthenticationSource(); SecureLdapContextSource secureSource = new SecureLdapContextSource(urls[0]); secureSource.setDirObjectFactory(DefaultDirObjectFactory.class); secureSource.setBase("ou=People,dc=openmicroscopy,dc=org"); secureSource.setUserDn(auth.getPrincipal()); secureSource.setPassword(auth.getCredentials()); secureSource.setProtocol(""); secureSource.afterPropertiesSet(); //secureSource.setKeyStore(""); //secureSource.setKeyStorePassword(""); //secureSource.setTrustPassword(""); //secureSource.setTrustPassword(""); */ fixture.template = new LdapTemplate(source); fixture.role = mock(RoleProvider.class); RoleProvider provider = (RoleProvider) fixture.role.proxy(); fixture.sql = mock(SqlAction.class); SqlAction sql = (SqlAction) fixture.sql.proxy(); fixture.ldap = new LdapImpl(source, fixture.template, new Roles(), fixture.config, provider, sql); fixture.provider = new LdapPasswordProvider(new PasswordUtil(sql), fixture.ldap); return fixture; }
From source file:org.apache.directory.server.tools.commands.exportcmd.ExportCommandExecutor.java
private void processParameters(Parameter[] params) { Map parameters = new HashMap(); for (int i = 0; i < params.length; i++) { Parameter parameter = params[i]; parameters.put(parameter.getName(), parameter.getValue()); }/*from ww w . j a v a2 s. c o m*/ // Quiet param Boolean quietParam = (Boolean) parameters.get(QUIET_PARAMETER); if (quietParam != null) { setQuietEnabled(quietParam.booleanValue()); } // Debug param Boolean debugParam = (Boolean) parameters.get(DEBUG_PARAMETER); if (debugParam != null) { setDebugEnabled(debugParam.booleanValue()); } // Verbose param Boolean verboseParam = (Boolean) parameters.get(VERBOSE_PARAMETER); if (verboseParam != null) { setVerboseEnabled(verboseParam.booleanValue()); } // Install-path param String installPathParam = (String) parameters.get(INSTALLPATH_PARAMETER); if (installPathParam != null) { try { setLayout(installPathParam); if (!isQuietEnabled()) { notifyOutputListener("loading settings from: " + getLayout().getConfigurationFile()); } ApplicationContext factory = null; URL configUrl; configUrl = getLayout().getConfigurationFile().toURL(); factory = new FileSystemXmlApplicationContext(configUrl.toString()); setConfiguration((ServerStartupConfiguration) factory.getBean("configuration")); } catch (MalformedURLException e) { notifyErrorListener(e.getMessage()); notifyExceptionListener(e); } } // Host param String hostParam = (String) parameters.get(HOST_PARAMETER); if (hostParam != null) { host = hostParam; } else { host = DEFAULT_HOST; if (isDebugEnabled()) { notifyOutputListener("host set to default: " + host); } } // Port param Integer portParam = (Integer) parameters.get(PORT_PARAMETER); if (portParam != null) { port = portParam.intValue(); } // else if ( getConfiguration() != null ) // { // port = getConfiguration().getLdapConfiguration().getIpPort(); // // if ( isDebugEnabled() ) // { // notifyOutputListener( "port overriden by server.xml configuration: " + // port ); // } // } else { port = DEFAULT_PORT; if (isDebugEnabled()) { notifyOutputListener("port set to default: " + port); } } // User param String userParam = (String) parameters.get(USER_PARAMETER); if (userParam != null) { user = userParam; } else { user = DEFAULT_USER; if (isDebugEnabled()) { notifyOutputListener("user set to default: " + user); } } // Password param String passwordParam = (String) parameters.get(PASSWORD_PARAMETER); if (passwordParam != null) { password = passwordParam; } else { password = DEFAULT_PASSWORD; if (isDebugEnabled()) { notifyOutputListener("password set to default: " + password); } } // Auth param String authParam = (String) parameters.get(AUTH_PARAMETER); if (authParam != null) { auth = authParam; } else { auth = DEFAULT_AUTH; if (isDebugEnabled()) { notifyOutputListener("authentication type set to default: " + auth); } } // Base DN param String baseDNParam = (String) parameters.get(BASEDN_PARAMETER); if (baseDNParam != null) { baseDN = baseDNParam; } else { baseDN = DEFAULT_BASEDN; if (isDebugEnabled()) { notifyOutputListener("base DN set to default: " + baseDN); } } // Export Point param String exportPointParam = (String) parameters.get(EXPORTPOINT_PARAMETER); if (exportPointParam != null) { exportPoint = exportPointParam; } else { exportPoint = DEFAULT_EXPORTPOINT; if (isDebugEnabled()) { notifyOutputListener("export point set to default: " + exportPoint); } } // scope param String scopeParam = (String) parameters.get(SCOPE_PARAMETER); if (scopeParam != null) { if (scopeParam.equals(SCOPE_OBJECT)) { scope = SearchControls.OBJECT_SCOPE; } else if (scopeParam.equals(SCOPE_ONELEVEL)) { scope = SearchControls.ONELEVEL_SCOPE; } else if (scopeParam.equals(SCOPE_SUBTREE)) { scope = SearchControls.SUBTREE_SCOPE; } } else { scope = DEFAULT_SCOPE; if (isDebugEnabled()) { notifyOutputListener("scope set to default: " + scope); } } // LdifFile param String ldifFileParam = (String) parameters.get(FILE_PARAMETER); if (ldifFileParam != null) { ldifFileName = ldifFileParam; } }