Allen, Christopher S. wrote:
One additional question, how hard would it be to have this thing to generate
Java code as well as AS2? Based on another post it sounds like you are doing
this conversion anyway before generating the AS2 files. The ability to generate
code in multiple languages with one tool would be incredibly useful for me, and
I'm sure for others as well. Would it be possible to set up templates (perhaps
XML files) for different languages, and if so, how would we go about doing this?
I'm not converting to Java *code* before generating the AS2 code. What
I'm doing is parsing the XMI into classes, and then examing those
classes to write the code. For example, my "Class.java" stores
information about a class, and looks like this:
// BEGIN Class.java
package com.darronschall.xmi2as.xmi;
import java.util.Vector;
/**
* @author Darron Schall
*/
public class Class extends PackageElement {
public boolean isAbstract = false;
public int visibility;
public Class superClass;
public Vector implementedInterfaces;
public Vector attributes;
public Vector operations;
public Class() {
implementedInterfaces = new Vector();
attributes = new Vector();
operations = new Vector();
}
}
// END Class.java
So then I have an AS2CodeGenerator.java file that has a method like this
(this is just a code snippet here...)
private void writeClass(Class c) {
print("class " + buildPackageChain(c) + c.name);
if (c.superClass != null) {
print(" extends " + c.superClass.name);
}
Iterator it = c.implementedInterfaces.iterator();
if (it.hasNext()) {
print(" implements");
while (it.hasNext()) {
Interface i = (Interface)it.next();
// TODO: add imports for implemented interfaces
print( " " + i.name );
if (it.hasNext()) {
print(",");
}
}
}
println(" {");
// loop over c.attributes
// loop over c.operations
println('}');
}
So, when you generate the code, a new AS2CodeGenerator is instantiated
and passed the "root" package (containing classes / subpackges, etc).
The code generator then loops over everything and write the files (with
methods like writePackage, writeClass, writeInterface, writeOperation,
writeAttribute, etc). If you want to generate java code, you would
essentially just create a new class - JavaCodeGenerator and just change
the "print" and "println" statements that you see in AS2CodeGenerator in
the "write" methods to adjust for the java syntax. Thus, it's pretty
easy to have it generate files for a different syntax (even like
ColdFusion - you can write a CFCCodeGenerator if you wanted).
Once Aral can set up the SVN repository, I'll post the code.
If you want to get into using templates and such for code generation,
it's probably better to go with one of the many code generators already
built. I'm pretty sure some already exist.. and I probably didn't have
to build this by hand at all, it just seemed easier to reinvent the
wheel than figure out how to operate someone else's. I looked at
http://sourceforge.net/projects/andromda but it just seemed overly
complex for what I wanted to do...
-d
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org