01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.services.dom;
07:
08: import java.io.File;
09: import java.io.FileInputStream;
10: import java.io.IOException;
11: import java.lang.reflect.InvocationTargetException;
12: import java.lang.reflect.Method;
13:
14: import org.jasig.portal.PortalException;
15: import org.jasig.portal.ResourceMissingException;
16: import org.jasig.portal.utils.ResourceLoader;
17:
18: /**
19: * This provides a DOM initialization service interface. It uses reflection
20: * so the resin library doesn't need to be available at compile time.
21: * @author Nick Bolton, nbolton@unicon.net
22: * @version $Revision: 34797 $
23: */
24: public final class ResinInitServiceImpl implements IDOMInitService {
25:
26: ResinInitServiceImpl() {
27: }
28:
29: /**
30: * Executes an initialization procedure for a specific dom implementation.
31: */
32: public void initialize() throws PortalException {
33: try {
34: Method method;
35: Object[] params = new Object[1];
36: Class[] paramClasses = new Class[1];
37:
38: File regFile = ResourceLoader.getResourceAsFile(this
39: .getClass(), "/properties/resin.conf");
40: FileInputStream is = new FileInputStream(regFile);
41:
42: // create the com.caucho.vfs.FileReadStream object
43: params[0] = is;
44: paramClasses[0] = FileInputStream.class;
45: Object fileReadStream = Class.forName(
46: "com.caucho.vfs.FileReadStream")
47: .getDeclaredConstructor(paramClasses).newInstance(
48: params);
49:
50: // create the com.caucho.vfs.ReadStream object
51: params[0] = fileReadStream;
52: paramClasses[0] = Class
53: .forName("com.caucho.vfs.StreamImpl");
54: Object readStream = Class.forName(
55: "com.caucho.vfs.ReadStream")
56: .getDeclaredConstructor(paramClasses).newInstance(
57: params);
58:
59: // parse resin configuration
60: params[0] = readStream;
61: paramClasses[0] = Class
62: .forName("com.caucho.vfs.ReadStream");
63: method = Class.forName("com.caucho.util.Registry")
64: .getDeclaredMethod("parse", paramClasses);
65: Object registry = method.invoke(null, params);
66:
67: // set configuration as the default
68: params[0] = registry;
69: paramClasses[0] = Class.forName("com.caucho.util.Registry");
70: method = Class.forName("com.caucho.util.Registry")
71: .getDeclaredMethod("setDefault", paramClasses);
72: method.invoke(null, params);
73: } catch (IOException ioe) {
74: ioe.printStackTrace();
75: throw new PortalException(ioe);
76: } catch (InvocationTargetException ite) {
77: ite.printStackTrace();
78: throw new PortalException(ite);
79: } catch (InstantiationException ie) {
80: ie.printStackTrace();
81: throw new PortalException(ie);
82: } catch (IllegalAccessException iae) {
83: iae.printStackTrace();
84: throw new PortalException(iae);
85: } catch (NoSuchMethodException nsme) {
86: nsme.printStackTrace();
87: throw new PortalException(nsme);
88: } catch (ResourceMissingException rme) {
89: rme.printStackTrace();
90: throw new PortalException(rme);
91: } catch (ClassNotFoundException cnfe) {
92: cnfe.printStackTrace();
93: throw new PortalException(cnfe);
94: }
95: }
96: }
|