01: /* Copyright 2005 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.layout.dlm;
07:
08: import java.io.StringWriter;
09: import java.io.PrintWriter;
10:
11: /**
12: * Loads the class specified in className and verifies that it conforms to
13: * the LayoutDecorator interface. If a null class name is passed in this
14: * class returns null. If an error occurs an exception is thrown indicating
15: * the problems that occurred.
16: * @version $Revision: 35711 $ $Date: 2005-05-02 22:55:35 -0700 (Mon, 02 May 2005) $
17: * @since uPortal 2.5
18: */
19: class DecoratorLoader {
20: public static final String RCS_ID = "@(#) $Header$";
21:
22: static LayoutDecorator load(String className) throws Exception {
23: Class theClass = null;
24: try {
25: theClass = Class.forName(className);
26: } catch (ClassNotFoundException cnfe) {
27: throw new Exception(
28: "java.lang.ClassNotFoundException occurred"
29: + " while loading class '" + className
30: + "' (or one of its "
31: + "dependent classes).", cnfe);
32: } catch (ExceptionInInitializerError eiie) {
33: StringWriter s = new StringWriter();
34: PrintWriter p = new PrintWriter(s);
35: eiie.printStackTrace(p);
36: p.flush();
37:
38: throw new Exception(
39: "java.lang.ExceptionInInitializerError "
40: + "occurred while " + "loading class '"
41: + className + "' (or one of its "
42: + "dependent classes). \nThis indicates"
43: + "that an exception "
44: + "occurred during evaluation of a static"
45: + " initializer or the initializer for a "
46: + "static variable. The stack trace is as"
47: + " follows:\n----------\n" + s.toString()
48: + "\n----------", eiie);
49: } catch (LinkageError le) {
50: throw new Exception(
51: "java.lang.LinkageError occurred while "
52: + "loading class '"
53: + className
54: + "'. \nThis typically means "
55: + "that a dependent class has changed "
56: + "incompatibly after compiling this class. ",
57: le);
58: }
59:
60: Object theInstance = null;
61:
62: try {
63: theInstance = theClass.newInstance();
64: } catch (IllegalAccessException iae) {
65: throw new Exception(
66: "java.lang.IllegalAccessException occurred "
67: + "while loading class '" + className
68: + "' (or one of its "
69: + "dependent classes). \nVerify that this "
70: + "is a public class "
71: + "and that it contains a public, zero "
72: + "argument constructor.", iae);
73: } catch (InstantiationException ie) {
74: throw new Exception(
75: "java.lang.InstantiationException occurred "
76: + "while loading class '" + className
77: + "' (or one of its "
78: + "dependent classes). \nVerify that the "
79: + "specified class is a "
80: + "class and not an interface or abstract "
81: + "class.", ie);
82: }
83: try {
84: return (LayoutDecorator) theInstance;
85: } catch (ClassCastException cce) {
86: throw new Exception(
87: "java.lang.ClassCastException occurred "
88: + "while loading class '" + className
89: + "'. \nVerify that the "
90: + "class implements the "
91: + "LayoutDecorator interface.", cce);
92: }
93: }
94: }
|