Class 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 Detail

      • ModelRegistry

        public ModelRegistry()
    • 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: IModelRegistry
        Return a new entity instance parsed from the given JSON object.
        Specified by:
        newInstance in interface IModelRegistry
        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: IModelRegistry
        Return a new entity instance of the given type, parsed from the given JSON object.
        Specified by:
        newInstance in interface IModelRegistry
        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: IModelRegistry
        Return 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:
        parseOne in interface IModelRegistry
        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: IModelRegistry
        Return 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:
        newInstance in interface IModelRegistry
        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: IModelRegistry
        Return a new entity instance parsed from the given input.
        Specified by:
        parseOne in interface IModelRegistry
        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: IModelRegistry
        Return a new entity instance of the given type, parsed from the given input.
        Specified by:
        parseOne in interface IModelRegistry
        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: IModelRegistry
        Parse a stream of entitied from the giben input and pass them to the given consumer.
        Specified by:
        parseStream in interface IModelRegistry
        Parameters:
        in - A input stream containing serialised entities.
        consumer - A sink for the parsed entities.