Class TypeBasedMultiplexer


  • @Deprecated
    public class TypeBasedMultiplexer
    extends java.lang.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​(java.lang.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​(java.lang.String keyOfObj,
                                    java.lang.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​(java.lang.String keyOfObj,
                                    java.lang.Object obj,
                                    java.net.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.
      • ifIs

        public <E> TypeBasedMultiplexer.OnTypeConsumer<E> ifIs​(java.lang.Class<E> predicateClass)
        Deprecated.
        Creates a setter which will be invoked by orElse(Consumer) or requireAny() if obj is an instance of predicateClass.
        Type Parameters:
        E - the type represented by predicateClass.
        Parameters:
        predicateClass - the predicate class (the callback set by a subsequent TypeBasedMultiplexer.OnTypeConsumer.then(Consumer) will be executed if obj is an instance of predicateClass).
        Returns:
        an OnTypeConsumer implementation to be used to set the action performed if obj is an instance of predicateClass.
        Throws:
        java.lang.IllegalArgumentException - if predicateClass is JSONObject. Use ifObject() for matching obj's class against JSONObject.
      • 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​(java.util.function.Consumer<java.lang.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.