Package org.jibx.binding.def
Class ObjectStringConversion
- java.lang.Object
-
- org.jibx.binding.def.StringConversion
-
- org.jibx.binding.def.ObjectStringConversion
-
public class ObjectStringConversion extends StringConversion
Object string conversion handling. Defines serialization handling for converting objects to and from aStringvalue. The default is to just use the objecttoString()method for serialization and a constructor from aStringvalue for deserialization.java.lang.Stringitself is a special case, with no added code used by default for either serializing or deserializing.java.lang.Objectis also a special case, with no added code used by default for deserializing (theStringvalue is used directly). Other classes must either implementtoString()and a constructor fromString, or use custom serializers and/or deserializers.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringFROMSTRING_SIGNATUREprivate ClassItemm_initFromStringInitializer used for creating instance fromString(only used if no conversion needed and no deserializer supplied; may benull)private ClassItemm_instToStringtoString()method for converting instance toString(only used if conversion needed and no serializer supplied; may benull)private booleanm_needDeserializeFlag for conversion fromStringneeded (type is anything other thanStringorObject)private booleanm_needSerializeFlag for conversion toStringneeded (type is anything other thanString)private static java.lang.StringNAME_METHODprivate static java.lang.StringNAME_SIGNATUREprivate static java.lang.StringTOSTRING_METHODprivate static java.lang.StringTOSTRING_SIGNATURE-
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 Constructor Description ObjectStringConversion(java.lang.Object dflt, java.lang.String ser, java.lang.String deser, java.lang.String type)Constructor.ObjectStringConversion(java.lang.String type, ObjectStringConversion inherit)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ObjectconvertDefault(java.lang.String text)Convert text representation into default value object.StringConversionderive(java.lang.String type, java.lang.String ser, java.lang.String conv, java.lang.String dser, java.lang.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(java.lang.String type, ContextMethodBuilder mb, int extra)Generate code to check if an optional value is not equal to the default.voidgenToText(java.lang.String type, ContextMethodBuilder mb)Shared code generation for converting instance of type toString.private voidinitMethods(boolean require)Initialize methods used for conversion of types without serializer or deserializer.booleanisPrimitive()Check if the type handled by this conversion is of a primitive type.-
Methods inherited from class org.jibx.binding.def.StringConversion
genPopValues, genWriteOptional, genWriteRequired, genWriteText, getTypeName, setDeserializer, setSerializer, setWhitespaceConverter
-
-
-
-
Field Detail
-
TOSTRING_METHOD
private static final java.lang.String TOSTRING_METHOD
- See Also:
- Constant Field Values
-
TOSTRING_SIGNATURE
private static final java.lang.String TOSTRING_SIGNATURE
- See Also:
- Constant Field Values
-
FROMSTRING_SIGNATURE
private static final java.lang.String FROMSTRING_SIGNATURE
- See Also:
- Constant Field Values
-
NAME_METHOD
private static final java.lang.String NAME_METHOD
- See Also:
- Constant Field Values
-
NAME_SIGNATURE
private static final java.lang.String NAME_SIGNATURE
- See Also:
- Constant Field Values
-
m_needDeserialize
private boolean m_needDeserialize
Flag for conversion fromStringneeded (type is anything other thanStringorObject)
-
m_initFromString
private ClassItem m_initFromString
Initializer used for creating instance fromString(only used if no conversion needed and no deserializer supplied; may benull)
-
m_needSerialize
private boolean m_needSerialize
Flag for conversion toStringneeded (type is anything other thanString)
-
m_instToString
private ClassItem m_instToString
toString()method for converting instance toString(only used if conversion needed and no serializer supplied; may benull)
-
-
Constructor Detail
-
ObjectStringConversion
ObjectStringConversion(java.lang.String type, ObjectStringConversion inherit) throws JiBXExceptionConstructor. Initializes conversion handling based on the supplied inherited handling.- Parameters:
type- fully qualified name of class handled by conversioninherit- conversion information inherited by this conversion- Throws:
JiBXException- if error in configuration
-
ObjectStringConversion
ObjectStringConversion(java.lang.Object dflt, java.lang.String ser, java.lang.String deser, java.lang.String type)Constructor. Initializes conversion handling based on argument values. This form is only used for constructing the default set of conversions. Because of this, it throws an unchecked exception on error.- Parameters:
dflt- default value object (wrapped value for primitive types, otherwiseString)ser- fully qualified name of serialization method (nullif none)deser- fully qualified name of deserialization method (nullif none)type- fully qualified name of class handled by conversion
-
-
Method Detail
-
initMethods
private void initMethods(boolean require) throws JiBXExceptionInitialize methods used for conversion of types without serializer or deserializer. Sets flags for types needed, with errors thrown at time of attempted use rather than at definition time. That offers the advantages of simpler handling (we don't need to know which directions are supported in a binding) and more flexibility (can support nested partial definitions cleanly).- Parameters:
require- class loading required flag- Throws:
JiBXException
-
genFromText
public void genFromText(ContextMethodBuilder mb) throws JiBXException
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- Throws:
JiBXException
-
genParseOptional
public void genParseOptional(boolean attr, ContextMethodBuilder mb) throws 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 converted 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:
JiBXException- if error in configuration
-
genParseRequired
public void genParseRequired(boolean attr, ContextMethodBuilder mb) throws 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:
JiBXException- if error in configuration
-
genToText
public void genToText(java.lang.String type, ContextMethodBuilder mb) throws JiBXExceptionShared code generation for converting instance of type toString. This override of the base class method checks for serialization using thetoStringmethod and implements that case directly, while calling the base class method for normal handling. The code generated by this method assumes that the reference to the instance to be converted is on the stack. It consumes the reference, replacing it with the correspondingStringvalue.- Overrides:
genToTextin classStringConversion- Parameters:
type- fully qualified class name for value on stackmb- marshal method builder- Throws:
JiBXException- if error in configuration
-
genToOptionalText
protected BranchWrapper genToOptionalText(java.lang.String type, ContextMethodBuilder mb, int extra) throws 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:
JiBXException- if error in configuration
-
isPrimitive
public boolean isPrimitive()
Check if the type handled by this conversion is of a primitive type.- Specified by:
isPrimitivein classStringConversion- Returns:
falseto indicate object type
-
convertDefault
protected java.lang.Object convertDefault(java.lang.String text) throws JiBXExceptionConvert text representation into default value object. For object types this just returns the text value.- Specified by:
convertDefaultin classStringConversion- Parameters:
text- value representation to be converted- Returns:
- converted default value object
- Throws:
JiBXException- on conversion error
-
derive
public StringConversion derive(java.lang.String type, java.lang.String ser, java.lang.String conv, java.lang.String dser, java.lang.String dflt) throws 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:
JiBXException- if error in configuration information
-
-