1 4 package com.tc.simulator.app; 5 6 import com.tc.logging.TCLogger; 7 import com.tc.logging.TCLogging; 8 import com.tc.object.bytecode.hook.impl.PreparedComponentsFromL2Connection; 9 import com.tc.object.config.DSOClientConfigHelper; 10 import com.tc.object.loaders.IsolationClassLoader; 11 import com.tc.simulator.listener.ListenerProvider; 12 13 import java.lang.reflect.Constructor ; 14 15 public class DSOApplicationBuilder implements ApplicationBuilder { 16 17 private final ApplicationConfig applicationConfig; 18 private final ClassLoader classloader; 19 20 private Class applicationClass; 21 private Constructor applicationConstructor; 22 23 public DSOApplicationBuilder(DSOClientConfigHelper config, ApplicationConfig applicationConfig, 24 PreparedComponentsFromL2Connection components) { 25 26 this(applicationConfig, new IsolationClassLoader(config, components)); 27 } 28 29 public DSOApplicationBuilder(ApplicationConfig applicationConfig, 30 ClassLoader classloader) { 31 this.applicationConfig = applicationConfig; 32 this.classloader = classloader; 33 } 34 35 TCLogger logger = TCLogging.getLogger(DSOApplicationBuilder.class); 37 public Application newApplication(String applicationId, ListenerProvider listenerProvider) 38 throws ApplicationInstantiationException { 39 try { 40 logger.info("Before initializing Class Loader..."); 41 initializeClassLoader(); 42 logger.info("After initializing Class Loader..."); 43 Class applicationConfigClass = classloader.loadClass(ApplicationConfig.class.getName()); 44 Class listenerProviderClass = classloader.loadClass(ListenerProvider.class.getName()); 45 this.applicationClass = this.classloader.loadClass(this.applicationConfig.getApplicationClassname()); 46 this.applicationConstructor = this.applicationClass.getConstructor(new Class [] { String .class, 47 applicationConfigClass, listenerProviderClass }); 48 logger.info("Before new Instance is created..."); 49 return (Application) this.applicationConstructor.newInstance(new Object [] { applicationId, 50 this.applicationConfig, listenerProvider }); 51 } catch (Throwable t) { 52 t.printStackTrace(); 53 throw new ApplicationInstantiationException(t); 54 } 55 56 } 57 58 private void initializeClassLoader() { 59 if (this.classloader instanceof IsolationClassLoader) { 60 ((IsolationClassLoader)this.classloader).init(); 61 } 62 } 63 64 public ClassLoader getContextClassLoader() { 65 return classloader; 66 } 67 68 } 69 | Popular Tags |