Package org.jibx.binding.def
Class StringConversion
- java.lang.Object
-
- org.jibx.binding.def.StringConversion
-
- Direct Known Subclasses:
ObjectStringConversion,PrimitiveStringConversion
public abstract class StringConversion extends java.lang.ObjectString conversion handling. Defines serialization handling for converting to and from aStringvalue. This uses an inheritance approach, where each serialization definition is initialized based on the handling set for the containing definition of the same (or parent class) type.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCOMPARE_OBJECTS_METHODprotected static java.lang.StringCOMPARE_OBJECTS_SIGNATUREprotected static java.lang.String[]DESERIALIZER_SIGNATURESprotected ClassItemm_converterWhitespace conversion method information.protected java.lang.Objectm_defaultDefault value used for this type (wrapper for primitives, otherwiseStringornull).protected ClassItemm_deserializerDeserializer method information.protected ClassItemm_serializerSerializer method information.protected java.lang.Stringm_typeNameFully qualified name of class handled by conversion.protected java.lang.Stringm_typeSignatureSignature of class handled by conversion.protected static java.lang.StringMARSHAL_ATTRIBUTEprotected static java.lang.StringMARSHAL_ELEMENTstatic intMARSHAL_NAME_VALUESprotected static java.lang.StringMARSHAL_SIGNATUREprotected static java.lang.StringUNMARSHAL_OPT_ATTRIBUTEprotected static java.lang.StringUNMARSHAL_OPT_ELEMENTprotected static java.lang.StringUNMARSHAL_OPT_SIGNATUREprotected static java.lang.StringUNMARSHAL_REQ_ATTRIBUTEprotected static java.lang.StringUNMARSHAL_REQ_ELEMENTprotected static java.lang.StringUNMARSHAL_REQ_SIGNATUREprotected static java.lang.String[]WHITESPACE_CONVERT_SIGNATURES
-
Constructor Summary
Constructors Modifier Constructor Description (package private)StringConversion(java.lang.Object dflt, java.lang.String ser, java.lang.String conv, java.lang.String deser, java.lang.String type)Constructor.privateStringConversion(java.lang.String type)Constructor.protectedStringConversion(java.lang.String type, StringConversion inherit)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.ObjectconvertDefault(java.lang.String text)Convert text representation into default value object.abstract 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.abstract voidgenFromText(ContextMethodBuilder mb)Generate code to convertStringrepresentation.abstract voidgenParseOptional(boolean attr, ContextMethodBuilder mb)Generate code to parse and convert optional attribute or element.abstract voidgenParseRequired(boolean attr, ContextMethodBuilder mb)Generate code to parse and convert required attribute or element.voidgenPopValues(int count, ContextMethodBuilder mb)Generate code to pop values from stack.protected abstract 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)Generate code to convert value to aString.voidgenWriteOptional(boolean attr, java.lang.String type, ContextMethodBuilder mb)Generate code to convert and write optional value to generated document.voidgenWriteRequired(boolean attr, java.lang.String type, ContextMethodBuilder mb)Generate code to convert and write required value to generated document.voidgenWriteText(boolean attr, ContextMethodBuilder mb)Generate code to writeStringvalue to generated document.java.lang.StringgetTypeName()Get name of type handled by this conversion.abstract booleanisPrimitive()Check if the type handled by this conversion is of a primitive type.protected voidsetDeserializer(java.lang.String deser)Set deserializer for conversion.protected voidsetSerializer(java.lang.String ser, boolean variant)Set serializer for conversion.protected voidsetWhitespaceConverter(java.lang.String wsconv)Set whitespace converter for conversion.
-
-
-
Field Detail
-
UNMARSHAL_OPT_ATTRIBUTE
protected static final java.lang.String UNMARSHAL_OPT_ATTRIBUTE
- See Also:
- Constant Field Values
-
UNMARSHAL_OPT_ELEMENT
protected static final java.lang.String UNMARSHAL_OPT_ELEMENT
- See Also:
- Constant Field Values
-
UNMARSHAL_OPT_SIGNATURE
protected static final java.lang.String UNMARSHAL_OPT_SIGNATURE
- See Also:
- Constant Field Values
-
UNMARSHAL_REQ_ATTRIBUTE
protected static final java.lang.String UNMARSHAL_REQ_ATTRIBUTE
- See Also:
- Constant Field Values
-
UNMARSHAL_REQ_ELEMENT
protected static final java.lang.String UNMARSHAL_REQ_ELEMENT
- See Also:
- Constant Field Values
-
UNMARSHAL_REQ_SIGNATURE
protected static final java.lang.String UNMARSHAL_REQ_SIGNATURE
- See Also:
- Constant Field Values
-
MARSHAL_ATTRIBUTE
protected static final java.lang.String MARSHAL_ATTRIBUTE
- See Also:
- Constant Field Values
-
MARSHAL_ELEMENT
protected static final java.lang.String MARSHAL_ELEMENT
- See Also:
- Constant Field Values
-
MARSHAL_SIGNATURE
protected static final java.lang.String MARSHAL_SIGNATURE
- See Also:
- Constant Field Values
-
COMPARE_OBJECTS_METHOD
protected static final java.lang.String COMPARE_OBJECTS_METHOD
- See Also:
- Constant Field Values
-
COMPARE_OBJECTS_SIGNATURE
protected static final java.lang.String COMPARE_OBJECTS_SIGNATURE
- See Also:
- Constant Field Values
-
WHITESPACE_CONVERT_SIGNATURES
protected static final java.lang.String[] WHITESPACE_CONVERT_SIGNATURES
-
DESERIALIZER_SIGNATURES
protected static final java.lang.String[] DESERIALIZER_SIGNATURES
-
MARSHAL_NAME_VALUES
public static final int MARSHAL_NAME_VALUES
- See Also:
- Constant Field Values
-
m_default
protected java.lang.Object m_default
Default value used for this type (wrapper for primitives, otherwiseStringornull).
-
m_serializer
protected ClassItem m_serializer
Serializer method information.
-
m_converter
protected ClassItem m_converter
Whitespace conversion method information.
-
m_deserializer
protected ClassItem m_deserializer
Deserializer method information.
-
m_typeName
protected java.lang.String m_typeName
Fully qualified name of class handled by conversion.
-
m_typeSignature
protected java.lang.String m_typeSignature
Signature of class handled by conversion.
-
-
Constructor Detail
-
StringConversion
private StringConversion(java.lang.String type)
Constructor. This internal form only initializes the type information.- Parameters:
type- fully qualified name of class handled by conversion
-
StringConversion
protected StringConversion(java.lang.String type, StringConversion inherit)Constructor. 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
-
StringConversion
StringConversion(java.lang.Object dflt, java.lang.String ser, java.lang.String conv, 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)conv- fully qualified name of whitespace conversion method (nullif none)deser- fully qualified name of deserialization method (nullif none)type- fully qualified name of class handled by conversion
-
-
Method Detail
-
getTypeName
public java.lang.String getTypeName()
Get name of type handled by this conversion.- Returns:
- fully qualified class name of type handled by conversion
-
genFromText
public abstract 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.- Parameters:
mb- method builder- Throws:
JiBXException- if error in configuration
-
genParseOptional
public abstract void genParseOptional(boolean attr, ContextMethodBuilder mb) throws JiBXExceptionGenerate code to parse and convert optional attribute or element. This abstract base class method must be implemented by every subclass. 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.- Parameters:
attr- item is an attribute (vs element) flagmb- method builder- Throws:
JiBXException- if error in configuration
-
genParseRequired
public abstract void genParseRequired(boolean attr, ContextMethodBuilder mb) throws JiBXExceptionGenerate code to parse and convert required attribute or element. This abstract base class method must be implemented by every subclass. 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.- Parameters:
attr- item is an attribute (vs element) flagmb- method builder- Throws:
JiBXException- if error in configuration
-
genWriteText
public void genWriteText(boolean attr, ContextMethodBuilder mb)Generate code to writeStringvalue to generated document. The code generated by this method assumes that the marshalling context, the name information, and the actual value to be converted have already been pushed on the stack. It consumes these, leaving the marshalling context on the stack.- Parameters:
attr- item is an attribute (vs element) flagmb- method builder
-
genPopValues
public void genPopValues(int count, ContextMethodBuilder mb)Generate code to pop values from stack.- Parameters:
count- number of values to be poppedmb- method builder
-
genToOptionalText
protected abstract 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. This abstract base class method must be implemented by every subclass. 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.- Parameters:
type- fully qualified class name for value on stackmb- method builderextra- count of extra words 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
-
genToText
public void genToText(java.lang.String type, ContextMethodBuilder mb) throws JiBXExceptionGenerate code to convert value to aString. 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.- Parameters:
type- fully qualified class name for value on stackmb- method builder- Throws:
JiBXException- if error in configuration
-
genWriteOptional
public void genWriteOptional(boolean attr, java.lang.String type, ContextMethodBuilder mb) throws JiBXExceptionGenerate code to convert and write optional value to generated document. The generated code first tests if the value is the same as the supplied default, and if so skips writing. The code assumes that the marshalling context, the name information, and the actual value to be converted have already been pushed on the stack. It consumes these, leaving only the marshalling context on the stack.- Parameters:
attr- item is an attribute (vs element) flagtype- fully qualified class name for value on stackmb- method builder- Throws:
JiBXException- if error in configuration
-
genWriteRequired
public void genWriteRequired(boolean attr, java.lang.String type, ContextMethodBuilder mb) throws JiBXExceptionGenerate code to convert and write required value to generated document. The code generated by this method assumes that the marshalling context, the name information, and the actual value to be converted have already been pushed on the stack. It consumes these, leaving the returned marshalling context on the stack.- Parameters:
attr- item is an attribute (vs element) flagtype- fully qualified class name for value on stackmb- method builder- Throws:
JiBXException- if error in configuration
-
isPrimitive
public abstract boolean isPrimitive()
Check if the type handled by this conversion is of a primitive type.- Returns:
trueif a primitive type,falseif an object type
-
setSerializer
protected void setSerializer(java.lang.String ser, boolean variant) throws JiBXExceptionSet serializer for conversion. This finds the named static method and sets it as the serializer to be used for this conversion. The serializer method is expected to take a single argument of either the handled type or a superclass or interface of the handled type, and to return aStringresult.- Parameters:
ser- fully qualified class and method name of serializervariant- allow variants of the specified type- Throws:
JiBXException- if serializer not found or not usable
-
setWhitespaceConverter
protected void setWhitespaceConverter(java.lang.String wsconv) throws JiBXExceptionSet whitespace converter for conversion. This finds the named static method and sets it as the whitespace converter to be used for this conversion. The whitespace converter method is expected to take a single argument of typeString, and to return the same.- Parameters:
wsconv- fully qualified class and method name of whitespace converter- Throws:
JiBXException- if whitespace converter not found or not usable
-
setDeserializer
protected void setDeserializer(java.lang.String deser) throws JiBXExceptionSet deserializer for conversion. This finds the named static method and sets it as the deserializer to be used for this conversion. The deserializer method is expected to take a single argument of typeString, and to return a value of the handled type or a subtype of that type.- Parameters:
deser- fully qualified class and method name of deserializer- Throws:
JiBXException- if deserializer not found or not usable
-
convertDefault
protected abstract java.lang.Object convertDefault(java.lang.String text) throws JiBXExceptionConvert text representation into default value object. Each subclass must implement this with the appropriate conversion handling.- Parameters:
text- value representation to be converted- Returns:
- converted default value object
- Throws:
JiBXException- on conversion error
-
derive
public abstract 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 abstract base class method must be implemented by every subclass. It 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.- 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
-
-