///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
//
// All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License and GNU Library
// General Public License as published by the Free Software Foundation;
// either version 2, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License and GNU Library General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// and GNU Library General Public License along with this program; if
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
// MA 02139, USA.
//
///////////////////////////////////////////////////////////////////////////////
package org.myoodb.tools.generator;
public abstract class AbstractCodeGeneratorImpl
{
protected String getSourceCodeClassName(String className)
{
return className.replace('$', '.');
}
protected String[] getClassNames(Class types[])
{
String classNames[] = new String[types.length];
for (int i = 0; i < types.length; ++i)
{
classNames[i] = getSourceCodeClassName(types[i].getName());
}
return classNames;
}
protected String getTypecode(Class classType)
{
String typeCode = null;
if (classType.isArray())
{
StringBuilder sb = new StringBuilder();
while (classType.isArray())
{
sb.append("[]");
classType = classType.getComponentType();
}
sb.insert(0, getSourceCodeClassName(classType.getName()));
typeCode = sb.toString();
}
else
{
typeCode = getSourceCodeClassName(classType.getName());
}
return typeCode;
}
protected Class[] parametersToClasses(AbstractCodeGenerator.Parameter parameters[]) throws ClassNotFoundException
{
Class classes[] = new Class[parameters.length];
for (int i = 0; i < parameters.length; i++)
{
classes[i] = parameters[i].getClassType();
}
return classes;
}
protected AbstractCodeGenerator.Parameter[] getParameters(Class parameterTypes[])
{
AbstractCodeGenerator.Parameter parameters[] = new AbstractCodeGenerator.Parameter[parameterTypes.length];
for (int i = 0; i < parameters.length; ++i)
{
parameters[i] = new AbstractCodeGenerator.Parameter(getTypecode(parameterTypes[i]), "arg" + i, parameterTypes[i].getName());
}
return parameters;
}
}
|