com.stackmob.sdk.model
Class StackMobModel

java.lang.Object
  extended by com.stackmob.sdk.model.StackMobModel
Direct Known Subclasses:
StackMobUser

public abstract class StackMobModel
extends Object


Nested Class Summary
static class StackMobModel.DateAsNumberTypeAdapter
           
 
Constructor Summary
StackMobModel(Class<? extends StackMobModel> actualClass)
           
StackMobModel(String id, Class<? extends StackMobModel> actualClass)
           
 
Method Summary
 void destroy()
           
 void destroy(StackMobCallback callback)
           
 void fetch()
           
 void fetch(StackMobCallback callback)
           
 void fetchWithDepth(int depth, StackMobCallback callback)
           
protected  void fillFieldFromJson(String jsonName, com.google.gson.JsonElement json)
           
protected  void fillFromJson(com.google.gson.JsonElement json)
           
protected  void fillFromJson(com.google.gson.JsonElement json, List<String> selection)
           
 void fillFromJson(String jsonString)
           
protected static StackMobModel getExistingModel(Collection<? extends StackMobModel> oldList, com.google.gson.JsonElement json)
          Finds a model with the same id as the json
protected  Collection<StackMobModel> getFieldAsCollection(Field field)
          Turns a field which is either an Array or Collection of StackMobModels and turns in into a collection
 String getID()
           
 String getIDFieldName()
           
protected  String getSchemaName()
          Determines the schema connected to this class on the server.
 boolean hasData()
           
protected  boolean hasSameID(com.google.gson.JsonElement json)
          Checks if the current object has the same id as this json
 void load(int depth)
           
 void save()
           
 void save(StackMobCallback callback)
           
 void saveWithDepth(int depth)
           
 void saveWithDepth(int depth, StackMobCallback callback)
           
protected  void setActualClass(Class<? extends StackMobModel> actualClass)
           
protected  void setFieldFromList(Field field, List<? extends StackMobModel> list, Class<? extends StackMobModel> modelClass)
          Sets a field which is either an Array or Collection of StackMobModels using a list
protected  void setID(com.google.gson.JsonElement json)
           
 void setID(String id)
           
 String toJson()
           
 String toJsonWithDepth(int depth)
           
protected  String toJsonWithDepth(int depth, RelationMapping mapping)
          Converts the object to JSON turning all Models into their ids
protected static List<StackMobModel> updateModelListFromJson(com.google.gson.JsonArray array, Collection<? extends StackMobModel> existingModels, Class<? extends StackMobModel> modelClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackMobModel

public StackMobModel(String id,
                     Class<? extends StackMobModel> actualClass)

StackMobModel

public StackMobModel(Class<? extends StackMobModel> actualClass)
Method Detail

setID

public void setID(String id)

getID

public String getID()

setActualClass

protected void setActualClass(Class<? extends StackMobModel> actualClass)

getSchemaName

protected String getSchemaName()
Determines the schema connected to this class on the server. By default it's the name of the class in lower case. Override in subclasses to change that. Must be 3-25 alphanumeric characters.

Returns:
the schema name

getIDFieldName

public String getIDFieldName()

hasData

public boolean hasData()

fillFieldFromJson

protected void fillFieldFromJson(String jsonName,
                                 com.google.gson.JsonElement json)
                          throws StackMobException
Throws:
StackMobException

getFieldAsCollection

protected Collection<StackMobModel> getFieldAsCollection(Field field)
                                                  throws IllegalAccessException
Turns a field which is either an Array or Collection of StackMobModels and turns in into a collection

Throws:
IllegalAccessException

setFieldFromList

protected void setFieldFromList(Field field,
                                List<? extends StackMobModel> list,
                                Class<? extends StackMobModel> modelClass)
                         throws IllegalAccessException,
                                InstantiationException
Sets a field which is either an Array or Collection of StackMobModels using a list

Throws:
IllegalAccessException
InstantiationException

updateModelListFromJson

protected static List<StackMobModel> updateModelListFromJson(com.google.gson.JsonArray array,
                                                             Collection<? extends StackMobModel> existingModels,
                                                             Class<? extends StackMobModel> modelClass)
                                                      throws IllegalAccessException,
                                                             InstantiationException,
                                                             StackMobException
Throws:
IllegalAccessException
InstantiationException
StackMobException

getExistingModel

protected static StackMobModel getExistingModel(Collection<? extends StackMobModel> oldList,
                                                com.google.gson.JsonElement json)
Finds a model with the same id as the json

Parameters:
oldList - The data in the object already
json -
Returns:

fillFromJson

public void fillFromJson(String jsonString)
                  throws StackMobException
Throws:
StackMobException

fillFromJson

protected void fillFromJson(com.google.gson.JsonElement json)
                     throws StackMobException
Throws:
StackMobException

fillFromJson

protected void fillFromJson(com.google.gson.JsonElement json,
                            List<String> selection)
                     throws StackMobException
Throws:
StackMobException

hasSameID

protected boolean hasSameID(com.google.gson.JsonElement json)
Checks if the current object has the same id as this json

Parameters:
json -
Returns:

setID

protected void setID(com.google.gson.JsonElement json)

toJson

public String toJson()

toJsonWithDepth

public String toJsonWithDepth(int depth)

toJsonWithDepth

protected String toJsonWithDepth(int depth,
                                 RelationMapping mapping)
Converts the object to JSON turning all Models into their ids

Returns:
the json representation of this model

fetch

public void fetch()

load

public void load(int depth)

fetch

public void fetch(StackMobCallback callback)

fetchWithDepth

public void fetchWithDepth(int depth,
                           StackMobCallback callback)

save

public void save()

saveWithDepth

public void saveWithDepth(int depth)

save

public void save(StackMobCallback callback)

saveWithDepth

public void saveWithDepth(int depth,
                          StackMobCallback callback)

destroy

public void destroy()

destroy

public void destroy(StackMobCallback callback)


Copyright © 2012 StackMob. All Rights Reserved.