{
clazz = request.getClassLoader().loadClass( classname );
}
catch ( ClassNotFoundException e )
{
throw new GenerationException( e.getMessage(), e );
}
List<Field> fieldsToGenerate = new ArrayList<Field>();
Field[] fields = clazz.getFields();
for ( Field field : fields )
{
if ( isPublic( field.getModifiers() ) && isStatic( field.getModifiers() )
&& isFinal( field.getModifiers() ) && isPrimitive( field.getType() ) )
{
fieldsToGenerate.add( field );
}
}
if ( fieldsToGenerate.isEmpty() )
{
continue;
}
File outDir = request.getTransientOutputFolder();
outDir = new File( outDir, clazz.getPackage().getName().replace( '.', '/' ) );
outDir.mkdirs();
File outFile = new File( outDir, clazz.getSimpleName() + ".as" );
FileWriter fw;
try
{
fw = new FileWriter( outFile );
fw.append( "package " ).append( clazz.getPackage().getName() ).append( '{' ).append( '\n' );
fw.append( "public class " ).append( clazz.getSimpleName() ).append( '{' ).append( '\n' );
for ( Field field : fieldsToGenerate )
{
fw.append( "public static const " ).append( field.getName() ).append( ':' );
fw.append( getAsType( field.getType() ) ).append( '=' );
fw.append( toString( field.get( clazz.newInstance() ) ) ).append( ';' ).append( '\n' );
}
fw.append( '}' ).append( '\n' );
fw.append( '}' ).append( '\n' );
fw.flush();
fw.close();
}
catch ( Exception e )
{
throw new GenerationException( "Error generating " + clazz.getName(), e );
}
}
}