Class BooleanAdapter
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter<Boolean,IBooleanItem>
-
- gov.nist.secauto.metaschema.core.datatype.adapter.BooleanAdapter
-
- All Implemented Interfaces:
IDataTypeAdapter<Boolean>
public class BooleanAdapter extends AbstractDataTypeAdapter<Boolean,IBooleanItem>
-
-
Field Summary
-
Fields inherited from class gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter
DEFAULT_JSON_FIELD_NAME
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected IBooleanItem
castInternal(IAnyAtomicItem item)
Attempt to cast the provided item to this adapter's item type.protected IBooleanItem
castToBoolean(INumericItem item)
Cast the provided numeric value to a boolean.protected IBooleanItem
castToBoolean(IStringItem item)
If the string is a numeric value, treat it as so.Boolean
copy(Object obj)
Create a copy of the provided value.Class<IBooleanItem>
getItemClass()
Get the java type of the associated item.com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes
getJsonRawType()
The JSON primative type of the data type.List<String>
getNames()
Get the metaschema type names associated with this adapter.IBooleanItem
newItem(Object value)
Construct a new item of this type using the provided value.Boolean
parse(com.fasterxml.jackson.core.JsonParser parser)
This default implementation will parse the value as a string and delegate to the string-based parsing method.Boolean
parse(String value)
Parses a provided string.void
writeJsonValue(Object value, com.fasterxml.jackson.core.JsonGenerator generator)
Writes the provided Java class instance as a JSON/YAML field value.-
Methods inherited from class gov.nist.secauto.metaschema.core.datatype.AbstractDataTypeAdapter
asString, canHandleQName, cast, getDefaultJsonValueKey, getJavaClass, isParsingStartElement, isUnrappedValueAllowedInXml, isXmlMixed, parse, toValue, writeXmlValue, writeXmlValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter
getPreferredName, isAtomic, parseAndSupply, parseAndSupply, parseAndSupply
-
-
-
-
Method Detail
-
getNames
public List<String> getNames()
Description copied from interface:IDataTypeAdapter
Get the metaschema type names associated with this adapter. This name must be unique with respect to all other metaschema types.At least one name must be provided, with the first name being the most preferred name.
- Returns:
- the name
-
getJsonRawType
public com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes getJsonRawType()
Description copied from interface:IDataTypeAdapter
The JSON primative type of the data type.- Returns:
- the JSON data type
-
parse
public Boolean parse(String value)
Description copied from interface:IDataTypeAdapter
Parses a provided string. Used to parse XML attributes, simple XML character data, and JSON/YAML property values.- Parameters:
value
- the string value to parse- Returns:
- the parsed data as the adapter's type
-
parse
public Boolean parse(com.fasterxml.jackson.core.JsonParser parser) throws IOException
Description copied from class:AbstractDataTypeAdapter
This default implementation will parse the value as a string and delegate to the string-based parsing method.- Specified by:
parse
in interfaceIDataTypeAdapter<Boolean>
- Overrides:
parse
in classAbstractDataTypeAdapter<Boolean,IBooleanItem>
- Parameters:
parser
- the JSON parser used to read the parsed value- Returns:
- the parsed value
- Throws:
IOException
- if a parsing error occurs
-
writeJsonValue
public void writeJsonValue(Object value, com.fasterxml.jackson.core.JsonGenerator generator) throws IOException
Description copied from interface:IDataTypeAdapter
Writes the provided Java class instance as a JSON/YAML field value.- Specified by:
writeJsonValue
in interfaceIDataTypeAdapter<Boolean>
- Overrides:
writeJsonValue
in classAbstractDataTypeAdapter<Boolean,IBooleanItem>
- Parameters:
value
- theField
instance value to writegenerator
- the JSON/YAML writer used to output the JSON/YAML data- Throws:
IOException
- if an unexpected error occurred while writing the JSON/YAML output
-
copy
public Boolean copy(Object obj)
Description copied from interface:IDataTypeAdapter
Create a copy of the provided value.- Parameters:
obj
- the value to copy- Returns:
- the copy
-
getItemClass
public Class<IBooleanItem> getItemClass()
Description copied from interface:IDataTypeAdapter
Get the java type of the associated item.- Specified by:
getItemClass
in interfaceIDataTypeAdapter<Boolean>
- Specified by:
getItemClass
in classAbstractDataTypeAdapter<Boolean,IBooleanItem>
- Returns:
- the java associated item type
-
newItem
public IBooleanItem newItem(Object value)
Description copied from interface:IDataTypeAdapter
Construct a new item of this type using the provided value.- Specified by:
newItem
in interfaceIDataTypeAdapter<Boolean>
- Specified by:
newItem
in classAbstractDataTypeAdapter<Boolean,IBooleanItem>
- Parameters:
value
- the item's value- Returns:
- a new item
-
castInternal
protected IBooleanItem castInternal(@NonNull IAnyAtomicItem item)
Description copied from class:AbstractDataTypeAdapter
Attempt to cast the provided item to this adapter's item type.The default implementation of this will attempt to parse the provided item as a string using the
IDataTypeAdapter.parse(String)
method. If this behavior is undesirable, then a subclass should override this method.- Overrides:
castInternal
in classAbstractDataTypeAdapter<Boolean,IBooleanItem>
- Parameters:
item
- the item to cast- Returns:
- the item casted to this adapter's item type
-
castToBoolean
@NonNull protected IBooleanItem castToBoolean(@NonNull INumericItem item)
Cast the provided numeric value to a boolean. Any non-zero value will betrue
, orfalse
otherwise.- Parameters:
item
- the item to cast- Returns:
true
if the item value is non-zero, orfalse
otherwise
-
castToBoolean
@NonNull protected IBooleanItem castToBoolean(@NonNull IStringItem item)
If the string is a numeric value, treat it as so. Otherwise parse the value as a boolean string.- Parameters:
item
- the item to cast- Returns:
- the effective boolean value of the string
- Throws:
InvalidValueForCastFunctionException
- if the provided item cannot be cast to a boolean value by any means
-
-