Added the (very early) beginnings of a Java-based code generator. Currenly only parses JSON document produced by the perl API docs scraper and produces a Java object graph.

git-svn-id: http://jclouds.googlecode.com/svn/trunk@857 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
jamurty 2009-05-26 20:50:59 +00:00
parent ce49993f64
commit 93504ae9b6
9 changed files with 153 additions and 0 deletions

View File

@ -46,6 +46,19 @@
<url>http://jclouds.googlecode.com/svn/trunk/aws/core</url>
</scm>
<repositories>
<repository>
<id>gson</id>
<url>http://google-gson.googlecode.com/svn/mavenrepo</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
@ -63,5 +76,12 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package org.jclouds.aws.codegen.model;
import java.util.List;
public class Command {
private String className;
private String packageName;
private String awsType;
private List<Parameter> parameters;
private Handler handler;
private Response response;
private List<String> see;
}

View File

@ -0,0 +1,11 @@
package org.jclouds.aws.codegen.model;
import java.util.List;
public class Handler {
private String className;
private String example;
private String awsType;
private String packageName;
private List<String> see;
}

View File

@ -0,0 +1,12 @@
package org.jclouds.aws.codegen.model;
import java.util.List;
public class Model {
private List<Package> packages;
@Override
public String toString() {
return packages.toString();
}
}

View File

@ -0,0 +1,13 @@
package org.jclouds.aws.codegen.model;
import java.util.List;
public class Package {
private String name;
private List<Command> commands;
@Override
public String toString() {
return String.format("{'name':'%1$s', 'commands':%2$s", name, commands);
}
}

View File

@ -0,0 +1,9 @@
package org.jclouds.aws.codegen.model;
public class Parameter {
private String name;
private String type;
private String javaType;
private String param;
private String desc;
}

View File

@ -0,0 +1,12 @@
package org.jclouds.aws.codegen.model;
import java.util.List;
public class Response {
private String className;
private List<ResponseField> fields;
private String awsType;
private String javaType;
private String packageName;
private List<String> see;
}

View File

@ -0,0 +1,8 @@
package org.jclouds.aws.codegen.model;
public class ResponseField {
private String desc;
private String name;
private String type;
private String javaType;
}

View File

@ -0,0 +1,55 @@
package org.jclouds.aws.codegen.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.jclouds.aws.codegen.model.Model;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
/**
* TODO: Finish this class and document it.
*
*
* @author James Murty
*/
public class CodeGenerator {
/**
* Parses a JSON object model file (as generated by
* <tt>aws/src/main/bin/parse_ec2.pl</tt>) and converts
* it into a Java object graph.
*
* @param objectModelFile
* @return
* @throws JsonParseException
* @throws FileNotFoundException
*/
public Model parseModelFromJSON(File objectModelFile)
throws JsonParseException, FileNotFoundException
{
Gson gson = new Gson();
return gson.fromJson(new FileReader(objectModelFile), Model.class);
}
public void generateCode(File objectModelFile, String rootPackageName)
throws JsonParseException, FileNotFoundException
{
Model model = parseModelFromJSON(objectModelFile);
}
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage: CodeGenerator objectModelFile rootPackage");
System.out.println(" E.g: CodeGenerator ec2.json org.jclouds.aws.ec2");
System.exit(1);
}
CodeGenerator codeGenerator = new CodeGenerator();
codeGenerator.generateCode(new File(args[0]), args[1]);
}
}