KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > sfsb > initialization > SFSBTxStoreManagerFactory


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.ejb.base.sfsb.initialization;
25
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28
29 import com.sun.logging.LogDomains;
30
31 import com.sun.ejb.base.sfsb.store.FileTxStoreManager;
32
33 import com.sun.ejb.spi.sfsb.store.SFSBTxStoreManager;
34
35 /**
36  * Factory for creating SFSBTxStoreManager. SFSBTxStoreManager is
37  * responsible for checkpointing an Array of SFSBBeanState(s)
38  * (as a single transactional unit if possible)
39  *
40  * @author Mahesh Kannan
41  */

42 public class SFSBTxStoreManagerFactory {
43
44     private static Logger JavaDoc _logger =
45         LogDomains.getLogger(LogDomains.EJB_LOGGER);
46     
47     protected static final String JavaDoc DEFAULT_EE_PACKAGE =
48     "com.sun.ejb.ee.sfsb.store";
49     
50     public static SFSBTxStoreManager createSFSBTxStoreManager(
51         String JavaDoc persistenceType)
52     {
53     if ("file".equalsIgnoreCase(persistenceType)) {
54         return new FileTxStoreManager();
55     }
56
57     try {
58         String JavaDoc className = createClassNameFrom(persistenceType);
59         return (SFSBTxStoreManager)
60             (Class.forName(className)).newInstance();
61     } catch (ClassNotFoundException JavaDoc cnfEx) {
62         _logger.log(Level.FINE,
63         "Exception while creating SFSBTxStoreManager for persistence "
64         + "type: " + persistenceType + ". Exception: " + cnfEx);
65     } catch (Exception JavaDoc ex) {
66         _logger.log(Level.FINE,
67         "Exception while creating SFSBTxStoreManager for "
68         + "persistence type: " + persistenceType, ex);
69     }
70
71     _logger.log(Level.WARNING, "Created FileTxStorManager for persistence"
72         + " type: " + persistenceType);
73
74     return new FileTxStoreManager();
75     }
76     
77     /**
78      *
79      * @param persistenceType
80      */

81     private static String JavaDoc createClassNameFrom(String JavaDoc persistenceType) {
82         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
83     sbuf.append(getEEPackage()).append(".")
84         .append(camelCase(persistenceType))
85         .append("TxStoreManager");
86         String JavaDoc classname = sbuf.toString();
87         return classname;
88     }
89     
90     /**
91      * this method strips out all non-alpha characters; camelCases the result
92      *
93      * @param inputString
94      */

95     private static String JavaDoc camelCase(String JavaDoc inputString) {
96         String JavaDoc strippedString = stripNonAlphas(inputString);
97         String JavaDoc firstLetter = (strippedString.substring(0, 1)).toUpperCase();
98         String JavaDoc remainingPart =
99             (strippedString.substring(1, strippedString.length())).toLowerCase();
100         return firstLetter + remainingPart;
101     }
102
103     /**
104      * this method strips out all non-alpha characters
105      *
106      * @param inputString
107      */

108     private static String JavaDoc stripNonAlphas(String JavaDoc inputString) {
109         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(50);
110         for(int i=0; i<inputString.length(); i++) {
111             char nextChar = inputString.charAt(i);
112             if(Character.isLetter(nextChar)) {
113                 sb.append(nextChar);
114             }
115         }
116         return sb.toString();
117     }
118
119     /**
120      * return the path where the ee builders reside
121      * although this method allows this to be configurable
122      * via an property in server.xml we do not expose it
123      * and it should not be re-configured
124      *
125      */

126     private static String JavaDoc getEEPackage() {
127         return DEFAULT_EE_PACKAGE;
128     }
129     
130 }
131
Popular Tags