KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DatabaseFactoryClassFactory.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.OSSDynamicClassException;
27 import org.opensubsystems.core.error.OSSException;
28 import org.opensubsystems.core.persist.DataFactory;
29 import org.opensubsystems.core.util.ClassFactory;
30 import org.opensubsystems.core.util.GlobalConstants;
31
32 /**
33  * Class factory responsible for instantiation of database factories. The correct
34  * factory is instantiated based on the factory interface or default implementation
35  * and currently active database instantiate correct database factory which should
36  * be used for this database.
37  *
38  * @version $Id: DatabaseFactoryClassFactory.java,v 1.5 2007/01/07 06:14:18 bastafidli Exp $
39  * @author Miro Halas
40  * @code.reviewer Miro Halas
41  * @code.reviewed 1.3 2004/12/18 06:18:21 bastafidli
42  */

43 public class DatabaseFactoryClassFactory extends ClassFactory
44 {
45    /**
46     * {@inheritDoc}
47     */

48    protected void verifyInstance(
49       Object JavaDoc objInstance
50    ) throws OSSException
51    {
52       // Make sure that the instantiated class is of type DataFactory
53
// and DatabaseFactory
54
if ((objInstance != null) && (!(objInstance instanceof DataFactory))
55          && (!(objInstance instanceof DatabaseFactory)))
56       {
57          throw new OSSDynamicClassException("Instantiated class " +
58                                             " doesn't implements DataFactory" +
59                                             " and DatabaseFactory" +
60                                             " interface and is of type " +
61                                             objInstance.getClass().getName());
62                       
63       }
64    }
65
66    /**
67     * {@inheritDoc}
68     */

69    protected void createDefaultClassNames(
70       String JavaDoc strClassIdentifier,
71       String JavaDoc strModifier,
72       List JavaDoc lstClassNames
73    ) throws OSSException
74    {
75       int iIndex;
76       int iIndex2;
77       StringBuffer JavaDoc sbClassName = new StringBuffer JavaDoc();
78       
79       // Assuming name of the class aaa.AAAFactory
80

81       // Find package separator
82
iIndex = strClassIdentifier.lastIndexOf('.');
83       // Find end of name
84
iIndex2 = strClassIdentifier.lastIndexOf("Factory");
85       if (GlobalConstants.ERROR_CHECKING)
86       {
87          assert iIndex2 != -1
88                 : "The factory class identifier is expected to end with name Factory";
89       }
90       // Check if it was found to do not produce StringIndexOutOfBoundsException
91
if (iIndex2 != -1)
92       {
93          // Transform to the class aaa.db.AAADatabaseFactory
94
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
95          sbClassName.append("db.");
96          sbClassName.append(strClassIdentifier.substring(iIndex + 1, iIndex2));
97          sbClassName.append("DatabaseFactory");
98          lstClassNames.add(sbClassName.toString());
99       }
100    }
101 }
102
Popular Tags