*/
public class CompoundControllerDefFactory extends DefFactoryImpl<ControllerDef> {
@Override
public ControllerDef getDef(DefDescriptor<ControllerDef> descriptor) throws QuickFixException {
Builder builder = new Builder();
builder.setDescriptor(descriptor);
builder.setLocation(descriptor.getQualifiedName(), -1);
DefDescriptor<ComponentDef> compDesc = DefDescriptorImpl.getAssociateDescriptor(descriptor, ComponentDef.class,
DefDescriptor.MARKUP_PREFIX);
BaseComponentDef componentDef = null;
if (compDesc.exists()) {
componentDef = compDesc.getDef();
} else {
DefDescriptor<ApplicationDef> appDesc = DefDescriptorImpl.getAssociateDescriptor(descriptor,
ApplicationDef.class, DefDescriptor.MARKUP_PREFIX);
componentDef = appDesc.getDef();
}
if (componentDef == null) {
DefDescriptor<ComponentDef> layoutDesc = DefDescriptorImpl.getAssociateDescriptor(descriptor,
ComponentDef.class, "layout");
componentDef = layoutDesc.getDef();
}
Map<String, ActionDef> flattened = Maps.newHashMap();
for (DefDescriptor<ControllerDef> delegate : componentDef.getControllerDefDescriptors()) {
ControllerDef c = delegate.getDef();
for (Map.Entry<String, ? extends ActionDef> e : c.getActionDefs().entrySet()) {
ActionDef a = flattened.get(e.getKey());
if (a != null) {
// TODO: server and client actions by same name, map needs
// key on action type
} else {
flattened.put(e.getKey(), e.getValue());
}
}
}
builder.setActionDefs(flattened);
return builder.build();
}