xapi.model.X_Model Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xapi-gwt Show documentation
Show all versions of xapi-gwt Show documentation
This module exists solely to package all other gwt modules into a single
uber jar. This makes deploying to non-mavenized targets much easier.
Of course, you would be wise to inherit your dependencies individually;
the uber jar is intended for projects like collide,
which have complex configuration, and adding many jars would be a pain.
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);
}
}