KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > strongtyper > Generator


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.strongtyper;
31
32 import java.util.List JavaDoc;
33
34 import com.genimen.djeneric.repository.DjDomain;
35 import com.genimen.djeneric.repository.DjExtent;
36 import com.genimen.djeneric.repository.DjProperty;
37 import com.genimen.djeneric.util.DjStringReplacer;
38
39 public abstract class Generator
40 {
41   public final static String JavaDoc IMPL_SUFFIX = "Impl";
42
43   public final static String JavaDoc ABSTRACT_SESSION_CLASS_NAME = "AbstractSessionImpl";
44   public final static String JavaDoc SESSION_CLASS_NAME = "SessionImpl";
45   public final static String JavaDoc SESSION_INTERFACE_NAME = "Session";
46   public final static String JavaDoc MANAGER_CLASS_NAME = "PersistenceManager";
47   public final static String JavaDoc EXCEPTION_CLASS_NAME = "Exception";
48   public final static String JavaDoc NOT_FOUND_EXCEPTION_CLASS_NAME = "NotFoundException";
49   public final static String JavaDoc MULTIPLE_FOUND_EXCEPTION_CLASS_NAME = "MultipleFoundException";
50   public final static String JavaDoc PARENT_CLASS_NAME = "ObjectImpl";
51   public final static String JavaDoc PARENT_INTERFACE_NAME = "Object";
52   public final static String JavaDoc QBE_CLASS_NAME = "QbeImpl";
53   public final static String JavaDoc QBE_INTERFACE_NAME = "Qbe";
54   public final static String JavaDoc OQL_CLASS_NAME = "OqlImpl";
55   public final static String JavaDoc OQL_INTERFACE_NAME = "Oql";
56   public final static String JavaDoc CURSOR_CLASS_NAME = "CursorImpl";
57   public final static String JavaDoc CURSOR_INTERFACE_NAME = "Cursor";
58
59   String JavaDoc _itfPackageName = "";
60   String JavaDoc _implPackageName = "";
61   String JavaDoc _busPackageName = "";
62   String JavaDoc _busImplPackageName = "";
63   String JavaDoc _uiPackageName = "";
64   String JavaDoc _systemPrefix = "";
65   String JavaDoc _systemName = "";
66   String JavaDoc _prefix = "";
67   String JavaDoc _suffix = "";
68
69   boolean _isAbstract = false;
70
71   private List JavaDoc _extentSet;
72
73   public Generator()
74   {
75   }
76
77   public abstract String JavaDoc getClassName();
78
79   public abstract String JavaDoc getCode() throws Exception JavaDoc;
80
81   public String JavaDoc getGeneratedSuffix()
82
83   {
84     return "Gtd";
85   }
86
87   public boolean isInSelectedSet(DjExtent ext)
88   {
89     return _extentSet.contains(ext);
90   }
91
92   public void setAbstract(boolean b)
93   {
94     _isAbstract = b;
95   }
96
97   public boolean isAbstract()
98   {
99     return _isAbstract;
100   }
101
102   public String JavaDoc translateNativeType(String JavaDoc tp)
103   {
104     if (tp.equals("Date")) return "java.util.Date";
105     return tp;
106   }
107
108   public boolean containsBigDecimal(DjExtent extent)
109   {
110     DjProperty props[] = extent.getProperties();
111
112     for (int i = 0; i < props.length; i++)
113     {
114       if (props[i].getTypeCode() == DjDomain.BIGDECIMAL_TYPE) return true;
115     }
116     return false;
117   }
118
119   public String JavaDoc getPrefix()
120   {
121     return _prefix;
122   }
123
124   public void setPrefix(String JavaDoc prefix)
125   {
126     _prefix = prefix;
127   }
128
129   public String JavaDoc getSystemPrefix()
130   {
131     return _systemPrefix;
132   }
133
134   public void setSystemPrefix(String JavaDoc prefix)
135   {
136     _systemPrefix = prefix;
137   }
138
139   public String JavaDoc getSystemName()
140   {
141     return _systemName;
142   }
143
144   public void setSystemName(String JavaDoc name)
145   {
146     _systemName = name;
147   }
148
149   public String JavaDoc getItfPackageName()
150   {
151     return _itfPackageName;
152   }
153
154   public void setItfPackageName(String JavaDoc packageName)
155   {
156     _itfPackageName = packageName;
157   }
158
159   public String JavaDoc getBusinessPackageName()
160   {
161     return _busPackageName;
162   }
163
164   public void setBusinessPackageName(String JavaDoc packageName)
165   {
166     _busPackageName = packageName;
167   }
168
169   public String JavaDoc getBusinessImplPackageName()
170   {
171     return _busImplPackageName;
172   }
173
174   public void setBusinessImplPackageName(String JavaDoc packageName)
175   {
176     _busImplPackageName = packageName;
177   }
178
179   public String JavaDoc getUiPackageName()
180   {
181     return _uiPackageName;
182   }
183
184   public void setUiPackageName(String JavaDoc packageName)
185   {
186     _uiPackageName = packageName;
187   }
188
189   public abstract String JavaDoc getPackageName();
190
191   public String JavaDoc getImplPackageName()
192   {
193     return _implPackageName;
194   }
195
196   public void setImplPackageName(String JavaDoc packageName)
197   {
198     _implPackageName = packageName;
199   }
200
201   public String JavaDoc getSuffix()
202   {
203     return _suffix;
204   }
205
206   public void setSuffix(String JavaDoc suffix)
207   {
208     _suffix = suffix;
209   }
210
211   public String JavaDoc getClassName(DjExtent extent)
212   {
213     return getPrefix() + extent.getObjectType() + getSuffix() + IMPL_SUFFIX;
214   }
215
216   public String JavaDoc getInterfaceName(DjExtent extent)
217   {
218     return getPrefix() + extent.getObjectType() + getSuffix();
219   }
220
221   public String JavaDoc getQbeClassName(DjExtent extent)
222   {
223     return getPrefix() + extent.getObjectType() + QBE_CLASS_NAME;
224   }
225
226   public String JavaDoc getQbeInterfaceName(DjExtent extent)
227   {
228     return getPrefix() + extent.getObjectType() + QBE_INTERFACE_NAME;
229   }
230
231   public String JavaDoc getCursorClassName(DjExtent extent)
232   {
233     return getPrefix() + extent.getObjectType() + CURSOR_CLASS_NAME;
234   }
235
236   public String JavaDoc getCursorInterfaceName(DjExtent extent)
237   {
238     return getPrefix() + extent.getObjectType() + CURSOR_INTERFACE_NAME;
239   }
240
241   public String JavaDoc getAbstractSessionClassName()
242   {
243     return getSystemPrefix() + ABSTRACT_SESSION_CLASS_NAME;
244   }
245
246   public String JavaDoc getSessionClassName()
247   {
248     return getSystemPrefix() + SESSION_CLASS_NAME;
249   }
250
251   public String JavaDoc getSessionInterfaceName()
252   {
253     return getSystemPrefix() + SESSION_INTERFACE_NAME;
254   }
255
256   public String JavaDoc getExceptionClassName()
257   {
258     return getSystemPrefix() + EXCEPTION_CLASS_NAME;
259   }
260
261   public String JavaDoc getNotFoundExceptionClassName()
262   {
263     return getSystemPrefix() + NOT_FOUND_EXCEPTION_CLASS_NAME;
264   }
265
266   public String JavaDoc getMultipleFoundExceptionClassName()
267   {
268     return getSystemPrefix() + MULTIPLE_FOUND_EXCEPTION_CLASS_NAME;
269   }
270
271   public String JavaDoc getManagerClassName()
272   {
273     return getSystemPrefix() + MANAGER_CLASS_NAME;
274   }
275
276   public String JavaDoc getOqlClassName()
277   {
278     return OQL_CLASS_NAME;
279   }
280
281   public String JavaDoc getOqlInterfaceName()
282   {
283     return OQL_INTERFACE_NAME;
284   }
285
286   public String JavaDoc getParentObjectClassName()
287   {
288     return getSystemPrefix() + PARENT_CLASS_NAME;
289   }
290
291   public String JavaDoc getParentInterfaceClassName()
292   {
293     return getSystemPrefix() + PARENT_INTERFACE_NAME;
294   }
295
296   public String JavaDoc initCap(String JavaDoc str)
297   {
298     if (str == null) return str;
299     DjStringReplacer sr = new DjStringReplacer(str);
300     str = sr.replace(" ", "");
301
302     if (str.length() < 2) return str.toUpperCase();
303
304     return str.substring(0, 1).toUpperCase() + str.substring(1);
305   }
306
307   public String JavaDoc constCap(String JavaDoc str)
308   {
309     if (str == null) return str;
310     String JavaDoc result = "";
311
312     DjStringReplacer sr = new DjStringReplacer(str);
313     str = sr.replace(" ", "");
314
315     boolean prevWasLower = false;
316     for (int i = 0; i < str.length(); i++)
317     {
318       // encountered an upper case char and prev char was lower?
319
boolean curIsLower = str.charAt(i) == str.toUpperCase().charAt(i);
320       if (prevWasLower && curIsLower)
321       {
322         result += "_";
323       }
324       prevWasLower = !curIsLower;
325       result += str.toUpperCase().charAt(i);
326     }
327     return result;
328   }
329
330   public void setExtentSet(List JavaDoc set)
331   {
332     _extentSet = set;
333
334   }
335 }
Popular Tags