com.cedarsoft.serialization.generator.common.output.serializer
Class AbstractGenerator<T extends com.cedarsoft.codegen.DecisionCallback>

java.lang.Object
  extended by com.cedarsoft.serialization.generator.common.output.GeneratorBase<T>
      extended by com.cedarsoft.serialization.generator.common.output.serializer.AbstractGenerator<T>
Type Parameters:
T - the type of the decision callback
Direct Known Subclasses:
AbstractNamespaceBasedGenerator

public abstract class AbstractGenerator<T extends com.cedarsoft.codegen.DecisionCallback>
extends GeneratorBase<T>

Generator base class for serializer generators


Field Summary
static String METHOD_NAME_DESERIALIZE
          The name of the deserialize method
static String METHOD_NAME_DESERIALIZE_FROM
           
static String METHOD_NAME_SERIALIZE
          The name of the serialize method
static String PARAM_NAME_FORMAT_VERSION
           
static String PARAM_NAME_SERIALIZE_TO
           
static String SERIALIZER_CLASS_NAME_SUFFIX
          The suffix used for generated serializers
static String VAR_NAME_OBJECT
           
 
Fields inherited from class com.cedarsoft.serialization.generator.common.output.GeneratorBase
codeGenerator, codeModel
 
Constructor Summary
protected AbstractGenerator(com.cedarsoft.codegen.CodeGenerator codeGenerator)
           
 
Method Summary
 void addDelegatingSerializerToConstructor(com.sun.codemodel.JDefinedClass serializerClass, com.sun.codemodel.JClass fieldType)
           
protected abstract  com.sun.codemodel.JVar appendDeserializeStatement(com.sun.codemodel.JDefinedClass serializerClass, com.sun.codemodel.JMethod deserializeMethod, com.sun.codemodel.JVar deserializeFrom, com.sun.codemodel.JVar wrapper, com.sun.codemodel.JVar formatVersion, com.cedarsoft.codegen.model.FieldWithInitializationInfo fieldInfo)
          Appends the deserialize statement and return the created var containing the value
protected abstract  void appendSerializeStatement(com.sun.codemodel.JDefinedClass serializerClass, com.sun.codemodel.JMethod serializeMethod, com.sun.codemodel.JVar serializeTo, com.sun.codemodel.JVar object, com.sun.codemodel.JVar formatVersion, com.cedarsoft.codegen.model.FieldWithInitializationInfo fieldInfo)
          Appends the serialize statement
protected  void constructDeserializedObject(com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor, com.sun.codemodel.JMethod deserializeMethod, Map<com.cedarsoft.codegen.model.FieldWithInitializationInfo,com.sun.codemodel.JVar> fieldToVar)
           
protected abstract  com.sun.codemodel.JMethod createConstructor(com.sun.codemodel.JDefinedClass serializerClass, com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor)
          Creates the constructor for the given serializer class (if necessary)
protected  com.sun.codemodel.JMethod createDeserializeMethodStub(com.sun.codemodel.JType domainType, com.sun.codemodel.JDefinedClass serializerClass)
           
protected  com.sun.codemodel.JVar createDeserializeWrapper(com.sun.codemodel.JMethod deserializeMethod, com.sun.codemodel.JVar deserializeFrom)
          Creates the deserialize wrapper.
protected  com.sun.codemodel.JMethod createSerializeMethodStub(com.sun.codemodel.JType domainType, com.sun.codemodel.JDefinedClass serializerClass)
           
static String createSerializerClassName(String domainClassName)
          Creates the class name for the serializer
protected abstract  com.sun.codemodel.JClass createSerializerExtendsExpression(com.sun.codemodel.JClass domainType)
          Returns the class the serializer extends (including type information!)
protected  Map<com.cedarsoft.codegen.model.FieldWithInitializationInfo,com.sun.codemodel.JVar> fillDeSerializationMethods(com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor, com.sun.codemodel.JDefinedClass serializerClass, com.sun.codemodel.JMethod serializeMethod, com.sun.codemodel.JMethod deserializeMethod)
           
protected  void finishConstructor(com.sun.codemodel.JDefinedClass serializerClass, com.sun.codemodel.JMethod constructor)
           
 com.sun.codemodel.JDefinedClass generateSerializer(com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor)
          Generates the serializer
protected abstract  Class<?> getExceptionType()
          Returns the exception type that is thrown on the serialize and deserialize methods
protected abstract  Class<?> getSerializeFromType()
          Returns the type of the serialize from object
protected  com.sun.codemodel.JClass getSerializerRefFor(com.sun.codemodel.JType type)
           
protected abstract  Class<?> getSerializeToType()
          Returns the type of the serializeTo type
 
Methods inherited from class com.cedarsoft.serialization.generator.common.output.GeneratorBase
getCodeGenerator, getCodeModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIALIZER_CLASS_NAME_SUFFIX

@Nonnull
public static final String SERIALIZER_CLASS_NAME_SUFFIX
The suffix used for generated serializers

See Also:
Constant Field Values

METHOD_NAME_SERIALIZE

public static final String METHOD_NAME_SERIALIZE
The name of the serialize method

See Also:
Constant Field Values

METHOD_NAME_DESERIALIZE

public static final String METHOD_NAME_DESERIALIZE
The name of the deserialize method

See Also:
Constant Field Values

METHOD_NAME_DESERIALIZE_FROM

public static final String METHOD_NAME_DESERIALIZE_FROM
See Also:
Constant Field Values

PARAM_NAME_FORMAT_VERSION

public static final String PARAM_NAME_FORMAT_VERSION
See Also:
Constant Field Values

PARAM_NAME_SERIALIZE_TO

public static final String PARAM_NAME_SERIALIZE_TO
See Also:
Constant Field Values

VAR_NAME_OBJECT

public static final String VAR_NAME_OBJECT
See Also:
Constant Field Values
Constructor Detail

AbstractGenerator

protected AbstractGenerator(@Nonnull
                            com.cedarsoft.codegen.CodeGenerator codeGenerator)
Method Detail

createSerializerExtendsExpression

@Nonnull
protected abstract com.sun.codemodel.JClass createSerializerExtendsExpression(@Nonnull
                                                                                      com.sun.codemodel.JClass domainType)
Returns the class the serializer extends (including type information!)

Parameters:
domainType - the domain type
Returns:
the class the serializer extends

createSerializerClassName

@Nonnull
public static String createSerializerClassName(@Nonnull
                                                       String domainClassName)
Creates the class name for the serializer

Parameters:
domainClassName - the class name of the domain object that is serialized
Returns:
the created class name for the serializer

generateSerializer

@Nonnull
public com.sun.codemodel.JDefinedClass generateSerializer(@Nonnull
                                                                  com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor)
                                                   throws com.sun.codemodel.JClassAlreadyExistsException
Generates the serializer

Parameters:
domainObjectDescriptor - the domain object descriptor
Returns:
the defined serializer class
Throws:
com.sun.codemodel.JClassAlreadyExistsException

finishConstructor

protected void finishConstructor(@Nonnull
                                 com.sun.codemodel.JDefinedClass serializerClass,
                                 @Nonnull
                                 com.sun.codemodel.JMethod constructor)

constructDeserializedObject

protected void constructDeserializedObject(@Nonnull
                                           com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor,
                                           @Nonnull
                                           com.sun.codemodel.JMethod deserializeMethod,
                                           @Nonnull
                                           Map<com.cedarsoft.codegen.model.FieldWithInitializationInfo,com.sun.codemodel.JVar> fieldToVar)

createConstructor

@Nonnull
protected abstract com.sun.codemodel.JMethod createConstructor(@Nonnull
                                                                       com.sun.codemodel.JDefinedClass serializerClass,
                                                                       @Nonnull
                                                                       com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor)
Creates the constructor for the given serializer class (if necessary)

Parameters:
serializerClass - the serialize class
domainObjectDescriptor - the domain object descriptor
Returns:
the created constructor

createSerializeMethodStub

@Nonnull
protected com.sun.codemodel.JMethod createSerializeMethodStub(@Nonnull
                                                                      com.sun.codemodel.JType domainType,
                                                                      @Nonnull
                                                                      com.sun.codemodel.JDefinedClass serializerClass)

createDeserializeMethodStub

@Nonnull
protected com.sun.codemodel.JMethod createDeserializeMethodStub(@Nonnull
                                                                        com.sun.codemodel.JType domainType,
                                                                        @Nonnull
                                                                        com.sun.codemodel.JDefinedClass serializerClass)

fillDeSerializationMethods

@Nonnull
protected Map<com.cedarsoft.codegen.model.FieldWithInitializationInfo,com.sun.codemodel.JVar> fillDeSerializationMethods(@Nonnull
                                                                                                                                 com.cedarsoft.codegen.model.DomainObjectDescriptor domainObjectDescriptor,
                                                                                                                                 @Nonnull
                                                                                                                                 com.sun.codemodel.JDefinedClass serializerClass,
                                                                                                                                 @Nonnull
                                                                                                                                 com.sun.codemodel.JMethod serializeMethod,
                                                                                                                                 @Nonnull
                                                                                                                                 com.sun.codemodel.JMethod deserializeMethod)

createDeserializeWrapper

@Nullable
protected com.sun.codemodel.JVar createDeserializeWrapper(@Nonnull
                                                                   com.sun.codemodel.JMethod deserializeMethod,
                                                                   @Nonnull
                                                                   com.sun.codemodel.JVar deserializeFrom)
Creates the deserialize wrapper. This method may be overridden by subclasses if a wrapper shall be used.

Parameters:
deserializeMethod - the deserialize method
deserializeFrom - the deserialize from
Returns:
the wrapper or null if no wrapper exists

addDelegatingSerializerToConstructor

public void addDelegatingSerializerToConstructor(@Nonnull
                                                 com.sun.codemodel.JDefinedClass serializerClass,
                                                 @Nonnull
                                                 com.sun.codemodel.JClass fieldType)

getSerializerRefFor

@Nonnull
protected com.sun.codemodel.JClass getSerializerRefFor(@Nonnull
                                                               com.sun.codemodel.JType type)

getExceptionType

@Nonnull
protected abstract Class<?> getExceptionType()
Returns the exception type that is thrown on the serialize and deserialize methods

Returns:
the exception type

getSerializeFromType

@Nonnull
protected abstract Class<?> getSerializeFromType()
Returns the type of the serialize from object

Returns:
the type of the serialize from object

getSerializeToType

@Nonnull
protected abstract Class<?> getSerializeToType()
Returns the type of the serializeTo type

Returns:
the type of the serializeTo type

appendDeserializeStatement

@Nonnull
protected abstract com.sun.codemodel.JVar appendDeserializeStatement(@Nonnull
                                                                             com.sun.codemodel.JDefinedClass serializerClass,
                                                                             @Nonnull
                                                                             com.sun.codemodel.JMethod deserializeMethod,
                                                                             @Nonnull
                                                                             com.sun.codemodel.JVar deserializeFrom,
                                                                             @Nullable
                                                                             com.sun.codemodel.JVar wrapper,
                                                                             @Nonnull
                                                                             com.sun.codemodel.JVar formatVersion,
                                                                             @Nonnull
                                                                             com.cedarsoft.codegen.model.FieldWithInitializationInfo fieldInfo)
Appends the deserialize statement and return the created var containing the value

Parameters:
serializerClass - the serializer class
deserializeMethod - the deserialize method
deserializeFrom - deserialize from
wrapper - the wrapper that may be used
formatVersion - the format version
fieldInfo - the field info
Returns:
the var holding the deserialized value

appendSerializeStatement

protected abstract void appendSerializeStatement(@Nonnull
                                                 com.sun.codemodel.JDefinedClass serializerClass,
                                                 @Nonnull
                                                 com.sun.codemodel.JMethod serializeMethod,
                                                 @Nonnull
                                                 com.sun.codemodel.JVar serializeTo,
                                                 @Nonnull
                                                 com.sun.codemodel.JVar object,
                                                 @Nonnull
                                                 com.sun.codemodel.JVar formatVersion,
                                                 @Nonnull
                                                 com.cedarsoft.codegen.model.FieldWithInitializationInfo fieldInfo)
Appends the serialize statement

Parameters:
serializerClass - the serializer class
serializeMethod - the serialize method
serializeTo - serialize to
object - the object that is serialized
formatVersion - the format version
fieldInfo - the field info


Copyright © 2011 cedarsoft GmbH. All Rights Reserved.