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

xapi.model.X_Model Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.model;

import javax.inject.Provider;

import xapi.annotation.gwt.MagicMethod;
import xapi.inject.X_Inject;
import xapi.model.api.Model;
import xapi.model.api.ModelKey;
import xapi.model.api.ModelManifest;
import xapi.model.service.ModelCache;
import xapi.model.service.ModelService;
import xapi.source.impl.StringCharIterator;
import xapi.util.api.SuccessHandler;

public class X_Model {

  private X_Model() {}

  private static final Provider cache = X_Inject.singletonLazy(ModelCache.class);
  private static final Provider service = X_Inject.singletonLazy(ModelService.class);

  public static ModelCache cache(){
    return cache.get();
  }

  @MagicMethod(doNotVisit=true,
      documentation="This magic method generates the model class and all of its dependent models, "
        + "then re-routes to the same provider as X_Inject.instance()")
  public static  M create(final Class modelClass) {
    return service.get().create(modelClass);
  }

  @MagicMethod(doNotVisit=true,
      documentation="This magic method generates the model class and all of its dependent models")
  public static  String register(final Class modelClass) {
    return service.get().register(modelClass);
  }

  public static  void persist(final M model, final SuccessHandler callback) {
    // TODO: return a Promises-like object
    service.get().persist(model, callback);
  }

  public static  void load(final Class modelClass, final ModelKey modelKey, final SuccessHandler callback) {
    // TODO: return a Promises-like object
    service.get().load(modelClass, modelKey, callback);
  }

  public static  String serialize(final Class cls, final M model) {
    return service.get().serialize(cls, model).toString();
  }

  public static  M deserialize(final Class cls, final String model) {
    return service.get().deserialize(cls, new StringCharIterator(model));
  }

  public static  String serialize(final ModelManifest manifest, final M model) {
    return service.get().serialize(manifest, model).toString();
  }

  public static  M deserialize(final ModelManifest manifest, final String model) {
    return service.get().deserialize(manifest, new StringCharIterator(model));
  }

  public static ModelService getService() {
    return service.get();
  }

  public static String keyToString(final ModelKey key) {
    return service.get().keyToString(key);
  }

  public static ModelKey keyFromString(final String key) {
    return service.get().keyFromString(key);
  }

  public static ModelKey newKey(final String kind) {
    return service.get().newKey("", kind);
  }

  public static ModelKey newKey(final String namespace, final String kind) {
    return service.get().newKey(namespace, kind);
  }

  public static ModelKey newKey(final String namespace, final String kind, final String id) {
    return service.get().newKey(namespace, kind, id);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy