org.jibx.binding.def
Class PrimitiveStringConversion

java.lang.Object
  extended by org.jibx.binding.def.StringConversion
      extended by org.jibx.binding.def.PrimitiveStringConversion

public class PrimitiveStringConversion
extends StringConversion

Primitive string conversion handling. Class for handling serialization converting a primitive type to and from String values.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
private static int DOUBLE_TYPE
           
private static int FLOAT_TYPE
           
private static int INT_TYPE
           
private static int LONG_TYPE
           
private  boolean m_isMarshalText
          Marshalling requires conversion to text flag.
private  boolean m_isUnmarshalText
          Unmarshalling requires conversion to text flag.
private  java.lang.String m_stackType
          Name of value type on stack.
private  ClassItem m_unmarshalOptAttribute
          Unmarshalling context method for optional attribute.
private  ClassItem m_unmarshalOptElement
          Unmarshalling context method for optional element.
private  ClassItem m_unmarshalReqAttribute
          Unmarshalling context method for required attribute.
private  ClassItem m_unmarshalReqElement
          Unmarshalling context method for required element.
private  int m_valueType
          Comparison and marshal type of value (INT_TYPE, LONG_TYPE, FLOAT_TYPE, or DOUBLE_TYPE)
private static ClassFile s_unmarshalClass
           
private static java.lang.Class[] SINGLE_STRING_ARGS
          Constant argument type array for finding conversion methods.
private static java.lang.String UNMARSHAL_SIG_LEAD
          Unmarshal method signature leading portion.
private static java.lang.String UTILITY_CLASS_NAME
          Class providing basic conversion methods.
 
Fields inherited from class org.jibx.binding.def.StringConversion
COMPARE_OBJECTS_METHOD, COMPARE_OBJECTS_SIGNATURE, DESERIALIZER_SIGNATURES, 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
 
Constructor Summary
  PrimitiveStringConversion(java.lang.Class cls, java.lang.Object dflt, java.lang.String code, java.lang.String ts, java.lang.String fs, java.lang.String uattr, java.lang.String uelem)
          Constructor.
protected PrimitiveStringConversion(java.lang.String type, PrimitiveStringConversion inherit)
          Constructor.
 
Method Summary
protected  java.lang.Object convertDefault(java.lang.String text)
          Convert text representation into default value object.
 StringConversion derive(java.lang.String type, java.lang.String ser, java.lang.String dser, java.lang.String dflt)
          Derive from existing formatting information.
 void genFromText(ContextMethodBuilder mb)
          Generate code to convert String representation.
 void genParseOptional(boolean attr, ContextMethodBuilder mb)
          Generate code to parse and convert optional attribute or element.
 void genParseRequired(boolean attr, ContextMethodBuilder mb)
          Generate code to parse and convert required attribute or element.
protected  BranchWrapper genToOptionalText(java.lang.String type, ContextMethodBuilder mb, int extra)
          Generate code to check if an optional value is not equal to the default.
 boolean isPrimitive()
          Check if the type handled by this conversion is of a primitive type.
protected  void pushDefault(ContextMethodBuilder mb)
          Push default value on stack.
protected  void setDeserializer(java.lang.String deser)
          Set deserializer for conversion.
protected  void setSerializer(java.lang.String ser)
          Set serializer for conversion.
 
Methods inherited from class org.jibx.binding.def.StringConversion
genPopValues, genToText, genWriteOptional, genWriteRequired, genWriteText, getTypeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_unmarshalClass

private static ClassFile s_unmarshalClass

INT_TYPE

private static final int INT_TYPE
See Also:
Constant Field Values

LONG_TYPE

private static final int LONG_TYPE
See Also:
Constant Field Values

FLOAT_TYPE

private static final int FLOAT_TYPE
See Also:
Constant Field Values

DOUBLE_TYPE

private static final int DOUBLE_TYPE
See Also:
Constant Field Values

UTILITY_CLASS_NAME

private static final java.lang.String UTILITY_CLASS_NAME
Class providing basic conversion methods.

See Also:
Constant Field Values

UNMARSHAL_SIG_LEAD

private static final java.lang.String UNMARSHAL_SIG_LEAD
Unmarshal method signature leading portion.

See Also:
Constant Field Values

SINGLE_STRING_ARGS

private static final java.lang.Class[] SINGLE_STRING_ARGS
Constant argument type array for finding conversion methods.


m_isMarshalText

private boolean m_isMarshalText
Marshalling requires conversion to text flag.


m_isUnmarshalText

private boolean m_isUnmarshalText
Unmarshalling requires conversion to text flag.


m_unmarshalOptAttribute

private ClassItem m_unmarshalOptAttribute
Unmarshalling context method for optional attribute.


m_unmarshalOptElement

private ClassItem m_unmarshalOptElement
Unmarshalling context method for optional element.


m_unmarshalReqAttribute

private ClassItem m_unmarshalReqAttribute
Unmarshalling context method for required attribute.


m_unmarshalReqElement

private ClassItem m_unmarshalReqElement
Unmarshalling context method for required element.


m_valueType

private int m_valueType
Comparison and marshal type of value (INT_TYPE, LONG_TYPE, FLOAT_TYPE, or DOUBLE_TYPE)


m_stackType

private java.lang.String m_stackType
Name of value type on stack.

Constructor Detail

PrimitiveStringConversion

protected PrimitiveStringConversion(java.lang.String type,
                                    PrimitiveStringConversion inherit)
Constructor. Initializes conversion handling based on the supplied inherited handling.

Parameters:
type - name of primitive type handled by conversion
inherit - conversion information inherited by this conversion

PrimitiveStringConversion

public PrimitiveStringConversion(java.lang.Class cls,
                                 java.lang.Object dflt,
                                 java.lang.String code,
                                 java.lang.String ts,
                                 java.lang.String fs,
                                 java.lang.String uattr,
                                 java.lang.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 conversion
dflt - default value object (wrapped value, or String or null with special deserializer)
ts - name of utility class static method for converting value to String
fs - name of utility class static method for converting String to value
uattr - unmarshalling context method name for attribute value
uelem - unmarshalling context method name for element value
Method Detail

genFromText

public void genFromText(ContextMethodBuilder mb)
Generate code to convert String representation. The code generated by this method assumes that the String value has already been pushed on the stack. It consumes this and leaves the converted value on the stack.

Specified by:
genFromText in class StringConversion
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 JiBXException
Generate 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:
genParseOptional in class StringConversion
Parameters:
attr - item is an attribute (vs element) flag
mb - method builder
Throws:
JiBXException - if error in configuration

genParseRequired

public void genParseRequired(boolean attr,
                             ContextMethodBuilder mb)
                      throws JiBXException
Generate 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:
genParseRequired in class StringConversion
Parameters:
attr - item is an attribute (vs element) flag
mb - 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:
genToOptionalText in class StringConversion
Parameters:
type - fully qualified class name for value on stack
mb - method builder
extra - 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

convertDefault

protected java.lang.Object convertDefault(java.lang.String text)
                                   throws 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 the String value directly.

Specified by:
convertDefault in class StringConversion
Parameters:
text - value representation to be converted
Returns:
converted default value object
Throws:
JiBXException - on conversion error

isPrimitive

public boolean isPrimitive()
Check if the type handled by this conversion is of a primitive type.

Specified by:
isPrimitive in class StringConversion
Returns:
true to indicate primitive type

setSerializer

protected void setSerializer(java.lang.String ser)
                      throws 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.

Overrides:
setSerializer in class StringConversion
Parameters:
ser - fully qualified class and method name of serializer
Throws:
JiBXException - if serializer not found or not usable

setDeserializer

protected void setDeserializer(java.lang.String deser)
                        throws 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:
setDeserializer in class StringConversion
Parameters:
deser - fully qualified class and method name of deserializer
Throws:
JiBXException - if deserializer not found or not usable

derive

public StringConversion derive(java.lang.String type,
                               java.lang.String ser,
                               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:
derive in class StringConversion
Parameters:
type - fully qualified name of class handled by conversion
ser - fully qualified name of serialization method (null if inherited)
dser - fully qualified name of deserialization method (null if inherited)
dflt - default value text (null if inherited)
Returns:
new instance initialized from existing one
Throws:
JiBXException - if error in configuration information


Project Web Site