01: /**
02: * $Id: MarkupManagerFactory.java,v 1.2 2003/12/19 22:46:45 jtb Exp $
03: * Copyright 2003 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.wsrp.consumer.markup;
14:
15: import com.sun.portal.wsrp.consumer.common.WSRPConsumerConfig;
16: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
17: import com.sun.portal.container.Container;
18:
19: /**
20: * <code>MarkupManagerFactory</code> is a class which
21: * provides creates static singleton instance of
22: * <code>WSRP Container</code>. This object is created as part
23: * of bootstrap doen by WSRPConsumerBootstrap.
24: */
25: public class MarkupManagerFactory {
26:
27: //
28: // static instance
29: //
30: private static Container _markupManager;
31:
32: public static Container getInstance() {
33: return _markupManager;
34: }
35:
36: /**
37: * Get an instance of MarkupManager.
38: *
39: * @return a <code>MarkupManager</code> value
40: * @exception WSRPConsumerException if an error occurs
41: */
42: public static void init() throws WSRPConsumerException {
43:
44: if (_markupManager == null) {
45: WSRPConsumerConfig config = WSRPConsumerConfig
46: .getInstance();
47: String mmClassname = config.getMarkupManagerClassname();
48: _markupManager = loadMarkupManagerClass(mmClassname);
49: } else {
50: throw new WSRPConsumerException(
51: "MarkupManagerFactory:Init can be called only once.");
52: }
53:
54: }
55:
56: protected static Container loadMarkupManagerClass(String classname)
57: throws WSRPConsumerException {
58:
59: Container markupManager = null;
60: try {
61: markupManager = (Container) (Class.forName(classname)
62: .newInstance());
63: } catch (ClassNotFoundException cnfe) {
64: throw new WSRPConsumerException(
65: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
66: cnfe);
67: } catch (NoClassDefFoundError ncdfe) {
68: throw new WSRPConsumerException(
69: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
70: ncdfe);
71: } catch (IllegalAccessException iae) {
72: throw new WSRPConsumerException(
73: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
74: iae);
75: } catch (ClassCastException cce) {
76: throw new WSRPConsumerException(
77: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
78: cce);
79: } catch (InstantiationException ie) {
80: throw new WSRPConsumerException(
81: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
82: ie);
83: } catch (SecurityException se) {
84: throw new WSRPConsumerException(
85: "MarkupManagerFactory.loadMarkupManagerClass(): failed to load MarkupManager class.",
86: se);
87: }
88: return markupManager;
89: }
90:
91: }
|