mirror of
https://github.com/apache/jclouds.git
synced 2025-02-17 23:46:13 +00:00
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:
parent
ce49993f64
commit
93504ae9b6
@ -46,6 +46,19 @@
|
|||||||
<url>http://jclouds.googlecode.com/svn/trunk/aws/core</url>
|
<url>http://jclouds.googlecode.com/svn/trunk/aws/core</url>
|
||||||
</scm>
|
</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>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>joda-time</groupId>
|
<groupId>joda-time</groupId>
|
||||||
@ -63,5 +76,12 @@
|
|||||||
<version>1.2</version>
|
<version>1.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>1.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user