Class TypeBasedMultiplexer
- java.lang.Object
-
- org.everit.json.schema.loader.internal.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.SchemaLoaderduring schema loading for type-based action selections. In other words this utility class is used for avoidingif..instanceof..castingconstructs. Together with theTypeBasedMultiplexer.OnTypeConsumerimplementations 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 JSONObjectThis class it NOT thread-safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTypeBasedMultiplexer.OnTypeConsumer<E>Deprecated.Created and used byTypeBasedMultiplexerto set actions (consumers) for matching classes.
-
Constructor Summary
Constructors Constructor Description TypeBasedMultiplexer(Object obj)Deprecated.Constructor withnullkeyOfObjandnullid.TypeBasedMultiplexer(String keyOfObj, Object obj)Deprecated.Contstructor withnull id.TypeBasedMultiplexer(String keyOfObj, Object obj, URI id)Deprecated.Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddResolutionScopeChangeListener(ResolutionScopeChangeListener resolutionScopeChangeListener)Deprecated.<E> TypeBasedMultiplexer.OnTypeConsumer<E>ifIs(Class<E> predicateClass)Deprecated.Creates a setter which will be invoked byorElse(Consumer)orrequireAny()ifobjis an instance ofpredicateClass.TypeBasedMultiplexer.OnTypeConsumer<org.json.JSONObject>ifObject()Deprecated.Creates aJSONObjectconsumer setter.voidorElse(Consumer<Object> orElseConsumer)Deprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or invokesorElseConsumerwith theobj.voidrequireAny()Deprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or throws with aSchemaException.
-
-
-
Constructor Detail
-
TypeBasedMultiplexer
public TypeBasedMultiplexer(Object obj)
Deprecated.Constructor withnullkeyOfObjandnullid.- Parameters:
obj- the object which' class is matched against the classes defined byifIs(Class)(orifObject()) calls.
-
TypeBasedMultiplexer
public TypeBasedMultiplexer(String keyOfObj, Object obj)
Deprecated.Contstructor withnull id.- Parameters:
keyOfObj- is an optional (nullable) string used byrequireAny()to construct the message of theSchemaExceptionif no appropriate consumer action is found.obj- the object which' class is matched against the classes defined byifIs(Class)(orifObject()) calls.
-
TypeBasedMultiplexer
public TypeBasedMultiplexer(String keyOfObj, Object obj, URI id)
Deprecated.Constructor.- Parameters:
keyOfObj- is an optional (nullable) string used byrequireAny()to construct the message of theSchemaExceptionif no appropriate consumer action is found.obj- the object which' class is matched against the classes defined byifIs(Class)(orifObject()) 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(Class<E> predicateClass)
Deprecated.Creates a setter which will be invoked byorElse(Consumer)orrequireAny()ifobjis an instance ofpredicateClass.- Type Parameters:
E- the type represented bypredicateClass.- Parameters:
predicateClass- the predicate class (the callback set by a subsequentTypeBasedMultiplexer.OnTypeConsumer.then(Consumer)will be executed ifobjis an instance ofpredicateClass).- Returns:
- an
OnTypeConsumerimplementation to be used to set the action performed ifobjis an instance ofpredicateClass. - Throws:
IllegalArgumentException- ifpredicateClassisJSONObject. UseifObject()for matchingobj's class againstJSONObject.
-
ifObject
public TypeBasedMultiplexer.OnTypeConsumer<org.json.JSONObject> ifObject()
Deprecated.Creates aJSONObjectconsumer setter.- Returns:
- an
OnTypeConsumerimplementation to be used to set the action performed ifobjis a JSONObject instance.
-
orElse
public void orElse(Consumer<Object> orElseConsumer)
Deprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or invokesorElseConsumerwith theobj.- Parameters:
orElseConsumer- the callback to be called if no types matched.
-
requireAny
public void requireAny()
Deprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or throws with aSchemaException.
-
-