org.apache.avro.reflect
Class ReflectData

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

public class ReflectData
extends SpecificData

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.EnumSymbol, GenericData.Fixed, GenericData.Record
 
Constructor Summary
protected ReflectData()
           
 
Method Summary
 int compare(Object o1, Object o2, Schema s)
          Compare objects according to their schema.
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 the schema for a Java type.
static ReflectData get()
          Return the singleton instance.
 Class getClass(Schema schema)
          Return the class that implements a schema, or null if none exists.
protected static Field getField(Class c, String name)
          Return the named field of the provided class.
 Protocol getProtocol(Class iface)
          Return the protocol for a Java interface.
protected  Schema getRecordSchema(Object record)
          Called to obtain the schema of a record.
protected  boolean isArray(Object datum)
          Called by the default implementation of GenericData.instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isBytes(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).
static Schema makeNullable(Schema schema)
          Create and return a union of the null schema and the provided schema.
 boolean validate(Schema schema, Object datum)
          Returns true if a Java datum matches a schema.
 
Methods inherited from class org.apache.avro.specific.SpecificData
getClassName, getSchema, isEnum
 
Methods inherited from class org.apache.avro.generic.GenericData
hashCode, hashCodeAdd, induce, instanceOf, isFixed, isMap, isString, resolveUnion, toString, 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

isArray

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

Overrides:
isArray in class GenericData

isBytes

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

Overrides:
isBytes 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 {GenericContainer#getSchema(). May be overridden for alternate record representations.

Overrides:
getRecordSchema in class GenericData

validate

public boolean validate(Schema schema,
                        Object datum)
Description copied from class: GenericData
Returns true if a Java datum matches a schema.

Overrides:
validate in class GenericData

getField

protected static Field getField(Class c,
                                String name)
Return the named field of the provided class. Implementation caches values, since this is used at runtime to get and set fields.


getClass

public Class getClass(Schema schema)
Description copied from class: SpecificData
Return the class that implements a schema, or null if none exists.

Overrides:
getClass in class SpecificData

createSchema

protected Schema createSchema(Type type,
                              Map<String,Schema> names)
Description copied from class: SpecificData
Create the schema for a Java type.

Overrides:
createSchema in class SpecificData

makeNullable

public static Schema makeNullable(Schema schema)
Create and return a union of the null schema and the provided schema.


createFieldSchema

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


getProtocol

public Protocol getProtocol(Class iface)
Return the 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.

Overrides:
getProtocol in class SpecificData

compare

public int compare(Object o1,
                   Object o2,
                   Schema s)
Description copied from class: GenericData
Compare objects according to their schema. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that of BinaryData.compare(byte[], int, byte[], int, Schema).

Overrides:
compare in class SpecificData


Copyright © 2010 The Apache Software Foundation