Class TypeBasedMultiplexer
- java.lang.Object
-
- org.everit.json.schema.loader.internal.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 avoidingif..instanceof..casting
constructs. Together with theTypeBasedMultiplexer.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TypeBasedMultiplexer.OnTypeConsumer<E>
Deprecated.Created and used byTypeBasedMultiplexer
to set actions (consumers) for matching classes.
-
Constructor Summary
Constructors Constructor Description TypeBasedMultiplexer(java.lang.Object obj)
Deprecated.Constructor withnull
keyOfObj
andnull
id
.TypeBasedMultiplexer(java.lang.String keyOfObj, java.lang.Object obj)
Deprecated.Contstructor withnull id
.TypeBasedMultiplexer(java.lang.String keyOfObj, java.lang.Object obj, java.net.URI id)
Deprecated.Constructor.
-
Method Summary
Modifier and Type Method Description void
addResolutionScopeChangeListener(ResolutionScopeChangeListener resolutionScopeChangeListener)
Deprecated.<E> TypeBasedMultiplexer.OnTypeConsumer<E>
ifIs(java.lang.Class<E> predicateClass)
Deprecated.Creates a setter which will be invoked byorElse(Consumer)
orrequireAny()
ifobj
is an instance ofpredicateClass
.TypeBasedMultiplexer.OnTypeConsumer<org.json.JSONObject>
ifObject()
Deprecated.Creates aJSONObject
consumer setter.void
orElse(java.util.function.Consumer<java.lang.Object> orElseConsumer)
Deprecated.Checks if theobj
is an instance of any previously set classes (byifIs(Class)
orifObject()
), performs the mapped action of found or invokesorElseConsumer
with theobj
.void
requireAny()
Deprecated.Checks if theobj
is 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(java.lang.Object obj)
Deprecated.Constructor withnull
keyOfObj
andnull
id
.- Parameters:
obj
- the object which' class is matched against the classes defined byifIs(Class)
(orifObject()
) calls.
-
TypeBasedMultiplexer
public TypeBasedMultiplexer(java.lang.String keyOfObj, java.lang.Object obj)
Deprecated.Contstructor withnull id
.- Parameters:
keyOfObj
- is an optional (nullable) string used byrequireAny()
to construct the message of theSchemaException
if no appropriate consumer action is found.obj
- the object which' class is matched against the classes defined byifIs(Class)
(orifObject()
) 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 byrequireAny()
to construct the message of theSchemaException
if 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(java.lang.Class<E> predicateClass)
Deprecated.Creates a setter which will be invoked byorElse(Consumer)
orrequireAny()
ifobj
is 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 ifobj
is an instance ofpredicateClass
).- Returns:
- an
OnTypeConsumer
implementation to be used to set the action performed ifobj
is an instance ofpredicateClass
. - Throws:
java.lang.IllegalArgumentException
- ifpredicateClass
isJSONObject
. UseifObject()
for matchingobj
's class againstJSONObject
.
-
ifObject
public TypeBasedMultiplexer.OnTypeConsumer<org.json.JSONObject> ifObject()
Deprecated.Creates aJSONObject
consumer setter.- Returns:
- an
OnTypeConsumer
implementation to be used to set the action performed ifobj
is a JSONObject instance.
-
orElse
public void orElse(java.util.function.Consumer<java.lang.Object> orElseConsumer)
Deprecated.Checks if theobj
is an instance of any previously set classes (byifIs(Class)
orifObject()
), performs the mapped action of found or invokesorElseConsumer
with theobj
.- Parameters:
orElseConsumer
- the callback to be called if no types matched.
-
requireAny
public void requireAny()
Deprecated.Checks if theobj
is an instance of any previously set classes (byifIs(Class)
orifObject()
), performs the mapped action of found or throws with aSchemaException
.
-
-