001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.taskadmin.context;
006:
007: import java.util.Properties;
008:
009: import java.io.FileInputStream;
010: import java.io.IOException;
011: import java.io.FileNotFoundException;
012:
013: import javax.servlet.ServletContext;
014: import com.sun.portal.util.ResourceLoader;
015: import com.sun.portal.desktop.context.ContextError;
016: import com.sun.portal.taskadmin.TaskAdminConstants;
017:
018: public class TaskAdminContextFactoryManager implements
019: TaskAdminConstants {
020: private static TaskAdminContextFactory tcf = null;
021: private static ChannelTaskAdminContextFactory ctcf = null;
022:
023: public static synchronized TaskAdminContextFactory getFactory() {
024: if (tcf == null) {
025: String tcfClassName = null;
026: try {
027: Properties contextProps = ResourceLoader.getInstance(
028: System.getProperties()).getProperties(
029: CONTEXT_CONFIG_FILE_NAME);
030: tcfClassName = contextProps
031: .getProperty(TASKADMIN_CONTEXT_FACTORY_CLASS_NAME);
032: } catch (FileNotFoundException fnfe) {
033: throw new ContextError(
034: "TaskAdminContextFactoryManager.getFactory(): ",
035: fnfe);
036: } catch (IOException ioe) {
037: throw new ContextError(
038: "TaskAdminContextFactoryManager.getFactory(): ",
039: ioe);
040: }
041: if (tcfClassName == null) {
042: throw new ContextError(
043: "TaskAdminContextFactoryManager.getFactory(): tcf class name was null from config file");
044: }
045:
046: try {
047: tcf = (TaskAdminContextFactory) (Class
048: .forName(tcfClassName).newInstance());
049: tcf.init();
050: } catch (ClassNotFoundException cnfe) {
051: throw new ContextError(
052: "TaskAdminContextFactoryManager.getFactory(): ",
053: cnfe);
054: } catch (NoClassDefFoundError ncdfe) {
055: throw new ContextError(
056: "TaskAdminContextFactoryManager.getFactory(): ",
057: ncdfe);
058: } catch (IllegalAccessException iae) {
059: throw new ContextError(
060: "TaskAdminContextFactoryManager.getFactory(): ",
061: iae);
062: } catch (ClassCastException cce) {
063: throw new ContextError(
064: "TaskAdminContextFactoryManager.getFactory(): ",
065: cce);
066: } catch (InstantiationException ie) {
067: throw new ContextError(
068: "TaskAdminContextFactoryManager.getFactory(): ",
069: ie);
070: } catch (SecurityException se) {
071: throw new ContextError(
072: "TaskAdminContextFactoryManager.getFactory(): ",
073: se);
074: }
075: }
076:
077: return tcf;
078: }
079:
080: public static synchronized ChannelTaskAdminContextFactory getChannelTaskAdminFactory() {
081: if (ctcf == null) {
082: String ctcfClassName = null;
083: try {
084: Properties contextProps = ResourceLoader.getInstance(
085: System.getProperties()).getProperties(
086: CONTEXT_CONFIG_FILE_NAME);
087: ctcfClassName = contextProps
088: .getProperty(CHANNEL_TASKADMIN_CONTEXT_FACTORY_CLASS_NAME);
089: } catch (FileNotFoundException fnfe) {
090: throw new ContextError(
091: "TaskAdminContextFactoryManager.getFactory(): ",
092: fnfe);
093: } catch (IOException ioe) {
094: throw new ContextError(
095: "TaskAdminContextFactoryManager.getFactory(): ",
096: ioe);
097: }
098: if (ctcfClassName == null) {
099: throw new ContextError(
100: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ctcf class name was null from config file");
101: }
102:
103: try {
104: ctcf = (ChannelTaskAdminContextFactory) (Class
105: .forName(ctcfClassName).newInstance());
106: ctcf.init();
107: } catch (ClassNotFoundException cnfe) {
108: throw new ContextError(
109: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
110: cnfe);
111: } catch (NoClassDefFoundError ncdfe) {
112: throw new ContextError(
113: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
114: ncdfe);
115: } catch (IllegalAccessException iae) {
116: throw new ContextError(
117: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
118: iae);
119: } catch (ClassCastException cce) {
120: throw new ContextError(
121: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
122: cce);
123: } catch (InstantiationException ie) {
124: throw new ContextError(
125: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
126: ie);
127: } catch (SecurityException se) {
128: throw new ContextError(
129: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
130: se);
131: }
132: }
133:
134: return ctcf;
135: }
136:
137: public static synchronized TaskAdminContextFactory getFactory(
138: String portalId) {
139: if (tcf == null) {
140: String tcfClassName = null;
141: try {
142: Properties contextProps = ResourceLoader.getInstance(
143: portalId).getProperties(
144: CONTEXT_CONFIG_FILE_NAME);
145: tcfClassName = contextProps
146: .getProperty(TASKADMIN_CONTEXT_FACTORY_CLASS_NAME);
147: } catch (FileNotFoundException fnfe) {
148: throw new ContextError(
149: "TaskAdminContextFactoryManager.getFactory(): ",
150: fnfe);
151: } catch (IOException ioe) {
152: throw new ContextError(
153: "TaskAdminContextFactoryManager.getFactory(): ",
154: ioe);
155: }
156: if (tcfClassName == null) {
157: throw new ContextError(
158: "TaskAdminContextFactoryManager.getFactory(): tcf class name was null from config file");
159: }
160:
161: try {
162: tcf = (TaskAdminContextFactory) (Class
163: .forName(tcfClassName).newInstance());
164: tcf.init();
165: } catch (ClassNotFoundException cnfe) {
166: throw new ContextError(
167: "TaskAdminContextFactoryManager.getFactory(): ",
168: cnfe);
169: } catch (NoClassDefFoundError ncdfe) {
170: throw new ContextError(
171: "TaskAdminContextFactoryManager.getFactory(): ",
172: ncdfe);
173: } catch (IllegalAccessException iae) {
174: throw new ContextError(
175: "TaskAdminContextFactoryManager.getFactory(): ",
176: iae);
177: } catch (ClassCastException cce) {
178: throw new ContextError(
179: "TaskAdminContextFactoryManager.getFactory(): ",
180: cce);
181: } catch (InstantiationException ie) {
182: throw new ContextError(
183: "TaskAdminContextFactoryManager.getFactory(): ",
184: ie);
185: } catch (SecurityException se) {
186: throw new ContextError(
187: "TaskAdminContextFactoryManager.getFactory(): ",
188: se);
189: }
190: }
191:
192: return tcf;
193: }
194:
195: public static synchronized ChannelTaskAdminContextFactory getChannelTaskAdminFactory(
196: String portalId) {
197: if (ctcf == null) {
198: String ctcfClassName = null;
199: try {
200: Properties contextProps = ResourceLoader.getInstance(
201: portalId).getProperties(
202: CONTEXT_CONFIG_FILE_NAME);
203: ctcfClassName = contextProps
204: .getProperty(CHANNEL_TASKADMIN_CONTEXT_FACTORY_CLASS_NAME);
205: } catch (FileNotFoundException fnfe) {
206: throw new ContextError(
207: "TaskAdminContextFactoryManager.getFactory(): ",
208: fnfe);
209: } catch (IOException ioe) {
210: throw new ContextError(
211: "TaskAdminContextFactoryManager.getFactory(): ",
212: ioe);
213: }
214: if (ctcfClassName == null) {
215: throw new ContextError(
216: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ctcf class name was null from config file");
217: }
218:
219: try {
220: ctcf = (ChannelTaskAdminContextFactory) (Class
221: .forName(ctcfClassName).newInstance());
222: ctcf.init();
223: } catch (ClassNotFoundException cnfe) {
224: throw new ContextError(
225: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
226: cnfe);
227: } catch (NoClassDefFoundError ncdfe) {
228: throw new ContextError(
229: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
230: ncdfe);
231: } catch (IllegalAccessException iae) {
232: throw new ContextError(
233: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
234: iae);
235: } catch (ClassCastException cce) {
236: throw new ContextError(
237: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
238: cce);
239: } catch (InstantiationException ie) {
240: throw new ContextError(
241: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
242: ie);
243: } catch (SecurityException se) {
244: throw new ContextError(
245: "TaskAdminContextFactoryManager.getChannelTaskAdminFactory(): ",
246: se);
247: }
248: }
249:
250: return ctcf;
251: }
252:
253: }
|