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

java.lang.Object
  extended by com.cedarsoft.serialization.generator.output.GeneratorBase<T>
      extended by com.cedarsoft.serialization.generator.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.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 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.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.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

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

See Also:
Constant Field Values

METHOD_NAME_SERIALIZE

@NonNls
public static final String METHOD_NAME_SERIALIZE
The name of the serialize method

See Also:
Constant Field Values

METHOD_NAME_DESERIALIZE

@NonNls
public static final String METHOD_NAME_DESERIALIZE
The name of the deserialize method

See Also:
Constant Field Values

METHOD_NAME_DESERIALIZE_FROM

@NonNls
public static final String METHOD_NAME_DESERIALIZE_FROM
See Also:
Constant Field Values

PARAM_NAME_FORMAT_VERSION

@NonNls
public static final String PARAM_NAME_FORMAT_VERSION
See Also:
Constant Field Values

PARAM_NAME_SERIALIZE_TO

@NonNls
public static final String PARAM_NAME_SERIALIZE_TO
See Also:
Constant Field Values

VAR_NAME_OBJECT

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

AbstractGenerator

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

createSerializerExtendsExpression

@NotNull
protected abstract com.sun.codemodel.JClass createSerializerExtendsExpression(@NotNull
                                                                                      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

@NotNull
@NonNls
public static String createSerializerClassName(@NotNull@NonNls
                                                              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

@NotNull
public com.sun.codemodel.JDefinedClass generateSerializer(@NotNull
                                                                  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(@NotNull
                                 com.sun.codemodel.JDefinedClass serializerClass,
                                 @NotNull
                                 com.sun.codemodel.JMethod constructor)

constructDeserializedObject

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

createConstructor

@NotNull
protected abstract com.sun.codemodel.JMethod createConstructor(@NotNull
                                                                       com.sun.codemodel.JDefinedClass serializerClass,
                                                                       @NotNull
                                                                       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

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

createDeserializeMethodStub

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

fillDeSerializationMethods

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

addDelegatingSerializerToConstructor

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

getSerializerRefFor

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

getExceptionType

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

Returns:
the exception type

getSerializeFromType

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

Returns:
the type of the serialize from object

getSerializeToType

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

Returns:
the type of the serializeTo type

appendDeserializeStatement

@NotNull
protected abstract com.sun.codemodel.JVar appendDeserializeStatement(@NotNull
                                                                             com.sun.codemodel.JDefinedClass serializerClass,
                                                                             @NotNull
                                                                             com.sun.codemodel.JMethod deserializeMethod,
                                                                             @NotNull
                                                                             com.sun.codemodel.JVar deserializeFrom,
                                                                             @NotNull
                                                                             com.sun.codemodel.JVar formatVersion,
                                                                             @NotNull
                                                                             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
formatVersion - the format version
fieldInfo - the field info
Returns:
the var holding the deserialized value

appendSerializeStatement

protected abstract void appendSerializeStatement(@NotNull
                                                 com.sun.codemodel.JDefinedClass serializerClass,
                                                 @NotNull
                                                 com.sun.codemodel.JMethod serializeMethod,
                                                 @NotNull
                                                 com.sun.codemodel.JVar serializeTo,
                                                 @NotNull
                                                 com.sun.codemodel.JVar object,
                                                 @NotNull
                                                 com.sun.codemodel.JVar formatVersion,
                                                 @NotNull
                                                 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.