if (context.canMarshal(toMap.getFullyQualifiedName())) {
if (gwtTarget) {
BuildMetaClass arrayMarshaller = MarshallerGeneratorFactory.createArrayMarshallerClass(type);
if (!containsInnerClass(classStructureBuilder, arrayMarshaller)) {
classStructureBuilder.declaresInnerClass(new InnerClass(arrayMarshaller));
}
Statement deferred = context.getArrayMarshallerCallback().deferred(type, arrayMarshaller);
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod,
deferred);
constructorParameters[parmIndex] =
Stmt.loadVariable(MarshallingGenUtil.getVarName(type)).invoke("demarshall",
extractJSONObjectProperty(mapping.getKey(), EJObject.class), Stmt.loadVariable("a1"));
}
else {
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod);
constructorParameters[parmIndex] = context.getArrayMarshallerCallback()
.demarshall(type, extractJSONObjectProperty(mapping.getKey(), EJObject.class));
}
}
else {
throw new MarshallingException("Encountered non-marshallable type " + toMap +
" while building a marshaller for " + mappingDefinition.getMappingClass());
}
}
else {
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod);
if (context.canMarshal(type.getFullyQualifiedName())) {
Statement s = maybeAddAssumedTypes(builder,
"c" + parmIndex,
mapping, fieldDemarshall(mapping, EJObject.class));
constructorParameters[parmIndex] = s;
}
else {
throw new MarshallingException("Encountered non-marshallable type " + type +
" while building a marshaller for " + mappingDefinition.getMappingClass());
}
}
}
if (instantiationMapping instanceof ConstructorMapping) {
final ConstructorMapping mapping = (ConstructorMapping) instantiationMapping;
final MetaConstructor constructor = mapping.getMember();
if (constructor.isPublic()) {
builder
.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.newObject(toMap, (Object[]) constructorParameters)));
}
else {
PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", classStructureBuilder,
constructor);
builder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.invokeStatic(
classStructureBuilder.getClassDefinition(),
PrivateAccessUtil.getPrivateMethodName(constructor),
(Object[]) constructorParameters)));
}
}
else if (instantiationMapping instanceof FactoryMapping) {
builder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.invokeStatic(toMap, ((FactoryMapping) instantiationMapping).getMember().getName(),
(Object[]) constructorParameters)));
}
}
else {
// use default constructor
builder._(
Stmt.declareVariable(toMap).named("entity").initializeWith(
Stmt.nestedCall(Stmt.newObject(toMap))));
}
builder._(loadVariable("a1").invoke("recordObject",
loadVariable("objId"), loadVariable("entity")));
}
/**
*
* FIELD BINDINGS
*
*/
for (final MemberMapping memberMapping : mappingDefinition.getMemberMappings()) {
if (!memberMapping.canWrite())
continue;
if (memberMapping.getTargetType().isConcrete() && !context.isRendered(memberMapping.getTargetType())) {
context.getMarshallerGeneratorFactory().addMarshaller(memberMapping.getTargetType());
}
final Statement bindingStatement;
final Statement val;
context.getMarshallerGeneratorFactory().addOrMarkMarshallerUnlazy(
memberMapping.getType().getOuterComponentType());
BlockBuilder<?> lazyInitMethod = (needsLazyInit(memberMapping.getType())) ? initMethod : null;
if (memberMapping.getType().isArray()) {
if (gwtTarget) {
BuildMetaClass arrayMarshaller =
MarshallerGeneratorFactory.createArrayMarshallerClass(memberMapping.getType().asBoxed());
if (!containsInnerClass(classStructureBuilder, arrayMarshaller)) {
classStructureBuilder.declaresInnerClass(new InnerClass(arrayMarshaller));
}
Statement deferred =
context.getArrayMarshallerCallback().deferred(memberMapping.getType().asBoxed(), arrayMarshaller);
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, memberMapping.getType()
.asBoxed(), lazyInitMethod, deferred);