All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.ennwifi.webframe.ui.client.data.MetaDataProvider Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package cn.ennwifi.webframe.ui.client.data;

import java.util.ArrayList;
import java.util.List;

import cn.ennwifi.webframe.ui.client.rpc.WebFrameProxy;
import cn.ennwifi.webframe.ui.shared.repository.S_METAObj;
import cn.mapway.ui.client.mvc.ObservableImpl;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 元数据提供器
 *
 * @author zhangjianshe
 */
public class MetaDataProvider extends ObservableImpl {

  private static List mData;
  private static MetaDataProvider INSANCE;
  private AsyncCallback> onData = new AsyncCallback>() {

    @Override
    public void onSuccess(List result) {
      loadding = false;

      mData = result;
      notifyObservers(mData);
    }

    @Override
    public void onFailure(Throwable caught) {
      loadding = false;
      GWT.log(caught.getMessage());
    }
  };
  private static boolean loadding = false;

    /**
     * Instantiates a new Meta data provider.
     */
    protected MetaDataProvider() {
    mData = new ArrayList();
  }

    /**
     * 获取唯一实例
     *
     * @return meta data provider
     */
    public static MetaDataProvider get() {
    if (INSANCE == null) {
      INSANCE = new MetaDataProvider();
      INSANCE.reload(true);
    }
    return INSANCE;
  }

    /**
     * 重新加载数据
     *
     * @param force the force
     */
    public void reload(boolean force) {
    if (loadding) {
      return;
    }
    if (force || mData.size() == 0) {
      loadding = true;
      WebFrameProxy.get().getMetaData("", true, onData);
    } else {
      notifyObservers(mData);
    }
  }

    /**
     * 根据路径找到元数据
     *
     * @param path the path
     * @return list
     */
    public List findByCatalog(String path) {
    List d = new ArrayList();
    for (S_METAObj m : mData) {
      if (m.getCatalog().equals(path)) {
        d.add(m);
      }
    }
    return d;
  }

    /**
     * 找到多个code 对应的元数据信息
     *
     * @param codes the codes
     * @return list
     */
    public List findByCodes(String[] codes) {
    List ds = new ArrayList();
    for (int i = 0; i < codes.length; i++) {
      S_METAObj d = findByCode(codes[i]);
      if (d != null) {
        ds.add(d);
      }
    }
    return ds;
  }

    /**
     * 转换Code到文本
     *
     * @param codes the codes
     * @return list
     */
    public List tanslate(String codes) {
    ArrayList mCodes = new ArrayList();
    if (codes != null) {
      String[] codelist = codes.split(",");
      for (int i = 0; i < codelist.length; i++) {
        String code = codelist[i];
        code = code.trim();
        if (code != null && code.length() > 0) {
          mCodes.add(findByCode(code));
        }
      }
    }
    return mCodes;
  }

    /**
     * 根据代码找到元数据
     *
     * @param code the code
     * @return s meta obj
     */
    public S_METAObj findByCode(String code) {
    if (code == null || code.length() == 0) {
      return null;
    }
    for (S_METAObj m : mData) {
      if (m.getCode().equals(code))
        return m;
    }
    return null;
  }

    /**
     * 获取所有元数据
     *
     * @return data
     */
    public List getData() {
    return mData;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy