com.dyuproject.protostuff.runtime
Class RuntimeSchema<T>

java.lang.Object
  extended by com.dyuproject.protostuff.runtime.MappedSchema<T>
      extended by com.dyuproject.protostuff.runtime.RuntimeSchema<T>
All Implemented Interfaces:
Schema<T>

public final class RuntimeSchema<T>
extends MappedSchema<T>

A schema that can be generated and cached at runtime for objects that have no schema. This is particularly useful for pojos from 3rd party libraries.

Author:
David Yu
Date created:
Nov 9, 2009

Nested Class Summary
 
Nested classes/interfaces inherited from class com.dyuproject.protostuff.runtime.MappedSchema
MappedSchema.Field<T>
 
Field Summary
 RuntimeEnv.Instantiator<T> instantiator
           
 
Fields inherited from class com.dyuproject.protostuff.runtime.MappedSchema
fields, fieldsByName, fieldsByNumber, pipeSchema, typeClass
 
Constructor Summary
RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<MappedSchema.Field<T>> fields, int lastFieldNumber, java.lang.reflect.Constructor<T> constructor)
           
RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<MappedSchema.Field<T>> fields, int lastFieldNumber, RuntimeEnv.Instantiator<T> instantiator)
           
 
Method Summary
static
<T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass)
          Generates a schema from the given class.
static
<T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, IdStrategy strategy)
          Generates a schema from the given class.
static
<T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.util.Map<java.lang.String,java.lang.String> declaredFields, IdStrategy strategy)
          Generates a schema from the given class with the declared fields (inclusive) based from the given Map.
static
<T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.util.Set<java.lang.String> exclusions, IdStrategy strategy)
          Generates a schema from the given class with the exclusion of certain fields.
static
<T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.lang.String[] exclusions, IdStrategy strategy)
          Generates a schema from the given class with the exclusion of certain fields.
static
<T> Schema<T>
getSchema(java.lang.Class<T> typeClass)
          Gets the schema that was either registered or lazily initialized at runtime.
static
<T> Schema<T>
getSchema(java.lang.Class<T> typeClass, IdStrategy strategy)
          Gets the schema that was either registered or lazily initialized at runtime.
 boolean isInitialized(T message)
          Always returns true, everything is optional.
static boolean isRegistered(java.lang.Class<?> typeClass)
          Returns true if the typeClass was not lazily created.
static boolean isRegistered(java.lang.Class<?> typeClass, IdStrategy strategy)
          Returns true if the typeClass was not lazily created.
static
<T> boolean
map(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)
          Maps the baseClass to a specific non-interface/non-abstract typeClass and registers it (this must be done on application startup).
 T newMessage()
           
static
<T> boolean
register(java.lang.Class<T> typeClass, Schema<T> schema)
          Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).
 
Methods inherited from class com.dyuproject.protostuff.runtime.MappedSchema
getFieldCount, getFieldName, getFieldNumber, getPipeSchema, mergeFrom, messageFullName, messageName, typeClass, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instantiator

public final RuntimeEnv.Instantiator<T> instantiator
Constructor Detail

RuntimeSchema

public RuntimeSchema(java.lang.Class<T> typeClass,
                     java.util.Collection<MappedSchema.Field<T>> fields,
                     int lastFieldNumber,
                     java.lang.reflect.Constructor<T> constructor)

RuntimeSchema

public RuntimeSchema(java.lang.Class<T> typeClass,
                     java.util.Collection<MappedSchema.Field<T>> fields,
                     int lastFieldNumber,
                     RuntimeEnv.Instantiator<T> instantiator)
Method Detail

map

public static <T> boolean map(java.lang.Class<? super T> baseClass,
                              java.lang.Class<T> typeClass)
Maps the baseClass to a specific non-interface/non-abstract typeClass and registers it (this must be done on application startup). With this approach, there is no overhead of writing the type metadata if a baseClass field is serialized. Returns true if the baseClass does not exist. NOTE: This is only supported when RuntimeEnv.ID_STRATEGY is DefaultIdStrategy.

Throws:
java.lang.IllegalArgumentException - if the typeClass is an interface or an abstract class.

register

public static <T> boolean register(java.lang.Class<T> typeClass,
                                   Schema<T> schema)
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup). NOTE: This is only supported when RuntimeEnv.ID_STRATEGY is DefaultIdStrategy.


isRegistered

public static boolean isRegistered(java.lang.Class<?> typeClass)
Returns true if the typeClass was not lazily created. Method overload for backwards compatibility.


isRegistered

public static boolean isRegistered(java.lang.Class<?> typeClass,
                                   IdStrategy strategy)
Returns true if the typeClass was not lazily created.


getSchema

public static <T> Schema<T> getSchema(java.lang.Class<T> typeClass)
Gets the schema that was either registered or lazily initialized at runtime. Method overload for backwards compatibility.


getSchema

public static <T> Schema<T> getSchema(java.lang.Class<T> typeClass,
                                      IdStrategy strategy)
Gets the schema that was either registered or lazily initialized at runtime.


createFrom

public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass)
Generates a schema from the given class. Method overload for backwards compatibility.


createFrom

public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass,
                                              IdStrategy strategy)
Generates a schema from the given class.


createFrom

public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass,
                                              java.lang.String[] exclusions,
                                              IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.


createFrom

public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass,
                                              java.util.Set<java.lang.String> exclusions,
                                              IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.


createFrom

public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass,
                                              java.util.Map<java.lang.String,java.lang.String> declaredFields,
                                              IdStrategy strategy)
Generates a schema from the given class with the declared fields (inclusive) based from the given Map. The value of a the Map's entry will be the name used for the field (which enables aliasing).


isInitialized

public boolean isInitialized(T message)
Always returns true, everything is optional.


newMessage

public T newMessage()


Copyright © 2009-2014. All Rights Reserved.