Package io.protostuff.runtime
Class ExplicitIdStrategy
- java.lang.Object
-
- io.protostuff.runtime.IdStrategy
-
- io.protostuff.runtime.NumericIdStrategy
-
- io.protostuff.runtime.ExplicitIdStrategy
-
public final class ExplicitIdStrategy extends NumericIdStrategy
Requires every messsage/pojo/enum/collection/map to be registered with unique ids.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ExplicitIdStrategy.BaseHS<T>
(package private) static class
ExplicitIdStrategy.Lazy<T>
(package private) static class
ExplicitIdStrategy.Registered<T>
(package private) static class
ExplicitIdStrategy.RegisteredCollectionFactory
(package private) static class
ExplicitIdStrategy.RegisteredEnumIO
(package private) static class
ExplicitIdStrategy.RegisteredMapFactory
static class
ExplicitIdStrategy.Registry
This Registry is only way to register your pojos/enums/collections/maps/delegates.-
Nested classes/interfaces inherited from class io.protostuff.runtime.NumericIdStrategy
NumericIdStrategy.RegisteredDelegate<T>
-
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.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory>
collectionMapping
(package private) java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory>
collections
(package private) java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>>
delegateMapping
(package private) java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>>
delegates
(package private) java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO>
enumMapping
(package private) java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO>
enums
(package private) java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory>
mapMapping
(package private) java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory>
maps
(package private) java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>>
pojoMapping
(package private) java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>>
pojos
-
Fields inherited from class io.protostuff.runtime.NumericIdStrategy
CID_BIGDECIMAL, CID_BIGINTEGER, CID_BOOL, CID_BYTE, CID_BYTE_ARRAY, CID_BYTES, CID_CHAR, CID_CLASS, CID_COLLECTION, CID_DATE, CID_DELEGATE, CID_DOUBLE, CID_ENUM, CID_ENUM_MAP, CID_ENUM_SET, CID_FLOAT, CID_INT32, CID_INT64, CID_MAP, CID_OBJECT, CID_POJO, CID_SHORT, CID_STRING
-
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 ExplicitIdStrategy(int flags, IdStrategy primaryGroup, int groupId, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory> collectionMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory> collections, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory> mapMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory> maps, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO> enumMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO> enums, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>> pojoMapping, java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>> pojos, java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>> delegateMapping, java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>> delegates)
ExplicitIdStrategy(java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory> collectionMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory> collections, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory> mapMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory> maps, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO> enumMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO> enums, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>> pojoMapping, java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>> pojos, java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>> delegateMapping, java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>> delegates)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Class<?>
collectionClass(int id)
private int
collectionId(java.lang.Class<?> clazz)
protected java.lang.Class<?>
delegateClass(int id)
protected java.lang.Class<?>
enumClass(int id)
protected CollectionSchema.MessageFactory
getCollectionFactory(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 int
getEnumId(java.lang.Class<?> clazz)
protected EnumIO<? extends java.lang.Enum<?>>
getEnumIO(java.lang.Class<?> enumClass)
Returns theEnumIO
.protected int
getId(java.lang.Class<?> clazz)
protected MapSchema.MessageFactory
getMapFactory(java.lang.Class<?> clazz)
Returns theMapSchema.MessageFactory
.protected NumericIdStrategy.RegisteredDelegate<?>
getRegisteredDelegate(java.lang.Class<?> clazz)
<T> HasSchema<T>
getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
Returns theschema wrapper
.boolean
isDelegateRegistered(java.lang.Class<?> typeClass)
Returns true if there is aDelegate
explicitly registered for thetypeClass
.boolean
isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClass
is explicitly registered.protected java.lang.Class<?>
mapClass(int id)
private int
mapId(java.lang.Class<?> clazz)
(package private) static <K,V>
java.util.IdentityHashMap<K,V>newMap(int size)
protected java.lang.Class<?>
pojoClass(int id)
protected CollectionSchema.MessageFactory
resolveCollectionFrom(Input input)
protected <T> HasDelegate<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
transferCollectionId(Input input, Output output, int fieldNumber)
protected <T> HasDelegate<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> 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 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> HasSchema<T>
writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)
-
Methods inherited from class io.protostuff.runtime.NumericIdStrategy
grow, newList, resolveArrayComponentTypeFrom, resolveClassFrom, transferArrayId, transferClassId, writeArrayIdTo, writeClassIdTo
-
Methods inherited from class io.protostuff.runtime.IdStrategy
createMessageInstance, newSchema
-
-
-
-
Field Detail
-
collectionMapping
final java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory> collectionMapping
-
collections
final java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory> collections
-
mapMapping
final java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory> mapMapping
-
maps
final java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory> maps
-
enumMapping
final java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO> enumMapping
-
enums
final java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO> enums
-
pojoMapping
final java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>> pojoMapping
-
pojos
final java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>> pojos
-
delegateMapping
final java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>> delegateMapping
-
delegates
final java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>> delegates
-
-
Constructor Detail
-
ExplicitIdStrategy
public ExplicitIdStrategy(java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory> collectionMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory> collections, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory> mapMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory> maps, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO> enumMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO> enums, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>> pojoMapping, java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>> pojos, java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>> delegateMapping, java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>> delegates)
-
ExplicitIdStrategy
public ExplicitIdStrategy(int flags, IdStrategy primaryGroup, int groupId, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredCollectionFactory> collectionMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredCollectionFactory> collections, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredMapFactory> mapMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredMapFactory> maps, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.RegisteredEnumIO> enumMapping, java.util.ArrayList<ExplicitIdStrategy.RegisteredEnumIO> enums, java.util.IdentityHashMap<java.lang.Class<?>,ExplicitIdStrategy.BaseHS<?>> pojoMapping, java.util.ArrayList<ExplicitIdStrategy.BaseHS<?>> pojos, java.util.IdentityHashMap<java.lang.Class<?>,NumericIdStrategy.RegisteredDelegate<?>> delegateMapping, java.util.ArrayList<NumericIdStrategy.RegisteredDelegate<?>> delegates)
-
-
Method Detail
-
isRegistered
public boolean isRegistered(java.lang.Class<?> typeClass)
Description copied from class:IdStrategy
Returns true if thetypeClass
is explicitly registered.- Specified by:
isRegistered
in classIdStrategy
-
getSchemaWrapper
public <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
Description copied from class:IdStrategy
Returns theschema wrapper
. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).- Specified by:
getSchemaWrapper
in classIdStrategy
-
getEnumIO
protected EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.Class<?> enumClass)
Description copied from class:IdStrategy
Returns theEnumIO
. The callers (internal field factories) are responsible that the class provided is an enum class.- Specified by:
getEnumIO
in classIdStrategy
-
getCollectionFactory
protected CollectionSchema.MessageFactory getCollectionFactory(java.lang.Class<?> clazz)
Description copied from class:IdStrategy
Returns theCollectionSchema.MessageFactory
. The callers (internal field factories) are responsible that the class provided implementsCollection
.- Specified by:
getCollectionFactory
in classIdStrategy
-
getMapFactory
protected MapSchema.MessageFactory getMapFactory(java.lang.Class<?> clazz)
Description copied from class:IdStrategy
Returns theMapSchema.MessageFactory
. The callers (internal field factories}) are responsible that the class provided implementsMap
.- Specified by:
getMapFactory
in classIdStrategy
-
writeCollectionIdTo
protected void writeCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeCollectionIdTo
in classIdStrategy
- Throws:
java.io.IOException
-
transferCollectionId
protected void transferCollectionId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferCollectionId
in classIdStrategy
- Throws:
java.io.IOException
-
resolveCollectionFrom
protected CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws java.io.IOException
- Specified by:
resolveCollectionFrom
in classIdStrategy
- Throws:
java.io.IOException
-
writeMapIdTo
protected void writeMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeMapIdTo
in classIdStrategy
- Throws:
java.io.IOException
-
transferMapId
protected void transferMapId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferMapId
in classIdStrategy
- Throws:
java.io.IOException
-
resolveMapFrom
protected MapSchema.MessageFactory resolveMapFrom(Input input) throws java.io.IOException
- Specified by:
resolveMapFrom
in classIdStrategy
- Throws:
java.io.IOException
-
writeEnumIdTo
protected void writeEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Specified by:
writeEnumIdTo
in classIdStrategy
- Throws:
java.io.IOException
-
transferEnumId
protected void transferEnumId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferEnumId
in classIdStrategy
- Throws:
java.io.IOException
-
resolveEnumFrom
protected EnumIO<?> resolveEnumFrom(Input input) throws java.io.IOException
- Specified by:
resolveEnumFrom
in classIdStrategy
- Throws:
java.io.IOException
-
isDelegateRegistered
public boolean isDelegateRegistered(java.lang.Class<?> typeClass)
Description copied from class:IdStrategy
Returns true if there is aDelegate
explicitly registered for thetypeClass
.- Specified by:
isDelegateRegistered
in classIdStrategy
-
getDelegate
public <T> Delegate<T> getDelegate(java.lang.Class<? super T> typeClass)
Description copied from class:IdStrategy
Returns thedelegate
.- Specified by:
getDelegate
in classIdStrategy
-
getDelegateWrapper
public <T> HasDelegate<T> getDelegateWrapper(java.lang.Class<? super T> typeClass)
Description copied from class:IdStrategy
Returns thedelegate
.- Specified by:
getDelegateWrapper
in classIdStrategy
-
tryWriteDelegateIdTo
protected <T> HasDelegate<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 classIdStrategy
- Throws:
java.io.IOException
-
transferDelegateId
protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferDelegateId
in classIdStrategy
- Throws:
java.io.IOException
-
resolveDelegateFrom
protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws java.io.IOException
- Specified by:
resolveDelegateFrom
in 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:
tryWritePojoIdTo
in 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:
writePojoIdTo
in classIdStrategy
- Throws:
java.io.IOException
-
transferPojoId
protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Specified by:
transferPojoId
in classIdStrategy
- Throws:
java.io.IOException
-
resolvePojoFrom
protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws java.io.IOException
- Specified by:
resolvePojoFrom
in classIdStrategy
- 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 classIdStrategy
- Throws:
java.io.IOException
-
collectionClass
protected java.lang.Class<?> collectionClass(int id)
- Specified by:
collectionClass
in classNumericIdStrategy
-
mapClass
protected java.lang.Class<?> mapClass(int id)
- Specified by:
mapClass
in classNumericIdStrategy
-
enumClass
protected java.lang.Class<?> enumClass(int id)
- Specified by:
enumClass
in classNumericIdStrategy
-
delegateClass
protected java.lang.Class<?> delegateClass(int id)
- Specified by:
delegateClass
in classNumericIdStrategy
-
pojoClass
protected java.lang.Class<?> pojoClass(int id)
- Specified by:
pojoClass
in classNumericIdStrategy
-
getRegisteredDelegate
protected NumericIdStrategy.RegisteredDelegate<?> getRegisteredDelegate(java.lang.Class<?> clazz)
- Specified by:
getRegisteredDelegate
in classNumericIdStrategy
-
getEnumId
protected int getEnumId(java.lang.Class<?> clazz)
- Specified by:
getEnumId
in classNumericIdStrategy
-
getId
protected int getId(java.lang.Class<?> clazz)
- Specified by:
getId
in classNumericIdStrategy
-
collectionId
private int collectionId(java.lang.Class<?> clazz)
-
mapId
private int mapId(java.lang.Class<?> clazz)
-
newMap
static <K,V> java.util.IdentityHashMap<K,V> newMap(int size)
-
-