public Collection<AObjectMappingDef> getCompiledObjectMappingDefs() {
return compiledObjectMappingDefs;
}
AObjectMappingDef compileObjectMappingDef(ACompilableObjectMappingDef orig) throws Exception {
final SimpleCompiler compiler = new SimpleCompiler();
compiler.setDebuggingInformation(true, true, true);
final ACodeBuilderForMappingDef builder = new ACodeBuilderForMappingDef(AObjectMappingDef.class.getName(), logger);
final ACodeSnippet codeForMap = orig.javaCodeForMap(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_TARGET_SNIPPET, compCtx);
final ACodeSnippet codeForDiff = orig.javaCodeForDiff(AMappingDefCompiler.OBJECT_MAPPING_SOURCE_OLD_SNIPPET, AMappingDefCompiler.OBJECT_MAPPING_SOURCE_NEW_SNIPPET, compCtx);
builder.addInjectedFields(codeForMap. getInjectedFields());
builder.addInjectedFields(codeForDiff.getInjectedFields());
// only raw types in the signatures because neither Janino nor Javassist support generics
builder.addMethod("public Object map(Object source, Object targetRaw, " +
AQualifiedSourceAndTargetType.class.getName() + " types, " +
AMapperWorker.class.getName() + " worker, " +
AMap.class.getName() + " context, " +
APath.class.getName() + " path) throws Exception {",
codeForMap.getCode());
builder.addMethod("public void diff(" +
ADiffBuilder.class.getName() + " diff, Object sourceOld, Object sourceNew, " +
AQualifiedSourceAndTargetType.class.getName() + " types, " +
AMapperDiffWorker.class.getName() + " worker, " +
AMap.class.getName() + " contextOld, " +
AMap.class.getName() + " contextNew, " +
APath.class.getName() + " path, boolean isDerived) throws Exception {",
codeForDiff.getCode());
compiler.cook(builder.build());
final Class omCls = compiler.getClassLoader().loadClass(builder.fqn);
// this assumes only one constructor. Seems a somewhat brittle, but no reason comes to mind why there should
// every be more than one
final Constructor ctor = omCls.getConstructors()[0];