com.dyuproject.protostuff.runtime
Class DefaultIdStrategy

java.lang.Object
  extended by com.dyuproject.protostuff.runtime.IdStrategy
      extended by com.dyuproject.protostuff.runtime.DefaultIdStrategy

public final class DefaultIdStrategy
extends IdStrategy

The FQCN(fully qualified class name) will serve as the id (string). Does not need any registration in the user-code (works out-of-the-box). The size of serialized representation may be not very efficient.

Author:
Leo Romanoff, David Yu

Nested Class Summary
 
Nested classes/interfaces inherited from class com.dyuproject.protostuff.runtime.IdStrategy
IdStrategy.Factory, IdStrategy.UnknownTypeException
 
Field Summary
 
Fields inherited from class com.dyuproject.protostuff.runtime.IdStrategy
groupId, primaryGroup
 
Constructor Summary
DefaultIdStrategy()
           
DefaultIdStrategy(IdStrategy primaryGroup, int groupId)
           
 
Method Summary
protected  CollectionSchema.MessageFactory getCollectionFactory(java.lang.Class<?> clazz)
          Returns the CollectionSchema.MessageFactory.
<T> Delegate<T>
getDelegate(java.lang.Class<? super T> typeClass)
          Returns the delegate.
protected  EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.Class<?> enumClass)
          Returns the EnumIO.
protected  MapSchema.MessageFactory getMapFactory(java.lang.Class<?> clazz)
          Returns the MapSchema.MessageFactory.
<T> HasSchema<T>
getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
          Returns the schema wrapper.
 boolean isDelegateRegistered(java.lang.Class<?> typeClass)
          Returns true if there is a Delegate explicitly registered for the typeClass.
 boolean isRegistered(java.lang.Class<?> typeClass)
          Returns true if the typeClass is explicitly registered.
<T> boolean
map(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)
          Used by RuntimeSchema.map(Class, Class).
 boolean registerCollection(CollectionSchema.MessageFactory factory)
          Registers a collection.
<T> boolean
registerDelegate(Delegate<T> delegate)
          Registers a delegate.
<T extends java.lang.Enum<T>>
boolean
registerEnum(java.lang.Class<T> enumClass)
          Registers an enum.
 boolean registerMap(MapSchema.MessageFactory factory)
          Registers a map.
<T> boolean
registerPojo(java.lang.Class<T> typeClass, Schema<T> schema)
          Registers a pojo.
protected  java.lang.Class<?> resolveArrayComponentTypeFrom(Input input, boolean mapped)
           
protected  java.lang.Class<?> resolveClassFrom(Input input, boolean mapped, boolean array)
           
protected  CollectionSchema.MessageFactory resolveCollectionFrom(Input input)
           
protected
<T> Delegate<T>
resolveDelegateFrom(Input input)
           
protected  EnumIO<?> resolveEnumFrom(Input input)
           
protected  MapSchema.MessageFactory resolveMapFrom(Input input)
           
protected
<T> HasSchema<T>
resolvePojoFrom(Input input, int fieldNumber)
           
protected  void transferArrayId(Input input, Output output, int fieldNumber, boolean mapped)
           
protected  void transferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array)
           
protected  void transferCollectionId(Input input, Output output, int fieldNumber)
           
protected
<T> Delegate<T>
transferDelegateId(Input input, Output output, int fieldNumber)
           
protected  void transferEnumId(Input input, Output output, int fieldNumber)
           
protected  void transferMapId(Input input, Output output, int fieldNumber)
           
protected
<T> HasSchema<T>
transferPojoId(Input input, Output output, int fieldNumber)
           
protected
<T> Delegate<T>
tryWriteDelegateIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)
          If this method returns null, the clazz was not registered as a delegate.
protected  void writeArrayIdTo(Output output, java.lang.Class<?> componentType)
           
protected  void writeClassIdTo(Output output, java.lang.Class<?> componentType, boolean array)
           
protected  void writeCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
           
protected  void writeEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
           
protected  void writeMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
           
protected
<T> Schema<T>
writeMessageIdTo(Output output, int fieldNumber, Message<T> message)
           
protected
<T> Schema<T>
writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)
           
 
Methods inherited from class com.dyuproject.protostuff.runtime.IdStrategy
newSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultIdStrategy

public DefaultIdStrategy()

DefaultIdStrategy

public DefaultIdStrategy(IdStrategy primaryGroup,
                         int groupId)
Method Detail

registerPojo

public <T> boolean registerPojo(java.lang.Class<T> typeClass,
                                Schema<T> schema)
Registers a pojo. Returns true if registration is successful or if the same exact schema was previously registered. Used by RuntimeSchema.register(Class, Schema).


registerEnum

public <T extends java.lang.Enum<T>> boolean registerEnum(java.lang.Class<T> enumClass)
Registers an enum. Returns true if registration is successful.


registerDelegate

public <T> boolean registerDelegate(Delegate<T> delegate)
Registers a delegate. Returns true if registration is successful.


registerCollection

public boolean registerCollection(CollectionSchema.MessageFactory factory)
Registers a collection. Returns true if registration is successful.


registerMap

public boolean registerMap(MapSchema.MessageFactory factory)
Registers a map. Returns true if registration is successful.


map

public <T> boolean map(java.lang.Class<? super T> baseClass,
                       java.lang.Class<T> typeClass)
Used by RuntimeSchema.map(Class, Class).


isDelegateRegistered

public boolean isDelegateRegistered(java.lang.Class<?> typeClass)
Description copied from class: IdStrategy
Returns true if there is a Delegate explicitly registered for the typeClass.

Specified by:
isDelegateRegistered in class IdStrategy

getDelegate

public <T> Delegate<T> getDelegate(java.lang.Class<? super T> typeClass)
Description copied from class: IdStrategy
Returns the delegate.

Specified by:
getDelegate in class IdStrategy

isRegistered

public boolean isRegistered(java.lang.Class<?> typeClass)
Description copied from class: IdStrategy
Returns true if the typeClass is explicitly registered.

Specified by:
isRegistered in class IdStrategy

getSchemaWrapper

public <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass,
                                         boolean create)
Description copied from class: IdStrategy
Returns the schema wrapper. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).

Specified by:
getSchemaWrapper in class IdStrategy

getEnumIO

protected EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.Class<?> enumClass)
Description copied from class: IdStrategy
Returns the EnumIO. The callers (internal field factories) are responsible that the class provided is an enum class.

Specified by:
getEnumIO in class IdStrategy

getCollectionFactory

protected CollectionSchema.MessageFactory getCollectionFactory(java.lang.Class<?> clazz)
Description copied from class: IdStrategy
Returns the CollectionSchema.MessageFactory. The callers (internal field factories) are responsible that the class provided implements Collection.

Specified by:
getCollectionFactory in class IdStrategy

getMapFactory

protected MapSchema.MessageFactory getMapFactory(java.lang.Class<?> clazz)
Description copied from class: IdStrategy
Returns the MapSchema.MessageFactory. The callers (internal field factories}) are responsible that the class provided implements .

Specified by:
getMapFactory in class IdStrategy

writeCollectionIdTo

protected void writeCollectionIdTo(Output output,
                                   int fieldNumber,
                                   java.lang.Class<?> clazz)
                            throws java.io.IOException
Specified by:
writeCollectionIdTo in class IdStrategy
Throws:
java.io.IOException

transferCollectionId

protected void transferCollectionId(Input input,
                                    Output output,
                                    int fieldNumber)
                             throws java.io.IOException
Specified by:
transferCollectionId in class IdStrategy
Throws:
java.io.IOException

resolveCollectionFrom

protected CollectionSchema.MessageFactory resolveCollectionFrom(Input input)
                                                         throws java.io.IOException
Specified by:
resolveCollectionFrom in class IdStrategy
Throws:
java.io.IOException

writeMapIdTo

protected void writeMapIdTo(Output output,
                            int fieldNumber,
                            java.lang.Class<?> clazz)
                     throws java.io.IOException
Specified by:
writeMapIdTo in class IdStrategy
Throws:
java.io.IOException

transferMapId

protected void transferMapId(Input input,
                             Output output,
                             int fieldNumber)
                      throws java.io.IOException
Specified by:
transferMapId in class IdStrategy
Throws:
java.io.IOException

resolveMapFrom

protected MapSchema.MessageFactory resolveMapFrom(Input input)
                                           throws java.io.IOException
Specified by:
resolveMapFrom in class IdStrategy
Throws:
java.io.IOException

writeEnumIdTo

protected void writeEnumIdTo(Output output,
                             int fieldNumber,
                             java.lang.Class<?> clazz)
                      throws java.io.IOException
Specified by:
writeEnumIdTo in class IdStrategy
Throws:
java.io.IOException

transferEnumId

protected void transferEnumId(Input input,
                              Output output,
                              int fieldNumber)
                       throws java.io.IOException
Specified by:
transferEnumId in class IdStrategy
Throws:
java.io.IOException

resolveEnumFrom

protected EnumIO<?> resolveEnumFrom(Input input)
                             throws java.io.IOException
Specified by:
resolveEnumFrom in class IdStrategy
Throws:
java.io.IOException

tryWriteDelegateIdTo

protected <T> Delegate<T> tryWriteDelegateIdTo(Output output,
                                               int fieldNumber,
                                               java.lang.Class<T> clazz)
                                    throws java.io.IOException
Description copied from class: IdStrategy
If this method returns null, the clazz was not registered as a delegate.

Specified by:
tryWriteDelegateIdTo in class IdStrategy
Throws:
java.io.IOException

transferDelegateId

protected <T> Delegate<T> transferDelegateId(Input input,
                                             Output output,
                                             int fieldNumber)
                                  throws java.io.IOException
Specified by:
transferDelegateId in class IdStrategy
Throws:
java.io.IOException

resolveDelegateFrom

protected <T> Delegate<T> resolveDelegateFrom(Input input)
                                   throws java.io.IOException
Specified by:
resolveDelegateFrom in class IdStrategy
Throws:
java.io.IOException

writePojoIdTo

protected <T> Schema<T> writePojoIdTo(Output output,
                                      int fieldNumber,
                                      java.lang.Class<T> clazz)
                           throws java.io.IOException
Specified by:
writePojoIdTo in class IdStrategy
Throws:
java.io.IOException

transferPojoId

protected <T> HasSchema<T> transferPojoId(Input input,
                                          Output output,
                                          int fieldNumber)
                               throws java.io.IOException
Specified by:
transferPojoId in class IdStrategy
Throws:
java.io.IOException

resolvePojoFrom

protected <T> HasSchema<T> resolvePojoFrom(Input input,
                                           int fieldNumber)
                                throws java.io.IOException
Specified by:
resolvePojoFrom in class IdStrategy
Throws:
java.io.IOException

writeMessageIdTo

protected <T> Schema<T> writeMessageIdTo(Output output,
                                         int fieldNumber,
                                         Message<T> message)
                              throws java.io.IOException
Specified by:
writeMessageIdTo in class IdStrategy
Throws:
java.io.IOException

writeArrayIdTo

protected void writeArrayIdTo(Output output,
                              java.lang.Class<?> componentType)
                       throws java.io.IOException
Specified by:
writeArrayIdTo in class IdStrategy
Throws:
java.io.IOException

transferArrayId

protected void transferArrayId(Input input,
                               Output output,
                               int fieldNumber,
                               boolean mapped)
                        throws java.io.IOException
Specified by:
transferArrayId in class IdStrategy
Throws:
java.io.IOException

resolveArrayComponentTypeFrom

protected java.lang.Class<?> resolveArrayComponentTypeFrom(Input input,
                                                           boolean mapped)
                                                    throws java.io.IOException
Specified by:
resolveArrayComponentTypeFrom in class IdStrategy
Throws:
java.io.IOException

writeClassIdTo

protected void writeClassIdTo(Output output,
                              java.lang.Class<?> componentType,
                              boolean array)
                       throws java.io.IOException
Specified by:
writeClassIdTo in class IdStrategy
Throws:
java.io.IOException

transferClassId

protected void transferClassId(Input input,
                               Output output,
                               int fieldNumber,
                               boolean mapped,
                               boolean array)
                        throws java.io.IOException
Specified by:
transferClassId in class IdStrategy
Throws:
java.io.IOException

resolveClassFrom

protected java.lang.Class<?> resolveClassFrom(Input input,
                                              boolean mapped,
                                              boolean array)
                                       throws java.io.IOException
Specified by:
resolveClassFrom in class IdStrategy
Throws:
java.io.IOException


Copyright © 2009-2014. All Rights Reserved.