Package io.protostuff.runtime
Class DefaultIdStrategy
- java.lang.Object
-
- io.protostuff.runtime.IdStrategy
-
- io.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDefaultIdStrategy.Lazy<T>(package private) static classDefaultIdStrategy.LazyRegister<T>(package private) static classDefaultIdStrategy.Mapped<T>(package private) static classDefaultIdStrategy.Registered<T>(package private) static classDefaultIdStrategy.RuntimeCollectionFactory(package private) static classDefaultIdStrategy.RuntimeMapFactory-
Nested classes/interfaces inherited from class io.protostuff.runtime.IdStrategy
IdStrategy.Factory, IdStrategy.UnknownTypeException, IdStrategy.Wrapper
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.ConcurrentHashMap<java.lang.String,CollectionSchema.MessageFactory>collectionMapping(package private) java.util.concurrent.ConcurrentHashMap<java.lang.String,HasDelegate<?>>delegateMapping(package private) java.util.concurrent.ConcurrentHashMap<java.lang.String,EnumIO<?>>enumMapping(package private) java.util.concurrent.ConcurrentHashMap<java.lang.String,MapSchema.MessageFactory>mapMapping(package private) java.util.concurrent.ConcurrentHashMap<java.lang.String,HasSchema<?>>pojoMapping-
Fields inherited from class io.protostuff.runtime.IdStrategy
ARRAY_BIGDECIMAL_SCHEMA, ARRAY_BIGINTEGER_SCHEMA, ARRAY_BOOL_BOXED_SCHEMA, ARRAY_BOOL_DERIVED_SCHEMA, ARRAY_BOOL_PRIMITIVE_SCHEMA, ARRAY_BYTEARRAY_SCHEMA, ARRAY_BYTESTRING_SCHEMA, ARRAY_CHAR_BOXED_SCHEMA, ARRAY_CHAR_DERIVED_SCHEMA, ARRAY_CHAR_PRIMITIVE_SCHEMA, ARRAY_DATE_SCHEMA, ARRAY_DOUBLE_BOXED_SCHEMA, ARRAY_DOUBLE_DERIVED_SCHEMA, ARRAY_DOUBLE_PRIMITIVE_SCHEMA, ARRAY_ELEMENT_SCHEMA, ARRAY_FLOAT_BOXED_SCHEMA, ARRAY_FLOAT_DERIVED_SCHEMA, ARRAY_FLOAT_PRIMITIVE_SCHEMA, ARRAY_INT32_BOXED_SCHEMA, ARRAY_INT32_DERIVED_SCHEMA, ARRAY_INT32_PRIMITIVE_SCHEMA, ARRAY_INT64_BOXED_SCHEMA, ARRAY_INT64_DERIVED_SCHEMA, ARRAY_INT64_PRIMITIVE_SCHEMA, ARRAY_PIPE_SCHEMA, ARRAY_SCHEMA, ARRAY_SHORT_BOXED_SCHEMA, ARRAY_SHORT_DERIVED_SCHEMA, ARRAY_SHORT_PRIMITIVE_SCHEMA, ARRAY_STRING_SCHEMA, AUTO_LOAD_POLYMORPHIC_CLASSES, CLASS_ELEMENT_SCHEMA, CLASS_PIPE_SCHEMA, CLASS_SCHEMA, COLLECTION_PIPE_SCHEMA, COLLECTION_SCHEMA, COLLECTION_SCHEMA_ON_REPEATED_FIELDS, DEFAULT_FLAGS, DYNAMIC_VALUE_PIPE_SCHEMA, DYNAMIC_VALUE_SCHEMA, ENTRY_PIPE_SCHEMA, ENTRY_SCHEMA, ENUMS_BY_NAME, flags, groupId, MAP_PIPE_SCHEMA, MAP_SCHEMA, MORPH_COLLECTION_INTERFACES, MORPH_MAP_INTERFACES, MORPH_NON_FINAL_POJOS, NUMBER_ELEMENT_SCHEMA, OBJECT_ELEMENT_SCHEMA, OBJECT_PIPE_SCHEMA, OBJECT_SCHEMA, POJO_SCHEMA_ON_COLLECTION_FIELDS, POJO_SCHEMA_ON_MAP_FIELDS, POLYMORPHIC_COLLECTION_PIPE_SCHEMA, POLYMORPHIC_COLLECTION_SCHEMA, POLYMORPHIC_ENUM_ELEMENT_SCHEMA, POLYMORPHIC_MAP_PIPE_SCHEMA, POLYMORPHIC_MAP_SCHEMA, POLYMORPHIC_POJO_ELEMENT_SCHEMA, POLYMORPHIC_THROWABLE_ELEMENT_SCHEMA, PRESERVE_NULL_ELEMENTS, preserveNull, primaryGroup
-
-
Constructor Summary
Constructors Constructor Description DefaultIdStrategy()DefaultIdStrategy(int flags)DefaultIdStrategy(int flags, IdStrategy primaryGroup, int groupId)DefaultIdStrategy(IdStrategy primaryGroup, int groupId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CollectionSchema.MessageFactorygetCollectionFactory(java.lang.Class<?> clazz)Returns theCollectionSchema.MessageFactory.<T> Delegate<T>getDelegate(java.lang.Class<? super T> typeClass)Returns thedelegate.<T> HasDelegate<T>getDelegateWrapper(java.lang.Class<? super T> typeClass)Returns thedelegate.protected EnumIO<? extends java.lang.Enum<?>>getEnumIO(java.lang.Class<?> enumClass)Returns theEnumIO.private EnumIO<? extends java.lang.Enum<?>>getEnumIO(java.lang.String className, boolean load)protected MapSchema.MessageFactorygetMapFactory(java.lang.Class<?> clazz)Returns theMapSchema.MessageFactory.<T> HasSchema<T>getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)Returns theschema wrapper.private <T> HasSchema<T>getSchemaWrapper(java.lang.String className, boolean load)booleanisDelegateRegistered(java.lang.Class<?> typeClass)Returns true if there is aDelegateexplicitly registered for thetypeClass.booleanisRegistered(java.lang.Class<?> typeClass)Returns true if thetypeClassis explicitly registered.<T> booleanmap(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)Used byRuntimeSchema.map(Class, Class).booleanregisterCollection(CollectionSchema.MessageFactory factory)Registers a collection.<T> booleanregisterDelegate(Delegate<T> delegate)Registers a delegate.<T> booleanregisterDelegate(java.lang.String className, Delegate<T> delegate)Registers a delegate by specifying the class name.<T extends java.lang.Enum<T>>
booleanregisterEnum(java.lang.Class<T> enumClass)Registers an enum.booleanregisterMap(MapSchema.MessageFactory factory)Registers a map.<T> booleanregisterPojo(java.lang.Class<T> typeClass)Registers a pojo.<T> booleanregisterPojo(java.lang.Class<T> typeClass, Schema<T> schema)Registers a pojo.protected java.lang.Class<?>resolveArrayComponentTypeFrom(Input input, boolean mapped)(package private) static java.lang.Class<?>resolveClass(java.lang.String className)protected java.lang.Class<?>resolveClassFrom(Input input, boolean mapped, boolean array)protected CollectionSchema.MessageFactoryresolveCollectionFrom(Input input)protected <T> HasDelegate<T>resolveDelegateFrom(Input input)protected EnumIO<?>resolveEnumFrom(Input input)protected MapSchema.MessageFactoryresolveMapFrom(Input input)protected <T> HasSchema<T>resolvePojoFrom(Input input, int fieldNumber)protected voidtransferArrayId(Input input, Output output, int fieldNumber, boolean mapped)protected voidtransferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array)protected voidtransferCollectionId(Input input, Output output, int fieldNumber)protected <T> HasDelegate<T>transferDelegateId(Input input, Output output, int fieldNumber)protected voidtransferEnumId(Input input, Output output, int fieldNumber)protected voidtransferMapId(Input input, Output output, int fieldNumber)protected <T> HasSchema<T>transferPojoId(Input input, Output output, int fieldNumber)protected <T> HasDelegate<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 <T> HasSchema<T>tryWritePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz, boolean registered)protected voidwriteArrayIdTo(Output output, java.lang.Class<?> componentType)protected voidwriteClassIdTo(Output output, java.lang.Class<?> componentType, boolean array)protected voidwriteCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)protected voidwriteEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)protected voidwriteMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)protected <T> Schema<T>writeMessageIdTo(Output output, int fieldNumber, Message<T> message)protected <T> HasSchema<T>writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)-
Methods inherited from class io.protostuff.runtime.IdStrategy
createMessageInstance, newSchema
-
-
-
-
Field Detail
-
pojoMapping
final java.util.concurrent.ConcurrentHashMap<java.lang.String,HasSchema<?>> pojoMapping
-
enumMapping
final java.util.concurrent.ConcurrentHashMap<java.lang.String,EnumIO<?>> enumMapping
-
collectionMapping
final java.util.concurrent.ConcurrentHashMap<java.lang.String,CollectionSchema.MessageFactory> collectionMapping
-
mapMapping
final java.util.concurrent.ConcurrentHashMap<java.lang.String,MapSchema.MessageFactory> mapMapping
-
delegateMapping
final java.util.concurrent.ConcurrentHashMap<java.lang.String,HasDelegate<?>> delegateMapping
-
-
Constructor Detail
-
DefaultIdStrategy
public DefaultIdStrategy()
-
DefaultIdStrategy
public DefaultIdStrategy(IdStrategy primaryGroup, int groupId)
-
DefaultIdStrategy
public DefaultIdStrategy(int flags)
-
DefaultIdStrategy
public DefaultIdStrategy(int flags, 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 byRuntimeSchema.register(Class, Schema).
-
registerPojo
public <T> boolean registerPojo(java.lang.Class<T> typeClass)
Registers a pojo. Returns true if registration is successful or if the same exact schema was previously registered.
-
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.
-
registerDelegate
public <T> boolean registerDelegate(java.lang.String className, Delegate<T> delegate)Registers a delegate by specifying the class name. 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 byRuntimeSchema.map(Class, Class).
-
isDelegateRegistered
public boolean isDelegateRegistered(java.lang.Class<?> typeClass)
Description copied from class:IdStrategyReturns true if there is aDelegateexplicitly registered for thetypeClass.- Specified by:
isDelegateRegisteredin classIdStrategy
-
getDelegateWrapper
public <T> HasDelegate<T> getDelegateWrapper(java.lang.Class<? super T> typeClass)
Description copied from class:IdStrategyReturns thedelegate.- Specified by:
getDelegateWrapperin classIdStrategy
-
getDelegate
public <T> Delegate<T> getDelegate(java.lang.Class<? super T> typeClass)
Description copied from class:IdStrategyReturns thedelegate.- Specified by:
getDelegatein classIdStrategy
-
isRegistered
public boolean isRegistered(java.lang.Class<?> typeClass)
Description copied from class:IdStrategyReturns true if thetypeClassis explicitly registered.- Specified by:
isRegisteredin classIdStrategy
-
getSchemaWrapper
private <T> HasSchema<T> getSchemaWrapper(java.lang.String className, boolean load)
-
getSchemaWrapper
public <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
Description copied from class:IdStrategyReturns theschema wrapper. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).- Specified by:
getSchemaWrapperin classIdStrategy
-
getEnumIO
private EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.String className, boolean load)
-
getEnumIO
protected EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.Class<?> enumClass)
Description copied from class:IdStrategyReturns theEnumIO. The callers (internal field factories) are responsible that the class provided is an enum class.- Specified by:
getEnumIOin classIdStrategy
-
getCollectionFactory
protected CollectionSchema.MessageFactory getCollectionFactory(java.lang.Class<?> clazz)
Description copied from class:IdStrategyReturns theCollectionSchema.MessageFactory. The callers (internal field factories) are responsible that the class provided implementsCollection.- Specified by:
getCollectionFactoryin classIdStrategy
-
getMapFactory
protected MapSchema.MessageFactory getMapFactory(java.lang.Class<?> clazz)
Description copied from class:IdStrategyReturns theMapSchema.MessageFactory. The callers (internal field factories}) are responsible that the class provided implementsMap.- Specified by:
getMapFactoryin classIdStrategy
-
writeCollectionIdTo
protected void writeCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeCollectionIdToin classIdStrategy- Throws:
java.io.IOException
-
transferCollectionId
protected void transferCollectionId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferCollectionIdin classIdStrategy- Throws:
java.io.IOException
-
resolveCollectionFrom
protected CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws java.io.IOException
- Specified by:
resolveCollectionFromin classIdStrategy- Throws:
java.io.IOException
-
writeMapIdTo
protected void writeMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeMapIdToin classIdStrategy- Throws:
java.io.IOException
-
transferMapId
protected void transferMapId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferMapIdin classIdStrategy- Throws:
java.io.IOException
-
resolveMapFrom
protected MapSchema.MessageFactory resolveMapFrom(Input input) throws java.io.IOException
- Specified by:
resolveMapFromin classIdStrategy- Throws:
java.io.IOException
-
writeEnumIdTo
protected void writeEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeEnumIdToin classIdStrategy- Throws:
java.io.IOException
-
transferEnumId
protected void transferEnumId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferEnumIdin classIdStrategy- Throws:
java.io.IOException
-
resolveEnumFrom
protected EnumIO<?> resolveEnumFrom(Input input) throws java.io.IOException
- Specified by:
resolveEnumFromin classIdStrategy- Throws:
java.io.IOException
-
tryWriteDelegateIdTo
protected <T> HasDelegate<T> tryWriteDelegateIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz) throws java.io.IOException
Description copied from class:IdStrategyIf this method returns null, the clazz was not registered as a delegate.- Specified by:
tryWriteDelegateIdToin classIdStrategy- Throws:
java.io.IOException
-
transferDelegateId
protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferDelegateIdin classIdStrategy- Throws:
java.io.IOException
-
resolveDelegateFrom
protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws java.io.IOException
- Specified by:
resolveDelegateFromin classIdStrategy- Throws:
java.io.IOException
-
tryWritePojoIdTo
protected <T> HasSchema<T> tryWritePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz, boolean registered) throws java.io.IOException
- Specified by:
tryWritePojoIdToin classIdStrategy- Throws:
java.io.IOException
-
writePojoIdTo
protected <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz) throws java.io.IOException
- Specified by:
writePojoIdToin classIdStrategy- Throws:
java.io.IOException
-
transferPojoId
protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferPojoIdin classIdStrategy- Throws:
java.io.IOException
-
resolvePojoFrom
protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws java.io.IOException
- Specified by:
resolvePojoFromin classIdStrategy- Throws:
java.io.IOException
-
writeMessageIdTo
protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws java.io.IOException
- Specified by:
writeMessageIdToin classIdStrategy- Throws:
java.io.IOException
-
writeArrayIdTo
protected void writeArrayIdTo(Output output, java.lang.Class<?> componentType) throws java.io.IOException
- Specified by:
writeArrayIdToin classIdStrategy- Throws:
java.io.IOException
-
transferArrayId
protected void transferArrayId(Input input, Output output, int fieldNumber, boolean mapped) throws java.io.IOException
- Specified by:
transferArrayIdin classIdStrategy- Throws:
java.io.IOException
-
resolveArrayComponentTypeFrom
protected java.lang.Class<?> resolveArrayComponentTypeFrom(Input input, boolean mapped) throws java.io.IOException
- Specified by:
resolveArrayComponentTypeFromin classIdStrategy- Throws:
java.io.IOException
-
resolveClass
static java.lang.Class<?> resolveClass(java.lang.String className)
-
writeClassIdTo
protected void writeClassIdTo(Output output, java.lang.Class<?> componentType, boolean array) throws java.io.IOException
- Specified by:
writeClassIdToin classIdStrategy- Throws:
java.io.IOException
-
transferClassId
protected void transferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array) throws java.io.IOException
- Specified by:
transferClassIdin classIdStrategy- Throws:
java.io.IOException
-
resolveClassFrom
protected java.lang.Class<?> resolveClassFrom(Input input, boolean mapped, boolean array) throws java.io.IOException
- Specified by:
resolveClassFromin classIdStrategy- Throws:
java.io.IOException
-
-