01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
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 and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.tools.generator;
25:
26: public abstract class AbstractCodeGeneratorImpl {
27: protected String getSourceCodeClassName(String className) {
28: return className.replace('$', '.');
29: }
30:
31: protected String[] getClassNames(Class types[]) {
32: String classNames[] = new String[types.length];
33: for (int i = 0; i < types.length; ++i) {
34: classNames[i] = getSourceCodeClassName(types[i].getName());
35: }
36:
37: return classNames;
38: }
39:
40: protected String getTypecode(Class classType) {
41: String typeCode = null;
42:
43: if (classType.isArray()) {
44: StringBuilder sb = new StringBuilder();
45: while (classType.isArray()) {
46: sb.append("[]");
47: classType = classType.getComponentType();
48: }
49: sb.insert(0, getSourceCodeClassName(classType.getName()));
50: typeCode = sb.toString();
51: } else {
52: typeCode = getSourceCodeClassName(classType.getName());
53: }
54:
55: return typeCode;
56: }
57:
58: protected Class[] parametersToClasses(
59: AbstractCodeGenerator.Parameter parameters[])
60: throws ClassNotFoundException {
61: Class classes[] = new Class[parameters.length];
62: for (int i = 0; i < parameters.length; i++) {
63: classes[i] = parameters[i].getClassType();
64: }
65:
66: return classes;
67: }
68:
69: protected AbstractCodeGenerator.Parameter[] getParameters(
70: Class parameterTypes[]) {
71: AbstractCodeGenerator.Parameter parameters[] = new AbstractCodeGenerator.Parameter[parameterTypes.length];
72: for (int i = 0; i < parameters.length; ++i) {
73: parameters[i] = new AbstractCodeGenerator.Parameter(
74: getTypecode(parameterTypes[i]), "arg" + i,
75: parameterTypes[i].getName());
76: }
77:
78: return parameters;
79: }
80: }
|