KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > DatabaseDependentClassFactory


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DatabaseDependentClassFactory.java,v 1.5 2007/01/07 06:14:18 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.persist.db;
23
24 import java.util.List JavaDoc;
25
26 import org.opensubsystems.core.error.OSSException;
27 import org.opensubsystems.core.util.ClassFactory;
28
29 /**
30  * Class factory responsible for instantiation of classes whose implementation
31  * depends on currently used database. Therefore this class factory tries to
32  * instantiate the correct class based on what database is currently used.
33  *
34  * @version $Id: DatabaseDependentClassFactory.java,v 1.5 2007/01/07 06:14:18 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.3 2004/12/18 06:18:20 bastafidli
38  */

39 class DatabaseDependentClassFactory extends ClassFactory
40 {
41    /**
42     * {@inheritDoc}
43     */

44    protected void createDefaultClassNames(
45       String JavaDoc strClassIdentifier,
46       String JavaDoc strModifier,
47       List JavaDoc lstClassNames
48    ) throws OSSException
49    {
50       int iIndex;
51       StringBuffer JavaDoc sbClassName = new StringBuffer JavaDoc();
52       
53       // Assuming name of the interface aaa.AAA
54

55       // Find package separator
56
iIndex = strClassIdentifier.lastIndexOf('.');
57
58       // First try class name aaa.dbname.DBNameAAA
59
if (iIndex != -1)
60       {
61          // There is a package
62
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
63          sbClassName.append(strModifier.toLowerCase());
64          sbClassName.append(".");
65          sbClassName.append(strModifier);
66          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
67                                strClassIdentifier.length()));
68       }
69       else
70       {
71          sbClassName.append(strModifier.toLowerCase());
72          sbClassName.append(".");
73          sbClassName.append(strModifier);
74          sbClassName.append(strClassIdentifier);
75       }
76       lstClassNames.add(sbClassName.toString());
77       sbClassName.delete(0, sbClassName.length());
78       // Now try class name aaa.DBNameAAA
79
if (iIndex != -1)
80       {
81          // There is a package
82
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
83          sbClassName.append(strModifier);
84          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
85                                strClassIdentifier.length()));
86       }
87       else
88       {
89          sbClassName.append(strModifier);
90          sbClassName.append(strClassIdentifier);
91       }
92       lstClassNames.add(sbClassName.toString());
93       sbClassName.delete(0, sbClassName.length());
94       // Now try class aaa.dbname.AAA
95
if (iIndex != -1)
96       {
97          // There is a package
98
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
99          sbClassName.append(strModifier.toLowerCase());
100          sbClassName.append(".");
101          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
102                                strClassIdentifier.length()));
103       }
104       else
105       {
106          sbClassName.append(strModifier.toLowerCase());
107          sbClassName.append(".");
108          sbClassName.append(strClassIdentifier);
109       }
110
111       lstClassNames.add(sbClassName.toString());
112       sbClassName.delete(0, sbClassName.length());
113       // Now try database independent class aaa.AAAImpl
114
sbClassName.append(strClassIdentifier);
115       sbClassName.append("Impl");
116       lstClassNames.add(sbClassName.toString());
117       sbClassName.delete(0, sbClassName.length());
118       // And now just try class aaa.AAA
119
sbClassName.append(strClassIdentifier);
120       lstClassNames.add(sbClassName.toString());
121    }
122    
123    /**
124     * {@inheritDoc}
125     */

126    protected String JavaDoc getModifier(
127    ) throws OSSException
128    {
129       return DatabaseImpl.getInstance().getDatabaseTypeIdentifier();
130    }
131 }
132
Popular Tags