Class TypeBasedMultiplexer


  • @Deprecated
    public class TypeBasedMultiplexer
    extends Object
    Deprecated.
    This class is deprecated. Currently it isn't used by the library itself, although it wasn't removed, to maintain backward compatiblity.

    Used by org.everit.json.schema.loader.SchemaLoader.SchemaLoader during schema loading for type-based action selections. In other words this utility class is used for avoiding if..instanceof..casting constructs. Together with the TypeBasedMultiplexer.OnTypeConsumer implementations it forms a fluent API to deal with the parts of the JSON schema where multiple kind of values are valid for a given key.

    Example usage: Object additProps = schemaJson.get("additionalProperties"); typeMultiplexer(additionalProps) .ifIs(JSONArray.class).then(arr -> {...if additProps is a JSONArray then process it... }) .ifObject().then(obj -> {...if additProps is a JSONArray then process it... }) .requireAny(); // throw a SchemaException if additProps is neither a JSONArray nor a JSONObject

    This class it NOT thread-safe.

    • Constructor Detail

      • TypeBasedMultiplexer

        public TypeBasedMultiplexer​(Object obj)
        Deprecated.
        Constructor with null keyOfObj and null id.
        Parameters:
        obj - the object which' class is matched against the classes defined by ifIs(Class) (or ifObject()) calls.
      • TypeBasedMultiplexer

        public TypeBasedMultiplexer​(String keyOfObj,
                                    Object obj)
        Deprecated.
        Contstructor with null id.
        Parameters:
        keyOfObj - is an optional (nullable) string used by requireAny() to construct the message of the SchemaException if no appropriate consumer action is found.
        obj - the object which' class is matched against the classes defined by ifIs(Class) (or ifObject()) calls.
      • TypeBasedMultiplexer

        public TypeBasedMultiplexer​(String keyOfObj,
                                    Object obj,
                                    URI id)
        Deprecated.
        Constructor.
        Parameters:
        keyOfObj - is an optional (nullable) string used by requireAny() to construct the message of the SchemaException if no appropriate consumer action is found.
        obj - the object which' class is matched against the classes defined by ifIs(Class) (or ifObject()) calls.
        id - the scope id at the point where the multiplexer is initialized.
    • Method Detail

      • addResolutionScopeChangeListener

        public void addResolutionScopeChangeListener​(ResolutionScopeChangeListener resolutionScopeChangeListener)
        Deprecated.
      • ifObject

        public TypeBasedMultiplexer.OnTypeConsumer<org.json.JSONObject> ifObject()
        Deprecated.
        Creates a JSONObject consumer setter.
        Returns:
        an OnTypeConsumer implementation to be used to set the action performed if obj is a JSONObject instance.
      • orElse

        public void orElse​(Consumer<Object> orElseConsumer)
        Deprecated.
        Checks if the obj is an instance of any previously set classes (by ifIs(Class) or ifObject()), performs the mapped action of found or invokes orElseConsumer with the obj.
        Parameters:
        orElseConsumer - the callback to be called if no types matched.
      • requireAny

        public void requireAny()
        Deprecated.
        Checks if the obj is an instance of any previously set classes (by ifIs(Class) or ifObject()), performs the mapped action of found or throws with a SchemaException.