private static RuntimeDelegate createRuntimeInstanceFromConfigurationFile() { RuntimeDelegate result=null; File configFile = getConfigurationFile(); if(configFile.canRead()) { InputStream is=null; try { is=new FileInputStream(configFile); Properties configProperties=new Properties(); configProperties.load(is); String delegateClassName=configProperties.getProperty(LDP4J_APPLICATION_SPI_PROPERTY); if(delegateClassName!=null) { result=createRuntimeInstanceForClassName(delegateClassName); } if(delegateClassName==null && LOGGER.isWarnEnabled()) { LOGGER.warn("Configuration file '"+configFile.getAbsolutePath()+"' does not define a delegate class name"); } } catch(FileNotFoundException e) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("Could not find runtime instance configuration file '"+configFile.getAbsolutePath()+"'",e); } } catch(IOException e) { if(LOGGER.isWarnEnabled()) { LOGGER.warn("Could not load runtime instance configuration file '"+configFile.getAbsolutePath()+"'",e); } } finally { closeQuietly(is, "Could not close configuration properties"); } } return result; }
/** * Obtain a {@code RuntimeInstance} instance using the method described in * {@link #getInstance}. * * @return an instance of {@code RuntimeInstance}. */ private static RuntimeDelegate findDelegate() { try { RuntimeDelegate result=createRuntimeInstanceFromSPI(); if(result==null) { result=createRuntimeInstanceFromConfigurationFile(); } if(result==null) { String delegateClassName = System.getProperty(LDP4J_APPLICATION_SPI_PROPERTY); if(delegateClassName!=null) { result=createRuntimeInstanceForClassName(delegateClassName); } } if(result==null) { result=new DefaultRuntimeInstance(); } return result; } catch (Exception ex) { throw new IllegalStateException("Could not find runtime delegate",ex); } }