Package org.symphonyoss.s2.canon.runtime
Class ModelRegistry
- java.lang.Object
-
- org.symphonyoss.s2.canon.runtime.ModelRegistry
-
- All Implemented Interfaces:
IModelRegistry
public class ModelRegistry extends Object implements IModelRegistry
A ModelRegistry is a container for IModels which can deserialize objects from any of the contained models.- Author:
- Bruce Skingle
-
-
Constructor Summary
Constructors Constructor Description ModelRegistry()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IEntitynewInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject)Return a new entity instance parsed from the given JSON object.IEntitynewInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject, String expectedTypeId)Return a new entity instance of the given type, parsed from the given JSON object.<E extends IEntity>
EnewInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject, String defaultTypeId, Class<E> type)Return a new entity instance of the given type, parsed from the given input.static List<org.symphonyoss.s2.common.dom.json.ImmutableJsonObject>parseListOfJsonObjects(Reader reader)Parse a list of JSON objects from the given Reader.static List<org.symphonyoss.s2.common.dom.json.JsonValue<?,?>>parseListOfJsonValues(Reader reader)Parse a list of JSON values from the given Reader.IEntityparseOne(Reader reader)Return a new entity instance parsed from the given input.IEntityparseOne(Reader reader, String typeId)Return a new entity instance of the given type, parsed from the given input.<E extends IEntity>
EparseOne(Reader reader, String defaultTypeId, Class<E> type)Return a new entity instance of the given type, parsed from the given input.static org.symphonyoss.s2.common.dom.json.ImmutableJsonObjectparseOneJsonObject(Reader reader)Parse a single JSON object from the given Reader.static org.symphonyoss.s2.common.dom.json.JsonValue<?,?>parseOneJsonValue(Reader reader)Parse a single JSON value from the given Reader.voidparseStream(InputStream in, IEntityConsumer consumer)Parse a stream of entitied from the giben input and pass them to the given consumer.ModelRegistrywithFactories(IEntityFactory<?,?,?>... factories)Create a registry with the given models.
-
-
-
Method Detail
-
withFactories
public ModelRegistry withFactories(IEntityFactory<?,?,?>... factories)
Create a registry with the given models.- Parameters:
factories- Entity factories to be registered.- Returns:
- this (Fluent interface)
-
newInstance
public IEntity newInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject)
Description copied from interface:IModelRegistryReturn a new entity instance parsed from the given JSON object.- Specified by:
newInstancein interfaceIModelRegistry- Parameters:
jsonObject- A JSON object containing the serialized form of an entity.- Returns:
- The deserialized entity.
-
newInstance
public IEntity newInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject, @Nullable String expectedTypeId)
Description copied from interface:IModelRegistryReturn a new entity instance of the given type, parsed from the given JSON object.- Specified by:
newInstancein interfaceIModelRegistry- Parameters:
jsonObject- A JSON object containing the serialized form of an entity.expectedTypeId- The type ID of the expected type.- Returns:
- The deserialized entity.
-
parseOne
public <E extends IEntity> E parseOne(Reader reader, String defaultTypeId, Class<E> type)
Description copied from interface:IModelRegistryReturn a new entity instance of the given type, parsed from the given input. The returned entity will be an instance of the given type, but may be a sub-class. The defaultTypeId is only used in cases where there is no type information in the serialised JSON. This enables canon generated client stubs to be used with non-canon server implementations.- Specified by:
parseOnein interfaceIModelRegistry- Parameters:
reader- A Reader containing the serialized form of an entity.defaultTypeId- The type ID of the expected type.type- The expected type of the entity.- Returns:
- The deserialized entity.
-
newInstance
public <E extends IEntity> E newInstance(org.symphonyoss.s2.common.dom.json.ImmutableJsonObject jsonObject, String defaultTypeId, Class<E> type)
Description copied from interface:IModelRegistryReturn a new entity instance of the given type, parsed from the given input. The returned entity will be an instance of the given type, but may be a sub-class. The defaultTypeId is only used in cases where there is no type information in the serialised JSON. This enables canon generated client stubs to be used with non-canon server implementations.- Specified by:
newInstancein interfaceIModelRegistry- Parameters:
jsonObject- A JSON object containing the serialized form of an entity.defaultTypeId- The type ID of the expected type.type- The expected type of the entity.- Returns:
- The deserialized entity.
-
parseListOfJsonObjects
public static List<org.symphonyoss.s2.common.dom.json.ImmutableJsonObject> parseListOfJsonObjects(Reader reader)
Parse a list of JSON objects from the given Reader. This method does not do a partial read, it is expected that the contents of the Reader are a single list of objects.- Parameters:
reader- The source of a JSON object.- Returns:
- The parsed list of ImmutableJsonObjects.
-
parseOneJsonObject
public static org.symphonyoss.s2.common.dom.json.ImmutableJsonObject parseOneJsonObject(Reader reader)
Parse a single JSON object from the given Reader. This method does not do a partial read, it is expected that the contents of the Reader are a single object.- Parameters:
reader- The source of a JSON object.- Returns:
- The parsed object as an ImmutableJsonObject.
- Throws:
IllegalArgumentException- If the input cannot be parsed or does not contain a single object.
-
parseListOfJsonValues
public static List<org.symphonyoss.s2.common.dom.json.JsonValue<?,?>> parseListOfJsonValues(Reader reader)
Parse a list of JSON values from the given Reader. This method does not do a partial read, it is expected that the contents of the Reader are a single value.- Parameters:
reader- The source of a JSON value.- Returns:
- The parsed list of (Immutable) JsonValues.
- Throws:
IllegalArgumentException- If the input cannot be parsed or does not contain a list of objects.
-
parseOneJsonValue
public static org.symphonyoss.s2.common.dom.json.JsonValue<?,?> parseOneJsonValue(Reader reader)
Parse a single JSON value from the given Reader. This method does not do a partial read, it is expected that the contents of the Reader are a single value.- Parameters:
reader- The source of a JSON value.- Returns:
- The parsed value as an (Immutable) JsonValue.
- Throws:
IllegalArgumentException- If the input cannot be parsed or does not contain a single object.
-
parseOne
public IEntity parseOne(Reader reader)
Description copied from interface:IModelRegistryReturn a new entity instance parsed from the given input.- Specified by:
parseOnein interfaceIModelRegistry- Parameters:
reader- A Reader containing the serialized form of an entity.- Returns:
- The deserialized entity.
-
parseOne
public IEntity parseOne(Reader reader, @Nullable String typeId)
Description copied from interface:IModelRegistryReturn a new entity instance of the given type, parsed from the given input.- Specified by:
parseOnein interfaceIModelRegistry- Parameters:
reader- A Reader containing the serialized form of an entity.typeId- The type ID of the expected type.- Returns:
- The deserialized entity.
-
parseStream
public void parseStream(InputStream in, IEntityConsumer consumer)
Description copied from interface:IModelRegistryParse a stream of entitied from the giben input and pass them to the given consumer.- Specified by:
parseStreamin interfaceIModelRegistry- Parameters:
in- A input stream containing serialised entities.consumer- A sink for the parsed entities.
-
-