package org.jibeframework.core.ui.wrapper;
import groovy.lang.GroovyObject;
import java.util.LinkedHashMap;
import java.util.Map;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.jibeframework.core.Context;
import org.jibeframework.core.service.ConfigService;
import org.jibeframework.core.service.impl.ManagedObjectFactoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
@JsonSerialize(using = WrapperSerializer.class)
public class ExtendedMapWrapper extends MapWrapper {
private String extendedId;
@Autowired
private ConfigService configService;
public ExtendedMapWrapper(String extendedId, MapWrapper wrapper) {
super(wrapper.getScope(), wrapper.getModelScope(), wrapper.getConfig());
this.extendedId = extendedId;
ManagedObjectFactoryImpl.injectDeps(this);
}
@SuppressWarnings("unchecked")
@Override
protected Object getValue() {
Object config = null;
Context context = Context.getCurrentContext();
if (context.containsViewBean(extendedId)) {
GroovyObject bean = (GroovyObject) context.getViewBean(extendedId);
config = bean.invokeMethod("getComponentDefinition", null);
} else {
config = configService.getConfig(extendedId);
}
if (Map.class.isAssignableFrom(config.getClass())) {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.putAll((Map<String, Object>) config);
result.putAll(this.getConfig());
setConfig(result);
} else {
throw new IllegalStateException("Extended config element has to be instance of Map: " + extendedId);
}
return super.getValue();
}
}