Interface IDataTypeAdapter<TYPE>
-
- All Known Implementing Classes:
AbstractCustomJavaDataTypeAdapter,AbstractDataTypeAdapter,AbstractIntegerAdapter,AbstractMarkupAdapter,AbstractStringAdapter,Base64Adapter,BooleanAdapter,DateAdapter,DateTimeAdapter,DateTimeWithTZAdapter,DateWithTZAdapter,DayTimeAdapter,DecimalAdapter,EmailAddressAdapter,HostnameAdapter,IntegerAdapter,IPv4AddressAdapter,IPv6AddressAdapter,MarkupLineAdapter,MarkupMultilineAdapter,NcNameAdapter,NonNegativeIntegerAdapter,PositiveIntegerAdapter,StringAdapter,TokenAdapter,UriAdapter,UriReferenceAdapter,UuidAdapter,YearMonthAdapter
public interface IDataTypeAdapter<TYPE>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description StringasString(Object value)Gets the value as a string suitable for writing as text.booleancanHandleQName(QName nextElementQName)Determines if adapter can parse the next element.IAnyAtomicItemcast(IAnyAtomicItem item)Cast the provided item to an item of this type, if possible.TYPEcopy(Object obj)Create a copy of the provided value.StringgetDefaultJsonValueKey()Gets the default value to use as the JSON/YAML field name for a Metaschema field value if no JSON value key flag or name is configured.Class<? extends IAnyAtomicItem>getItemClass()Get the java type of the associated item.Class<TYPE>getJavaClass()Get the Java class supported by this adapter.com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypesgetJsonRawType()The JSON primative type of the data type.List<String>getNames()Get the metaschema type names associated with this adapter.default StringgetPreferredName()Get the most preferred name for this data type.default booleanisAtomic()Determines if the data type is an atomic, scalar value.booleanisParsingStartElement()Indicates if the adapter will parse theXMLStreamConstants.START_ELEMENTbefore parsing the value data.booleanisUnrappedValueAllowedInXml()Determines if the data type's value is allowed to be unwrapped in XML when the value is a field value.booleanisXmlMixed()Determines if the datatype uses mixed text and element content in XML.IAnyAtomicItemnewItem(Object value)Construct a new item of this type using the provided value.TYPEparse(com.fasterxml.jackson.core.JsonParser parser)Parses a JSON property value.TYPEparse(String value)Parses a provided string.TYPEparse(org.codehaus.stax2.XMLEventReader2 eventReader)This method is expected to parse content starting at the next event.default Supplier<TYPE>parseAndSupply(com.fasterxml.jackson.core.JsonParser parser)Parses a provided string usingparse(JsonParser).default Supplier<TYPE>parseAndSupply(String value)Parses a provided string usingparse(String).default Supplier<TYPE>parseAndSupply(org.codehaus.stax2.XMLEventReader2 eventReader)Parses a provided string usingparse(XMLEventReader2).TYPEtoValue(Object value)Casts the provided value to the type associated with this adapter.voidwriteJsonValue(Object instance, com.fasterxml.jackson.core.JsonGenerator writer)Writes the provided Java class instance as a JSON/YAML field value.voidwriteXmlValue(Object instance, QName parentName, org.codehaus.stax2.XMLStreamWriter2 writer)Writes the provided Java class instance data as XML.voidwriteXmlValue(Object instance, StartElement parent, org.codehaus.stax2.evt.XMLEventFactory2 eventFactory, XMLEventWriter eventWriter)Writes the provided Java class instance data as XML.
-
-
-
Method Detail
-
getNames
@NonNull List<String> getNames()
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
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes getJsonRawType()
The JSON primative type of the data type.- Returns:
- the JSON data type
-
getPreferredName
@NonNull default String getPreferredName()
Get the most preferred name for this data type.- Returns:
- the name
-
getJavaClass
@NonNull Class<TYPE> getJavaClass()
Get the Java class supported by this adapter.- Returns:
- the Java class
-
toValue
@NonNull TYPE toValue(@NonNull Object value)
Casts the provided value to the type associated with this adapter.- Parameters:
value- a value of the provided type- Returns:
- the typed value
-
asString
@NonNull String asString(@NonNull Object value)
Gets the value as a string suitable for writing as text. This is intended for data types that have a simple string-based structure in XML and JSON, such as for XML attributes or JSON keys. An adapter for a complex data structures that consist of XML elements will throw anUnsupportedOperationExceptionwhen this is called.- Parameters:
value- the data to formatted as a string- Returns:
- a string
- Throws:
UnsupportedOperationException- if the data type cannot be represented as a string
-
copy
@NonNull TYPE copy(@NonNull Object obj)
Create a copy of the provided value.- Parameters:
obj- the value to copy- Returns:
- the copy
-
isAtomic
default boolean isAtomic()
Determines if the data type is an atomic, scalar value. Complex structures such as Markup are not considered atomic.- Returns:
trueif the data type is an atomic scalar value, orfalseotherwise
-
getItemClass
@NonNull Class<? extends IAnyAtomicItem> getItemClass()
Get the java type of the associated item.- Returns:
- the java associated item type
-
newItem
@NonNull IAnyAtomicItem newItem(@NonNull Object value)
Construct a new item of this type using the provided value.- Parameters:
value- the item's value- Returns:
- a new item
-
cast
@NonNull IAnyAtomicItem cast(IAnyAtomicItem item)
Cast the provided item to an item of this type, if possible.- Parameters:
item- the atomic item to cast- Returns:
- an atomic item of this type
- Throws:
InvalidValueForCastFunctionException- if the provided item type cannot be cast to this item type
-
isParsingStartElement
boolean isParsingStartElement()
Indicates if the adapter will parse theXMLStreamConstants.START_ELEMENTbefore parsing the value data.- Returns:
trueif the adapter requires the start element for parsing, orfalseotherwise
-
canHandleQName
boolean canHandleQName(@NonNull QName nextElementQName)
Determines if adapter can parse the next element. The next element'sQNameis provided for this purpose.This will be called when the parser encounter's an element it does not recognize. This gives the adapter a chance to request parsing of the data.
- Parameters:
nextElementQName- the next element's namespace-qualified name- Returns:
trueif the adapter will parse the element, orfalseotherwise
-
parse
@NonNull TYPE parse(@NonNull String value)
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
- Throws:
IllegalArgumentException- if the data is not valid to the data type
-
parse
@NonNull TYPE parse(@NonNull org.codehaus.stax2.XMLEventReader2 eventReader) throws IOException
This method is expected to parse content starting at the next event. Parsing will continue until the next event represents content that is not handled by this adapter. This means the event stream should be positioned after anyXMLStreamConstants.END_ELEMENTthat corresponds to anXMLStreamConstants.START_ELEMENTparsed by this adapter.If
isParsingStartElement()returnstrue, then the first event to parse will be theXMLStreamConstants.START_ELEMENTfor the element that contains the value data, then the value data. If this is the case, this method must also parse the correspondingXMLStreamConstants.END_ELEMENT. Otherwise, the first event to parse will be the value data.The value data is expected to be parsed completely, leaving the event stream on a peeked event corresponding to content that is not handled by this method.
- Parameters:
eventReader- the XML parser used to read the parsed value- Returns:
- the parsed value
- Throws:
IOException- if a parsing error occurs
-
parse
@NonNull TYPE parse(@NonNull com.fasterxml.jackson.core.JsonParser parser) throws IOException
Parses a JSON property value.- Parameters:
parser- the JSON parser used to read the parsed value- Returns:
- the parsed value
- Throws:
IOException- if a parsing error occurs
-
parseAndSupply
@NonNull default Supplier<TYPE> parseAndSupply(@NonNull String value) throws IOException
Parses a provided string usingparse(String).This method may pre-parse the data and then return copies, since the data can only be parsed once, but the supplier might be called multiple times.
- Parameters:
value- the string value to parse- Returns:
- a supplier that will provide new instances of the parsed data
- Throws:
IOException- if an error occurs while parsing- See Also:
parse(String)
-
parseAndSupply
@NonNull default Supplier<TYPE> parseAndSupply(@NonNull org.codehaus.stax2.XMLEventReader2 eventReader) throws IOException
Parses a provided string usingparse(XMLEventReader2).This method may pre-parse the data and then return copies, since the data can only be parsed once, but the supplier might be called multiple times.
- Parameters:
eventReader- the XML parser used to read the parsed value- Returns:
- a supplier that will provide new instances of the parsed data
- Throws:
IOException- if an error occurs while parsing- See Also:
parse(String),parse(XMLEventReader2)
-
parseAndSupply
@NonNull default Supplier<TYPE> parseAndSupply(@NonNull com.fasterxml.jackson.core.JsonParser parser) throws IOException
Parses a provided string usingparse(JsonParser).This method may pre-parse the data and then return copies, since the data can only be parsed once, but the supplier might be called multiple times.
- Parameters:
parser- the JSON parser used to read the parsed value- Returns:
- a supplier that will provide new instances of the parsed data
- Throws:
IOException- if an error occurs while parsing- See Also:
parse(String),parse(JsonParser)
-
writeXmlValue
void writeXmlValue(@NonNull Object instance, @NonNull StartElement parent, @NonNull org.codehaus.stax2.evt.XMLEventFactory2 eventFactory, @NonNull XMLEventWriter eventWriter) throws IOException, XMLStreamException
Writes the provided Java class instance data as XML. The parent element information is provided as aStartElementevent, which allows namespace information to be obtained from the parent element using theStartElement.getName()andStartElement.getNamespaceContext()methods, which can be used when writing the provided instance value.- Parameters:
instance- theFieldinstance value to writeparent- theStartElementXML event that is the parent of the data to writeeventFactory- the XML event factory used to generate XML writing eventseventWriter- the XML writer used to output XML as events- Throws:
XMLStreamException- if an unexpected error occurred while processing the XML outputIOException- if an unexpected error occurred while writing to the output stream
-
writeXmlValue
void writeXmlValue(@NonNull Object instance, @NonNull QName parentName, @NonNull org.codehaus.stax2.XMLStreamWriter2 writer) throws XMLStreamException
Writes the provided Java class instance data as XML. The parent element information is provided as an XMLQName, which allows namespace information to be obtained from the parent element. Additional namespace information can be gathered using theXMLStreamWriter.getNamespaceContext()method, which can be used when writing the provided instance value.- Parameters:
instance- theFieldinstance value to writeparentName- the qualified name of the XML data's parent elementwriter- the XML writer used to output the XML data- Throws:
XMLStreamException- if an unexpected error occurred while processing the XML output
-
writeJsonValue
void writeJsonValue(@NonNull Object instance, @NonNull com.fasterxml.jackson.core.JsonGenerator writer) throws IOException
Writes the provided Java class instance as a JSON/YAML field value.- Parameters:
instance- theFieldinstance value to writewriter- the JSON/YAML writer used to output the JSON/YAML data- Throws:
IOException- if an unexpected error occurred while writing the JSON/YAML output
-
getDefaultJsonValueKey
@NonNull String getDefaultJsonValueKey()
Gets the default value to use as the JSON/YAML field name for a Metaschema field value if no JSON value key flag or name is configured.- Returns:
- the default field name to use
-
isUnrappedValueAllowedInXml
boolean isUnrappedValueAllowedInXml()
Determines if the data type's value is allowed to be unwrapped in XML when the value is a field value.- Returns:
trueif allowed, orfalseotherwise.
-
isXmlMixed
boolean isXmlMixed()
Determines if the datatype uses mixed text and element content in XML.- Returns:
trueif the datatype uses mixed text and element content in XML, orfalseotherwise
-
-