Package org.jibx.binding.def
Class PrimitiveStringConversion
- java.lang.Object
-
- org.jibx.binding.def.StringConversion
-
- org.jibx.binding.def.PrimitiveStringConversion
-
public class PrimitiveStringConversion extends StringConversion
Primitive string conversion handling. Class for handling serialization converting a primitive type to and fromStringvalues.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
-
Fields inherited from class org.jibx.binding.def.StringConversion
COMPARE_OBJECTS_METHOD, COMPARE_OBJECTS_SIGNATURE, DESERIALIZER_SIGNATURES, m_converter, m_default, m_deserializer, m_serializer, m_typeName, m_typeSignature, MARSHAL_ATTRIBUTE, MARSHAL_ELEMENT, MARSHAL_NAME_VALUES, MARSHAL_SIGNATURE, UNMARSHAL_OPT_ATTRIBUTE, UNMARSHAL_OPT_ELEMENT, UNMARSHAL_OPT_SIGNATURE, UNMARSHAL_REQ_ATTRIBUTE, UNMARSHAL_REQ_ELEMENT, UNMARSHAL_REQ_SIGNATURE, WHITESPACE_CONVERT_SIGNATURES
-
-
Constructor Summary
Constructors Modifier Constructor Description PrimitiveStringConversion(Class cls, Object dflt, String code, String ts, String fs, String uattr, String uelem)Constructor.protectedPrimitiveStringConversion(String type, PrimitiveStringConversion inherit)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ObjectconvertDefault(String text)Convert text representation into default value object.StringConversionderive(String type, String ser, String conv, String dser, String dflt)Derive from existing formatting information.voidgenFromText(ContextMethodBuilder mb)Generate code to convertStringrepresentation.voidgenParseOptional(boolean attr, ContextMethodBuilder mb)Generate code to parse and convert optional attribute or element.voidgenParseRequired(boolean attr, ContextMethodBuilder mb)Generate code to parse and convert required attribute or element.protected BranchWrappergenToOptionalText(String type, ContextMethodBuilder mb, int extra)Generate code to check if an optional value is not equal to the default.booleanisPrimitive()Check if the type handled by this conversion is of a primitive type.protected voidpushDefault(ContextMethodBuilder mb)Push default value on stack.protected voidsetDeserializer(String deser)Set deserializer for conversion.protected voidsetSerializer(String ser)Set serializer for conversion.protected voidsetWhitespaceConverter(String wsconv)Set whitespace converter for conversion.-
Methods inherited from class org.jibx.binding.def.StringConversion
genPopValues, genToText, genWriteOptional, genWriteRequired, genWriteText, getTypeName, setSerializer
-
-
-
-
Constructor Detail
-
PrimitiveStringConversion
protected PrimitiveStringConversion(String type, PrimitiveStringConversion inherit)
Constructor. Initializes conversion handling based on the supplied inherited handling.- Parameters:
type- name of primitive type handled by conversioninherit- conversion information inherited by this conversion
-
PrimitiveStringConversion
public PrimitiveStringConversion(Class cls, Object dflt, String code, String ts, String fs, String uattr, String uelem)
Constructor. Initializes conversion handling based on argument values. This form is only used for constructing the default set of conversions.- Parameters:
cls- class of primitive type handled by conversiondflt- default value object (wrapped value, orStringornullwith special deserializer)code- primitive type codets- name of utility class static method for converting value toStringfs- name of utility class static method for convertingStringto valueuattr- unmarshalling context method name for attribute valueuelem- unmarshalling context method name for element value
-
-
Method Detail
-
genFromText
public void genFromText(ContextMethodBuilder mb)
Generate code to convertStringrepresentation. The code generated by this method assumes that theStringvalue has already been pushed on the stack. It consumes this and leaves the converted value on the stack.- Specified by:
genFromTextin classStringConversion- Parameters:
mb- method builder
-
pushDefault
protected void pushDefault(ContextMethodBuilder mb)
Push default value on stack. Just adds the appropriate instruction to the list for the method.- Parameters:
mb- method builder
-
genParseOptional
public void genParseOptional(boolean attr, ContextMethodBuilder mb) throws org.jibx.runtime.JiBXExceptionGenerate code to parse and convert optional attribute or element. The code generated by this method assumes that the unmarshalling context and name information for the attribute or element have already been pushed on the stack. It consumes these and leaves the converted value (or default value, if the item itself is missing) on the stack.- Specified by:
genParseOptionalin classStringConversion- Parameters:
attr- item is an attribute (vs element) flagmb- method builder- Throws:
org.jibx.runtime.JiBXException- if error in configuration
-
genParseRequired
public void genParseRequired(boolean attr, ContextMethodBuilder mb) throws org.jibx.runtime.JiBXExceptionGenerate code to parse and convert required attribute or element. The code generated by this method assumes that the unmarshalling context and name information for the attribute or element have already been pushed on the stack. It consumes these and leaves the converted value on the stack.- Specified by:
genParseRequiredin classStringConversion- Parameters:
attr- item is an attribute (vs element) flagmb- method builder- Throws:
org.jibx.runtime.JiBXException- if error in configuration
-
genToOptionalText
protected BranchWrapper genToOptionalText(String type, ContextMethodBuilder mb, int extra) throws org.jibx.runtime.JiBXException
Generate code to check if an optional value is not equal to the default. The code generated by this method assumes that the actual value to be converted has already been pushed on the stack. It consumes this, leaving the converted text reference on the stack if it's not equal to the default value.- Specified by:
genToOptionalTextin classStringConversion- Parameters:
type- fully qualified class name for value on stackmb- method builderextra- count of extra values to be popped from stack if missing- Returns:
- handle for branch taken when value is equal to the default (target must be set by caller)
- Throws:
org.jibx.runtime.JiBXException- if error in configuration
-
convertDefault
protected Object convertDefault(String text) throws org.jibx.runtime.JiBXException
Convert text representation into default value object. This override of the base class method uses reflection to call the actual deserialization method, returning the wrapped result value. If a custom deserializer is defined this just returns theStringvalue directly.- Specified by:
convertDefaultin classStringConversion- Parameters:
text- value representation to be converted- Returns:
- converted default value object
- Throws:
org.jibx.runtime.JiBXException- on conversion error
-
isPrimitive
public boolean isPrimitive()
Check if the type handled by this conversion is of a primitive type.- Specified by:
isPrimitivein classStringConversion- Returns:
trueto indicate primitive type
-
setSerializer
protected void setSerializer(String ser) throws org.jibx.runtime.JiBXException
Set serializer for conversion. This override of the base class method sets a flag to indicate that values must be converted to text before they are written to a document after executing the base class processing.- Parameters:
ser- fully qualified class and method name of serializer- Throws:
org.jibx.runtime.JiBXException- if serializer not found or not usable
-
setWhitespaceConverter
protected void setWhitespaceConverter(String wsconv) throws org.jibx.runtime.JiBXException
Set whitespace converter for conversion. This override of the base class method sets a flag to indicate that values must be read from a document as text and converted as a separate step after executing the base class processing.- Overrides:
setWhitespaceConverterin classStringConversion- Parameters:
wsconv- fully qualified class and method name of whitespace converter- Throws:
org.jibx.runtime.JiBXException- if whitespace converter not found or not usable
-
setDeserializer
protected void setDeserializer(String deser) throws org.jibx.runtime.JiBXException
Set deserializer for conversion. This override of the base class method sets a flag to indicate that values must be read from a document as text and converted as a separate step after executing the base class processing.- Overrides:
setDeserializerin classStringConversion- Parameters:
deser- fully qualified class and method name of deserializer- Throws:
org.jibx.runtime.JiBXException- if deserializer not found or not usable
-
derive
public StringConversion derive(String type, String ser, String conv, String dser, String dflt) throws org.jibx.runtime.JiBXException
Derive from existing formatting information. This allows constructing a new instance from an existing format of the same or an ancestor type, with the properties of the existing format copied to the new instance except where overridden by the supplied values.- Specified by:
derivein classStringConversion- Parameters:
type- fully qualified name of class handled by conversion (nullif inherited)ser- fully qualified name of serialization method (nullif inherited)conv- fully qualified name of whitespace conversion method (nullif inherited)dser- fully qualified name of deserialization method (nullif inherited)dflt- default value text (nullif inherited)- Returns:
- new instance initialized from existing one
- Throws:
org.jibx.runtime.JiBXException- if error in configuration information
-
-