org.persvr.datasource
Class AbstractJsonSource

java.lang.Object
  extended by org.persvr.remote.JsonReceiver
      extended by org.persvr.datasource.AbstractJsonSource
All Implemented Interfaces:
DataSource, ListDataSource
Direct Known Subclasses:
HttpJsonSource, LocalJsonFileSource

public abstract class AbstractJsonSource
extends JsonReceiver
implements DataSource, ListDataSource


Nested Class Summary
protected  class AbstractJsonSource.RootAndResolved
           
 
Nested classes/interfaces inherited from class org.persvr.remote.JsonReceiver
JsonReceiver.UpdateInfo
 
Field Summary
 long defaultCacheLength
           
 
Fields inherited from class org.persvr.remote.JsonReceiver
FUNCTION_CODE_KEY, NOT_READY_FIELD, path
 
Constructor Summary
AbstractJsonSource()
           
 
Method Summary
 void abortTransaction()
           
 void commitTransaction()
           
protected  java.lang.Object convertJsonToJavaScript(java.lang.Object value, java.lang.String id)
           
 java.lang.String getId()
          Gets a string identification of the data source
protected abstract  java.lang.Object getJson(java.lang.String resourceName)
          Gets the JSON string for a particular object id.
protected  AbstractJsonSource.RootAndResolved getMap(java.lang.String objectId)
           
protected  java.lang.String getPathSeparator()
           
protected static java.lang.String getResourceAsString(java.io.InputStream is)
           
protected  void handleNewObject(java.lang.Object value, java.lang.String key, java.lang.String parentId)
           
 boolean hiddenId(java.lang.String id)
           
protected  void makeDirty(java.lang.String objectId)
           
protected  void mapJson(PersistableInitializer initializer, java.lang.Object object, java.lang.String objectId)
           
 void mapObject(PersistableInitializer initializer, java.lang.String objectId)
          This is called when an object is being activated to retrieve the persisted data for a given object
 void mapSchema(PersistableInitializer initializer)
           
protected abstract  void newJson(java.lang.String json)
           
 void recordList(java.lang.String objectId, java.util.List<? extends java.lang.Object> values)
           
 NewObjectPersister recordNewObject(Persistable object)
           
 void recordPropertyAddition(java.lang.String objectId, java.lang.String name, java.lang.Object value, int attributes)
           
 void recordPropertyChange(java.lang.String objectId, java.lang.String name, java.lang.Object value, int attributes)
           
 void recordPropertyRemoval(java.lang.String objectId, java.lang.String name)
           
protected  java.lang.String serialize(Persistable target)
           
 void setId(java.lang.String id)
          Sets a string identification of the data source
protected abstract  void setJson(java.lang.String resourceName, java.lang.String json)
           
 void startTransaction()
           
 
Methods inherited from class org.persvr.remote.JsonReceiver
convertJsponStringToObject, convertParsedToObject, createInitialObject, getPath, handleRPC, idFromJSPONObject, idOrValueFromJSON, listFromJSPONArray, parseJsponString, replaceList, setPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.persvr.datasource.DataSource
getFieldValue, initParameters, mapQuery
 

Field Detail

defaultCacheLength

public long defaultCacheLength
Constructor Detail

AbstractJsonSource

public AbstractJsonSource()
Method Detail

getJson

protected abstract java.lang.Object getJson(java.lang.String resourceName)
                                     throws java.lang.Exception
Gets the JSON string for a particular object id. This is called when an object needs to be initialized, and this AbstractJsonSource/JsonReceiver will handle the conversion of the JSON string to an object

Parameters:
objectId -
Returns:
the JSON string
Throws:
java.lang.Exception

getId

public java.lang.String getId()
Description copied from interface: DataSource
Gets a string identification of the data source

Specified by:
getId in interface DataSource
Returns:

setId

public void setId(java.lang.String id)
Description copied from interface: DataSource
Sets a string identification of the data source

Specified by:
setId in interface DataSource

mapSchema

public void mapSchema(PersistableInitializer initializer)
               throws java.lang.Exception
Throws:
java.lang.Exception

getPathSeparator

protected java.lang.String getPathSeparator()

getMap

protected AbstractJsonSource.RootAndResolved getMap(java.lang.String objectId)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

convertJsonToJavaScript

protected java.lang.Object convertJsonToJavaScript(java.lang.Object value,
                                                   java.lang.String id)

mapObject

public void mapObject(PersistableInitializer initializer,
                      java.lang.String objectId)
               throws java.lang.Exception
Description copied from interface: DataSource
This is called when an object is being activated to retrieve the persisted data for a given object

Specified by:
mapObject in interface DataSource
Throws:
java.lang.Exception

mapJson

protected void mapJson(PersistableInitializer initializer,
                       java.lang.Object object,
                       java.lang.String objectId)

getResourceAsString

protected static java.lang.String getResourceAsString(java.io.InputStream is)
                                               throws java.io.IOException
Throws:
java.io.IOException

abortTransaction

public void abortTransaction()
                      throws java.lang.Exception
Throws:
java.lang.Exception

setJson

protected abstract void setJson(java.lang.String resourceName,
                                java.lang.String json)
                         throws java.lang.Exception
Throws:
java.lang.Exception

newJson

protected abstract void newJson(java.lang.String json)
                         throws java.lang.Exception
Throws:
java.lang.Exception

commitTransaction

public void commitTransaction()
                       throws java.lang.Exception
Throws:
java.lang.Exception

recordNewObject

public NewObjectPersister recordNewObject(Persistable object)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

serialize

protected java.lang.String serialize(Persistable target)

makeDirty

protected void makeDirty(java.lang.String objectId)

startTransaction

public void startTransaction()
                      throws java.lang.Exception
Throws:
java.lang.Exception

hiddenId

public boolean hiddenId(java.lang.String id)
Specified by:
hiddenId in interface DataSource

recordList

public void recordList(java.lang.String objectId,
                       java.util.List<? extends java.lang.Object> values)
                throws java.lang.Exception
Specified by:
recordList in interface ListDataSource
Throws:
java.lang.Exception

recordPropertyAddition

public void recordPropertyAddition(java.lang.String objectId,
                                   java.lang.String name,
                                   java.lang.Object value,
                                   int attributes)
                            throws java.lang.Exception
Throws:
java.lang.Exception

recordPropertyChange

public void recordPropertyChange(java.lang.String objectId,
                                 java.lang.String name,
                                 java.lang.Object value,
                                 int attributes)
                          throws java.lang.Exception
Throws:
java.lang.Exception

recordPropertyRemoval

public void recordPropertyRemoval(java.lang.String objectId,
                                  java.lang.String name)
                           throws java.lang.Exception
Throws:
java.lang.Exception

handleNewObject

protected void handleNewObject(java.lang.Object value,
                               java.lang.String key,
                               java.lang.String parentId)