KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > simulator > app > DSOApplicationBuilder


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
14
15 public class DSOApplicationBuilder implements ApplicationBuilder {
16
17   private final ApplicationConfig applicationConfig;
18   private final ClassLoader JavaDoc classloader;
19
20   private Class JavaDoc applicationClass;
21   private Constructor JavaDoc 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 JavaDoc classloader) {
31     this.applicationConfig = applicationConfig;
32     this.classloader = classloader;
33   }
34   
35   // XXX:: Adding more debugs to figure out the OOME in Primitive ArrayTest.
36
TCLogger logger = TCLogging.getLogger(DSOApplicationBuilder.class);
37   public Application newApplication(String JavaDoc 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 JavaDoc applicationConfigClass = classloader.loadClass(ApplicationConfig.class.getName());
44       Class JavaDoc listenerProviderClass = classloader.loadClass(ListenerProvider.class.getName());
45       this.applicationClass = this.classloader.loadClass(this.applicationConfig.getApplicationClassname());
46       this.applicationConstructor = this.applicationClass.getConstructor(new Class JavaDoc[] { String JavaDoc.class,
47           applicationConfigClass, listenerProviderClass });
48       logger.info("Before new Instance is created...");
49       return (Application) this.applicationConstructor.newInstance(new Object JavaDoc[] { applicationId,
50           this.applicationConfig, listenerProvider });
51     } catch (Throwable JavaDoc 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 JavaDoc getContextClassLoader() {
65     return classloader;
66   }
67
68 }
69
Popular Tags