From 93504ae9b64d9479669c957d6cb9666713b9ea34 Mon Sep 17 00:00:00 2001 From: jamurty Date: Tue, 26 May 2009 20:50:59 +0000 Subject: [PATCH] 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 --- aws/core/pom.xml | 20 +++++++ .../jclouds/aws/codegen/model/Command.java | 13 +++++ .../jclouds/aws/codegen/model/Handler.java | 11 ++++ .../org/jclouds/aws/codegen/model/Model.java | 12 ++++ .../jclouds/aws/codegen/model/Package.java | 13 +++++ .../jclouds/aws/codegen/model/Parameter.java | 9 +++ .../jclouds/aws/codegen/model/Response.java | 12 ++++ .../aws/codegen/model/ResponseField.java | 8 +++ .../aws/codegen/util/CodeGenerator.java | 55 +++++++++++++++++++ 9 files changed, 153 insertions(+) create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Command.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Handler.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Model.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Package.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Parameter.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/Response.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/model/ResponseField.java create mode 100644 aws/core/src/main/java/org/jclouds/aws/codegen/util/CodeGenerator.java diff --git a/aws/core/pom.xml b/aws/core/pom.xml index 85757bd372..6cf0777085 100644 --- a/aws/core/pom.xml +++ b/aws/core/pom.xml @@ -46,6 +46,19 @@ http://jclouds.googlecode.com/svn/trunk/aws/core + + + gson + http://google-gson.googlecode.com/svn/mavenrepo + + true + + + true + + + + joda-time @@ -63,5 +76,12 @@ 1.2 test + + com.google.code.gson + gson + 1.3 + compile + + diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Command.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Command.java new file mode 100644 index 0000000000..611a9a22d2 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Command.java @@ -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 parameters; + private Handler handler; + private Response response; + private List see; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Handler.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Handler.java new file mode 100644 index 0000000000..060c88eb6f --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Handler.java @@ -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 see; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Model.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Model.java new file mode 100644 index 0000000000..6560f766c3 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Model.java @@ -0,0 +1,12 @@ +package org.jclouds.aws.codegen.model; + +import java.util.List; + +public class Model { + private List packages; + + @Override + public String toString() { + return packages.toString(); + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Package.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Package.java new file mode 100644 index 0000000000..4d7b048e78 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Package.java @@ -0,0 +1,13 @@ +package org.jclouds.aws.codegen.model; + +import java.util.List; + +public class Package { + private String name; + private List commands; + + @Override + public String toString() { + return String.format("{'name':'%1$s', 'commands':%2$s", name, commands); + } +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Parameter.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Parameter.java new file mode 100644 index 0000000000..263761645d --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Parameter.java @@ -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; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/Response.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Response.java new file mode 100644 index 0000000000..76b337168d --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/Response.java @@ -0,0 +1,12 @@ +package org.jclouds.aws.codegen.model; + +import java.util.List; + +public class Response { + private String className; + private List fields; + private String awsType; + private String javaType; + private String packageName; + private List see; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/model/ResponseField.java b/aws/core/src/main/java/org/jclouds/aws/codegen/model/ResponseField.java new file mode 100644 index 0000000000..bb9d09d0f4 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/model/ResponseField.java @@ -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; +} diff --git a/aws/core/src/main/java/org/jclouds/aws/codegen/util/CodeGenerator.java b/aws/core/src/main/java/org/jclouds/aws/codegen/util/CodeGenerator.java new file mode 100644 index 0000000000..bd984af148 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/codegen/util/CodeGenerator.java @@ -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 + * aws/src/main/bin/parse_ec2.pl) 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]); + } + +}