org.apache.avro.compiler.specific
Class SpecificCompiler

java.lang.Object
  extended by org.apache.avro.compiler.specific.SpecificCompiler

public class SpecificCompiler
extends Object

Generate specific Java interfaces and classes for protocols and schemas. Java reserved keywords are mangled to preserve compilation.


Nested Class Summary
static class SpecificCompiler.Slf4jLogChute
           
 
Constructor Summary
SpecificCompiler(Protocol protocol)
           
SpecificCompiler(Schema schema)
           
 
Method Summary
static void compileProtocol(File[] srcFiles, File dest)
          Generates Java interface and classes for a number of protocol files.
static void compileProtocol(File src, File dest)
          Generates Java interface and classes for a protocol.
static void compileSchema(File[] srcFiles, File dest)
          Generates Java classes for a number of schema files.
static void compileSchema(File src, File dest)
          Generates Java classes for a schema.
 void compileToDestination(File src, File dst)
          Generate output under dst, unless existing file is newer than src.
static String escapeForJavadoc(String s)
          Utility for template use.
static String generateClearMethod(Schema schema, Schema.Field field)
          Generates the name of a field "clear" method.
static String generateGetMethod(Schema schema, Schema.Field field)
          Generates the name of a field accessor method.
static String generateHasMethod(Schema schema, Schema.Field field)
          Generates the name of a field "has" method.
static String generateSetMethod(Schema schema, Schema.Field field)
          Generates the name of a field mutator method.
static boolean isUnboxedJavaTypeNullable(Schema schema)
          Tests whether an unboxed Java type can be set to null
static String javaEscape(Object o)
          Utility for template use.
 String javaType(Schema schema)
          Utility for template use.
 String javaUnbox(Schema schema)
          Utility for template use.
static void main(String[] args)
           
static String mangle(String word)
          Utility for template use.
static String mangle(String word, boolean isError)
          Utility for template use.
static String mangle(String word, Set<String> reservedWords)
          Utility for template use.
static String mangle(String word, Set<String> reservedWords, boolean isMethod)
          Utility for template use.
static String nullToEmpty(String x)
          Utility for template use.
 void setStringType(GenericData.StringType t)
          Set the Java type to be emitted for string schemas.
 void setTemplateDir(String templateDir)
          Set the CLASSPATH resource directory where templates reside.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpecificCompiler

public SpecificCompiler(Protocol protocol)

SpecificCompiler

public SpecificCompiler(Schema schema)
Method Detail

setTemplateDir

public void setTemplateDir(String templateDir)
Set the CLASSPATH resource directory where templates reside.


compileProtocol

public static void compileProtocol(File src,
                                   File dest)
                            throws IOException
Generates Java interface and classes for a protocol.

Parameters:
src - the source Avro protocol file
dest - the directory to place generated files in
Throws:
IOException

compileProtocol

public static void compileProtocol(File[] srcFiles,
                                   File dest)
                            throws IOException
Generates Java interface and classes for a number of protocol files.

Parameters:
srcFiles - the source Avro protocol files
dest - the directory to place generated files in
Throws:
IOException

compileSchema

public static void compileSchema(File src,
                                 File dest)
                          throws IOException
Generates Java classes for a schema.

Throws:
IOException

compileSchema

public static void compileSchema(File[] srcFiles,
                                 File dest)
                          throws IOException
Generates Java classes for a number of schema files.

Throws:
IOException

compileToDestination

public void compileToDestination(File src,
                                 File dst)
                          throws IOException
Generate output under dst, unless existing file is newer than src.

Throws:
IOException

setStringType

public void setStringType(GenericData.StringType t)
Set the Java type to be emitted for string schemas.


javaType

public String javaType(Schema schema)
Utility for template use. Returns the java type for a Schema.


javaUnbox

public String javaUnbox(Schema schema)
Utility for template use. Returns the unboxed java type for a Schema.


javaEscape

public static String javaEscape(Object o)
Utility for template use. Escapes quotes and backslashes.


escapeForJavadoc

public static String escapeForJavadoc(String s)
Utility for template use. Escapes comment end with HTML entities.


nullToEmpty

public static String nullToEmpty(String x)
Utility for template use. Returns empty string for null.


mangle

public static String mangle(String word)
Utility for template use. Adds a dollar sign to reserved words.


mangle

public static String mangle(String word,
                            boolean isError)
Utility for template use. Adds a dollar sign to reserved words.


mangle

public static String mangle(String word,
                            Set<String> reservedWords)
Utility for template use. Adds a dollar sign to reserved words.


mangle

public static String mangle(String word,
                            Set<String> reservedWords,
                            boolean isMethod)
Utility for template use. Adds a dollar sign to reserved words.


generateGetMethod

public static String generateGetMethod(Schema schema,
                                       Schema.Field field)
Generates the name of a field accessor method.

Parameters:
schema - the schema in which the field is defined.
field - the field for which to generate the accessor name.
Returns:
the name of the accessor method for the given field.

generateSetMethod

public static String generateSetMethod(Schema schema,
                                       Schema.Field field)
Generates the name of a field mutator method.

Parameters:
schema - the schema in which the field is defined.
field - the field for which to generate the accessor name.
Returns:
the name of the mutator method for the given field.

generateHasMethod

public static String generateHasMethod(Schema schema,
                                       Schema.Field field)
Generates the name of a field "has" method.

Parameters:
schema - the schema in which the field is defined.
field - the field for which to generate the accessor name.
Returns:
the name of the has method for the given field.

generateClearMethod

public static String generateClearMethod(Schema schema,
                                         Schema.Field field)
Generates the name of a field "clear" method.

Parameters:
schema - the schema in which the field is defined.
field - the field for which to generate the accessor name.
Returns:
the name of the has method for the given field.

isUnboxedJavaTypeNullable

public static boolean isUnboxedJavaTypeNullable(Schema schema)
Tests whether an unboxed Java type can be set to null


main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.