1 25 26 package org.objectweb.easybeans.server; 27 28 import java.net.URL ; 29 30 import org.objectweb.easybeans.log.JLog; 31 import org.objectweb.easybeans.log.JLogFactory; 32 import org.objectweb.easybeans.xmlconfig.XMLConfiguration; 33 import org.objectweb.easybeans.xmlconfig.XMLConfigurationException; 34 35 36 40 public final class EmbeddedConfigurator { 41 42 45 private static final String CONFIGURATION_FILE_NAME = "easybeans.xml"; 46 47 50 private static JLog logger = JLogFactory.getLog(EmbeddedConfigurator.class); 51 52 53 56 private EmbeddedConfigurator() { 57 58 } 59 60 68 public static Embedded init(final Embedded embedded, final URL xmlConfigurationURL) throws EmbeddedException { 69 configure(embedded, xmlConfigurationURL); 70 return embedded; 71 } 72 73 80 public static Embedded create(final URL xmlConfigurationURL) throws EmbeddedException { 81 return init(new Embedded(), xmlConfigurationURL); 82 } 83 84 90 public static Embedded create() throws EmbeddedException { 91 URL xmlConfigurationURL = Thread.currentThread().getContextClassLoader().getResource(CONFIGURATION_FILE_NAME); 92 if (xmlConfigurationURL == null) { 93 throw new EmbeddedException("No configuration file with name '" + CONFIGURATION_FILE_NAME 94 + "' was found in classpath."); 95 } 96 return create(xmlConfigurationURL); 97 } 98 99 105 private static void configure(final Embedded embedded, final URL xmlConfigurationURL) throws EmbeddedException { 106 long tStart = System.currentTimeMillis(); 107 logger.info("Starting configuration of EasyBeans server"); 108 XMLConfiguration xmlConfiguration = new XMLConfiguration(xmlConfigurationURL); 109 try { 110 xmlConfiguration.configure(embedded); 111 } catch (XMLConfigurationException e) { 112 throw new EmbeddedException("Cannot configure the embedded server", e); 113 } 114 if (logger.isInfoEnabled()) { 115 logger.info("Configuration done in : " + (System.currentTimeMillis() - tStart) + " ms"); 116 } 117 } 118 119 } 120 | Popular Tags |