Class TypeBasedMultiplexer
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Created and used byTypeBasedMultiplexerto set actions (consumers) for matching classes. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Constructor withnullkeyOfObjandnullid.TypeBasedMultiplexer(String keyOfObj, Object obj) Deprecated.Contstructor withnull id.TypeBasedMultiplexer(String keyOfObj, Object obj, URI id) Deprecated.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResolutionScopeChangeListener(ResolutionScopeChangeListener resolutionScopeChangeListener) Deprecated.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.voidDeprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or invokesorElseConsumerwith theobj.voidDeprecated.Checks if theobjis an instance of any previously set classes (byifIs(Class)orifObject()), performs the mapped action of found or throws with aSchemaException.
-
Constructor Details
-
TypeBasedMultiplexer
Deprecated.Constructor withnullkeyOfObjandnullid.- Parameters:
obj- the object which' class is matched against the classes defined byifIs(Class)(orifObject()) calls.
-
TypeBasedMultiplexer
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
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 Details
-
addResolutionScopeChangeListener
public void addResolutionScopeChangeListener(ResolutionScopeChangeListener resolutionScopeChangeListener) Deprecated. -
ifIs
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
Deprecated.Creates aJSONObjectconsumer setter.- Returns:
- an
OnTypeConsumerimplementation to be used to set the action performed ifobjis a JSONObject instance.
-
orElse
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.
-