org.apache.avro.reflect
Class ReflectData

java.lang.Object
  extended by org.apache.avro.generic.GenericData
      extended by org.apache.avro.reflect.ReflectData
Direct Known Subclasses:
ReflectData.AllowNull, SpecificData

public class ReflectData
extends GenericData

Utilities to use existing Java classes and interfaces via reflection.


Nested Class Summary
static class ReflectData.AllowNull
          ReflectData implementation that permits null field values.
 
Nested classes/interfaces inherited from class org.apache.avro.generic.GenericData
GenericData.Array<T>, GenericData.Fixed, GenericData.Record
 
Constructor Summary
protected ReflectData()
           
 
Method Summary
protected  Schema createFieldSchema(Field field, Map<String,Schema> names)
          Create a schema for a field.
protected  Schema createSchema(Type type, Map<String,Schema> names)
          Create a schema for a type and it's fields.
static ReflectData get()
          Return the singleton instance.
 Class getClass(Schema schema)
          Return the class that implements this schema.
 String getClassName(Schema schema)
          Returns the Java class name indicated by a schema's name and namespace.
 Protocol getProtocol(Class iface)
          Generate a protocol for a Java interface.
protected  Schema getRecordSchema(Object record)
          Called to obtain the schema of a record.
 Schema getSchema(Type type)
          Generate a schema for a Java type.
protected  boolean isEnum(Object datum)
          Called by the default implementation of GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isRecord(Object datum)
          Called by the default implementation of GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).
 boolean validate(Schema schema, Object datum)
          Returns true if an object matches a schema.
 
Methods inherited from class org.apache.avro.generic.GenericData
compare, induce, instanceOf, isArray, isBytes, isFixed, isMap, isString, resolveUnion, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectData

protected ReflectData()
Method Detail

get

public static ReflectData get()
Return the singleton instance.


isRecord

protected boolean isRecord(Object datum)
Description copied from class: GenericData
Called by the default implementation of GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).

Overrides:
isRecord in class GenericData

getRecordSchema

protected Schema getRecordSchema(Object record)
Description copied from class: GenericData
Called to obtain the schema of a record. By default calls {GenericRecord#getSchema(). May be overridden for alternate record representations.

Overrides:
getRecordSchema in class GenericData

isEnum

protected boolean isEnum(Object datum)
Description copied from class: GenericData
Called by the default implementation of GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).

Overrides:
isEnum in class GenericData

validate

public boolean validate(Schema schema,
                        Object datum)
Returns true if an object matches a schema.

Overrides:
validate in class GenericData

getClass

public Class getClass(Schema schema)
Return the class that implements this schema.


getClassName

public String getClassName(Schema schema)
Returns the Java class name indicated by a schema's name and namespace.


getSchema

public Schema getSchema(Type type)
Generate a schema for a Java type.

For records, declared fields (not inherited) which are not static or transient are used.

Note that unions cannot be automatically generated by this method, since Java provides no representation for unions.


createSchema

protected Schema createSchema(Type type,
                              Map<String,Schema> names)
Create a schema for a type and it's fields. Note that by design only fields of the direct class, not it's super classes, are used for creating the schema. Also, fields are not permitted to be null.


createFieldSchema

protected Schema createFieldSchema(Field field,
                                   Map<String,Schema> names)
Create a schema for a field.


getProtocol

public Protocol getProtocol(Class iface)
Generate a protocol for a Java interface.

Note that this requires that Paranamer is run over compiled interface declarations, since Java 6 reflection does not provide access to method parameter names. See Avro's build.xml for an example.



Copyright © 2009 The Apache Software Foundation