Package org.jibeframework.core.ui.wrapper

Source Code of org.jibeframework.core.ui.wrapper.UIConfig

package org.jibeframework.core.ui.wrapper;

import groovy.lang.GroovyObject;

import java.util.List;
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.jibeframework.core.ui.wrapper.factory.ListWrapperFactory;
import org.jibeframework.core.ui.wrapper.factory.MapWrapperFactory;
import org.springframework.beans.factory.annotation.Autowired;

@JsonSerialize(using = WrapperSerializer.class)
public class UIConfig extends Wrapper {

  @Autowired
  private ConfigService configService;

  private Context context = Context.getCurrentContext();
  private String configId;
  private MapWrapperFactory mapWrapperFactory = new MapWrapperFactory();
  private ListWrapperFactory listWrapperFactory = new ListWrapperFactory();

  public UIConfig(String configId) {
    super(null, null);
    this.configId = configId;
    ManagedObjectFactoryImpl.injectDeps(this);

  }

  protected UIConfig(String scope, String modelScope, String configId) {
    super(scope, modelScope);
    this.configId = configId;
    ManagedObjectFactoryImpl.injectDeps(this);

  }

  @SuppressWarnings("unchecked")
  protected Object getValue() {
    Object config = null;
    if (context.containsViewBean(configId)) {
      GroovyObject bean = (GroovyObject) context.getViewBean(configId);
      config = bean.invokeMethod("getComponentDefinition", null);
    } else {
      config = configService.getConfig(configId);
    }
    if (config instanceof Map) {
      return mapWrapperFactory.createWrapper(getScope(), getModelScope(), (Map<String, Object>) config);
    } else if (config instanceof List) {
      return listWrapperFactory.createWrapper(getScope(), getModelScope(), (List<Object>) config);
    } else {
      throw new IllegalStateException("Has to be instance of Map or List");
    }
  }

}
TOP

Related Classes of org.jibeframework.core.ui.wrapper.UIConfig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.