KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > work > WorkManagerFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors.work;
25
26 import com.sun.enterprise.util.Utility;
27 import com.sun.enterprise.connectors.ConnectorRuntimeException;
28 import com.sun.logging.LogDomains;
29 import java.io.IOException JavaDoc;
30 import java.lang.reflect.InvocationTargetException JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import java.util.Properties JavaDoc;
33 import java.util.logging.Level JavaDoc;
34 import java.util.logging.Logger JavaDoc;
35 import javax.resource.spi.work.WorkManager JavaDoc;
36 import com.sun.enterprise.util.i18n.StringManager;
37
38 /**
39  * WorkManagerFactory allows other customized WorkManager implementation
40  * to be plugged into the server. The name of the customized
41  * implementation class for the WorkManager has to be specified as
42  * a system property "workmanager.class".
43  * <p>
44  * It is assumed that the implementation for WorkManager also provides
45  * a public method called "getInstance" that returns a WorkManager object.
46  * This frees the WorkManagerFactory from deciding whether WorkManager
47  * is implemented as a Singleton in the server.
48  * <p>
49  * @author Qingqing Ouyang, Binod P.G.
50  */

51 public class WorkManagerFactory {
52     
53     private static final String JavaDoc DEFAULT =
54     "com.sun.enterprise.connectors.work.CommonWorkManager";
55     
56     private static final String JavaDoc WORK_MANAGER_CLASS = "workmanager.class";
57     
58     private static Logger JavaDoc logger =
59     LogDomains.getLogger(LogDomains.RSR_LOGGER);
60  
61     private static StringManager localStrings =
62                         StringManager.getManager(WorkManagerFactory.class);
63    
64     /**
65      * This is called by the constructor of BootstrapContextImpl
66      */

67     public static WorkManager JavaDoc getWorkManager(String JavaDoc poolName)
68                               throws ConnectorRuntimeException {
69         
70         String JavaDoc className = null;
71         String JavaDoc methodName = "getInstance";
72         Class JavaDoc cls = null;
73         WorkManager JavaDoc wm = null;
74         
75         try {
76             className = System.getProperty(WORK_MANAGER_CLASS, DEFAULT);
77
78             // Default work manager implementation is not a singleton.
79
if (className.equals(DEFAULT)) {
80                 return new CommonWorkManager(poolName);
81             }
82             
83             cls = Class.forName(className);
84             if (cls != null) {
85                 Method JavaDoc method = cls.getMethod("getInstance", new Class JavaDoc[]{});
86                 wm = (WorkManager JavaDoc) method.invoke(cls, new Object JavaDoc[] {});
87             }
88         } catch (Exception JavaDoc e) {
89             String JavaDoc msg = localStrings.getString("workmanager.instantiation_error");
90             logger.log(Level.SEVERE, msg, e);
91         }
92         
93         return wm;
94     }
95
96 }
97
Popular Tags