01: /*
02: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: package com.sun.jumpimpl.isolate.jvmprocess;
26:
27: import com.sun.jump.common.JUMPAppModel;
28: import com.sun.jump.isolate.jvmprocess.JUMPIsolateProcess;
29: import com.sun.jump.isolate.jvmprocess.JUMPAppContainer;
30: import com.sun.jump.isolate.jvmprocess.JUMPAppContainerContext;
31:
32: import java.lang.reflect.InvocationTargetException;
33: import java.lang.reflect.Method;
34: import java.util.Map;
35:
36: public class AppContainerFactoryImpl {
37:
38: private Map config = JUMPIsolateProcess.getInstance().getConfig();
39:
40: private static String PREFIX = "com.sun.jumpimpl.isolate.jvmprocess";
41: private static String CONTAINER_CLASSNAME = "AppContainerImpl";
42: private static String FACTORY_METHODNAME = "getInstance";
43:
44: public JUMPAppContainer getAppContainer(JUMPAppModel model,
45: JUMPAppContainerContext context) {
46:
47: String defaultPackageName = PREFIX + "." + model.toString();
48:
49: String packageName = null;
50:
51: if (config != null) {
52: packageName = (String) config
53: .get("appcontainerfactory.packagename."
54: + model.toString());
55: }
56:
57: if (packageName == null) {
58: packageName = defaultPackageName;
59: }
60:
61: String fullClassName = packageName + "." + CONTAINER_CLASSNAME;
62:
63: try {
64: Class clazz = Class.forName(fullClassName);
65:
66: Method m = clazz.getMethod(FACTORY_METHODNAME,
67: new Class[] { JUMPAppContainerContext.class });
68:
69: return (JUMPAppContainer) m.invoke(null,
70: new Object[] { context });
71:
72: } catch (ClassNotFoundException e) {
73: System.out.println(fullClassName + " not found");
74: e.printStackTrace();
75: } catch (NoSuchMethodException e) {
76: System.out.println(FACTORY_METHODNAME + "() not found in "
77: + fullClassName);
78: e.printStackTrace();
79: } catch (IllegalAccessException e) {
80: e.printStackTrace();
81: } catch (InvocationTargetException e) {
82: e.printStackTrace();
83: } catch (IllegalArgumentException e) {
84: e.printStackTrace();
85: }
86: return null;
87: }
88:
89: }
|