|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectma.glasnost.orika.impl.generator.SourceCodeContext
public class SourceCodeContext
SourceCodeContext contains the state information necessary while generating source code for a given mapping object; it also houses various utility methods which can be used to aid in code generation.
| Constructor Summary | |
|---|---|
SourceCodeContext(String baseClassName,
Class<?> superClass,
MappingContext mappingContext,
StringBuilder logDetails)
Constructs a new instance of SourceCodeContext |
|
| Method Summary | ||
|---|---|---|
void |
addField(String fieldSource)
Adds a field definition to the class based on the provided source. |
|
void |
addMethod(String methodSource)
Adds a method definition to the class based on the provided source. |
|
boolean |
aggregateSpecsApply(FieldMap fieldMap)
Tests whether any aggregate specifications apply for the specified FieldMap, and if so, adds it to the list of FieldMaps for that spec, returning true. |
|
static void |
append(StringBuilder out,
String... statements)
Appends all of the String values provided to the StringBuilder in order, as "statements" |
|
String |
assureInstanceExists(VariableRef propertyRef,
VariableRef source)
Append a statement which assures that the variable reference has an existing instance; if it does not, a new object is generated using MapperFacade.newObject |
|
String |
callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression)
|
|
String |
callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression,
String destExpression)
|
|
String |
callMapper(VariableRef source,
Type<?> destination)
|
|
String |
callMapper(VariableRef source,
VariableRef destination)
|
|
String |
compareFields(FieldMap fieldMap,
VariableRef sourceProperty,
VariableRef destinationProperty,
Type<?> destinationType,
StringBuilder logDetails)
Generates source code for an "equality" comparison of two variables, based on the FieldMap passed |
|
protected Class<?> |
compileClass()
Compile and return the (generated) class; this will also cause the generated class to be detached from the class-pool, and any (optional) source and/or class files to be written. |
|
String |
currentElementComparator(Node source,
Node dest,
Node.NodeList srcNodes,
Node.NodeList destNodes)
|
|
void |
debug(String msg)
|
|
static VariableRef |
entrySetRef(VariableRef s)
Creates a VariableRef representing a Set |
|
Set<FieldMap> |
getAssociatedMappings(Collection<FieldMap> fieldMaps,
FieldMap map)
Finds all field maps out of the provided set which are associated with the map passed in ( including that map itself); by "associated", we mean any mappings which are connected to the original FieldMap by having a matching source or destination, including transitive associations. |
|
String |
getClassName()
|
|
String |
getClassSimpleName()
|
|
|
getInstance()
|
|
MappingContext |
getMappingContext()
|
|
String |
getPackageName()
|
|
protected StringBuilder |
getSourceBuilder()
|
|
Class<?> |
getSuperClass()
|
|
boolean |
isDebugEnabled()
|
|
static String |
join(List<?> list,
String separator)
Join the items in the list together in a String, separated by the provided separator |
|
String |
mapAggregateFields()
|
|
String |
mapFields(FieldMap fieldMap,
VariableRef sourceProperty,
VariableRef destinationProperty,
Type<?> destinationType,
StringBuilder logDetails)
Generate the code necessary to process the provided FieldMap. |
|
String |
newObject(VariableRef source,
Type<?> destinationType)
|
|
String |
newObjectFromMapper(Type<?> sourceType,
Type<?> destinationType)
|
|
String |
newObjectFromMapper(VariableRef source,
Type<?> destinationType)
Generates a code snippet to generate a new instance of the destination type from a mapper |
|
boolean |
shouldMapNulls()
|
|
static String |
statement(String str,
Object... args)
Appends the provided string as a source code statement, ending it with a statement terminator as appropriate. |
|
String |
toSourceFile()
|
|
String |
usedConverter(Converter<?,?> converter)
|
|
String |
usedMapperFacadeNewObjectCall(VariableRef source,
VariableRef destination)
|
|
String |
usedType(Type<?> type)
|
|
String |
usedType(VariableRef r)
Generate usedType array index code for the provided variable |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SourceCodeContext(String baseClassName,
Class<?> superClass,
MappingContext mappingContext,
StringBuilder logDetails)
baseClassName - superClass - compilerStrategy - propertyResolver - mapperFactory - logDetails - | Method Detail |
|---|
public boolean isDebugEnabled()
public void debug(String msg)
protected StringBuilder getSourceBuilder()
public Class<?> getSuperClass()
public String getClassSimpleName()
public String getPackageName()
public String getClassName()
public boolean shouldMapNulls()
public MappingContext getMappingContext()
public void addMethod(String methodSource)
methodSource - public void addField(String fieldSource)
fieldSource - the source from which to compile the fieldpublic String toSourceFile()
protected Class<?> compileClass()
throws CompilerStrategy.SourceCodeGenerationException
javassist.CannotCompileException
IOException
CompilerStrategy.SourceCodeGenerationException
public <T extends GeneratedObjectBase> T getInstance()
throws CompilerStrategy.SourceCodeGenerationException,
InstantiationException,
IllegalAccessException
javassist.CannotCompileException
IOException
InstantiationException
IllegalAccessException
CompilerStrategy.SourceCodeGenerationExceptionpublic String usedConverter(Converter<?,?> converter)
public String usedType(Type<?> type)
public String callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression,
String destExpression)
public String callMapper(Type<?> sourceType,
Type<?> destinationType,
String sourceExpression)
public String callMapper(VariableRef source,
VariableRef destination)
public String callMapper(VariableRef source,
Type<?> destination)
public String usedMapperFacadeNewObjectCall(VariableRef source,
VariableRef destination)
public String newObjectFromMapper(Type<?> sourceType,
Type<?> destinationType)
public String newObjectFromMapper(VariableRef source,
Type<?> destinationType)
source - destinationType -
public String usedType(VariableRef r)
r -
public String newObject(VariableRef source,
Type<?> destinationType)
source - destinationType -
public String assureInstanceExists(VariableRef propertyRef,
VariableRef source)
propertyRef - the property or variable reference on which to check for an
instancesource -
this SourceCodeBuilder
public static String statement(String str,
Object... args)
str - args -
this SourceCodeBuilder
public static void append(StringBuilder out,
String... statements)
out - statements -
public static String join(List<?> list,
String separator)
list - separator -
public static VariableRef entrySetRef(VariableRef s)
s - the Map type variable ref
public String currentElementComparator(Node source,
Node dest,
Node.NodeList srcNodes,
Node.NodeList destNodes)
source - dest - srcNodes - destNodes -
public Set<FieldMap> getAssociatedMappings(Collection<FieldMap> fieldMaps,
FieldMap map)
fieldMaps - the set of all field mapsmap - the field map from which to start searching for reference
public boolean aggregateSpecsApply(FieldMap fieldMap)
fieldMap -
public String mapAggregateFields()
public String mapFields(FieldMap fieldMap,
VariableRef sourceProperty,
VariableRef destinationProperty,
Type<?> destinationType,
StringBuilder logDetails)
fieldMap - the FieldMap describing fields to be mappedsourceProperty - a variable reference to the source propertydestinationProperty - a variable reference to the destination propertydestinationType - the destination's typelogDetails - a StringBuilder to contain the debug output
this CodeSourceBuilder
public String compareFields(FieldMap fieldMap,
VariableRef sourceProperty,
VariableRef destinationProperty,
Type<?> destinationType,
StringBuilder logDetails)
fieldMap - sourceProperty - destinationProperty - destinationType - logDetails -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||