KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > application > ThickClientDependentClassFactory


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ThickClientDependentClassFactory.java,v 1.4 2007/01/07 06:14:39 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.application;
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 thick client gui technology. Therefore this class
32  * factory tries to instantiate the correct class based on what technology is
33  * currently used.
34  *
35  * @version $Id: ThickClientDependentClassFactory.java,v 1.4 2007/01/07 06:14:39 bastafidli Exp $
36  * @author Miro Halas
37  * @code.reviewer Miro Halas
38  * @code.reviewed 1.2 2006/01/30 14:10:43 bastafidli
39  */

40 public class ThickClientDependentClassFactory extends ClassFactory
41 {
42    // Attributes ///////////////////////////////////////////////////////////////
43

44    /**
45     * GUI technology used.
46     */

47    protected String JavaDoc m_strGuiTechnology;
48    
49    // Constructors /////////////////////////////////////////////////////////////
50

51    /**
52     * Constructor
53     *
54     * @param strGuiTechnology - identification of GUI technology which will be
55     * used to identify classes which use it
56     */

57    public ThickClientDependentClassFactory(
58       String JavaDoc strGuiTechnology
59    )
60    {
61       m_strGuiTechnology = strGuiTechnology;
62    }
63   
64    /**
65     * Constructor
66     *
67     * @param client - client requesting the factory
68     */

69    public ThickClientDependentClassFactory(
70       ThickClient client
71    )
72    {
73       m_strGuiTechnology = client.getGui().getGuiTechnology();
74    }
75   
76    // Helper methods ///////////////////////////////////////////////////////////
77

78    /**
79     * {@inheritDoc}
80     */

81    protected void createDefaultClassNames(
82       String JavaDoc strClassIdentifier,
83       String JavaDoc strModifier,
84       List JavaDoc lstClassNames
85    ) throws OSSException
86    {
87       int iIndex;
88       StringBuffer JavaDoc sbClassName = new StringBuffer JavaDoc();
89       
90       // Assuming name of the interface aaa.AAA
91

92       // Find package separator
93
iIndex = strClassIdentifier.lastIndexOf('.');
94
95       // First try class name aaa.guitech.GuiTechAAA
96
if (iIndex != -1)
97       {
98          // There is a package
99
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
100          sbClassName.append(strModifier.toLowerCase());
101          sbClassName.append(".");
102          sbClassName.append(strModifier);
103          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
104                                strClassIdentifier.length()));
105       }
106       else
107       {
108          sbClassName.append(strModifier.toLowerCase());
109          sbClassName.append(".");
110          sbClassName.append(strModifier);
111          sbClassName.append(strClassIdentifier);
112       }
113       lstClassNames.add(sbClassName.toString());
114       sbClassName.delete(0, sbClassName.length());
115       // Now try class name aaa.GuiTechAAA
116
if (iIndex != -1)
117       {
118          // There is a package
119
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
120          sbClassName.append(strModifier);
121          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
122                                strClassIdentifier.length()));
123       }
124       else
125       {
126          sbClassName.append(strModifier);
127          sbClassName.append(strClassIdentifier);
128       }
129       lstClassNames.add(sbClassName.toString());
130       sbClassName.delete(0, sbClassName.length());
131       // Now try class aaa.guitech.AAA
132
if (iIndex != -1)
133       {
134          // There is a package
135
sbClassName.append(strClassIdentifier.substring(0, iIndex + 1));
136          sbClassName.append(strModifier.toLowerCase());
137          sbClassName.append(".");
138          sbClassName.append(strClassIdentifier.substring(iIndex + 1,
139                                strClassIdentifier.length()));
140       }
141       else
142       {
143          sbClassName.append(strModifier.toLowerCase());
144          sbClassName.append(".");
145          sbClassName.append(strClassIdentifier);
146       }
147
148       lstClassNames.add(sbClassName.toString());
149       sbClassName.delete(0, sbClassName.length());
150       // Now try database independent class aaa.AAAImpl
151
sbClassName.append(strClassIdentifier);
152       sbClassName.append("Impl");
153       lstClassNames.add(sbClassName.toString());
154       sbClassName.delete(0, sbClassName.length());
155       // And now just try class aaa.AAA
156
sbClassName.append(strClassIdentifier);
157       lstClassNames.add(sbClassName.toString());
158    }
159    
160    /**
161     * {@inheritDoc}
162     */

163    protected String JavaDoc getModifier(
164    ) throws OSSException
165    {
166       return m_strGuiTechnology;
167    }
168 }
169
Popular Tags