com.octo.android.robospice.persistence
Class ObjectPersisterFactory

java.lang.Object
  extended by com.octo.android.robospice.persistence.ObjectPersisterFactory
All Implemented Interfaces:
Persister
Direct Known Subclasses:
InDatabaseObjectPersisterFactory, InFileObjectPersisterFactory

public abstract class ObjectPersisterFactory
extends Object
implements Persister

Super class of all factories of ObjectPersisterFactory classes. They are responsible for creating ObjectPersister classes that will save/load data for a given class. Such factories are useful because we sometimes need to create ObjectPersister dynamically. For instance when we serialize items as JSON, we need to create a new ObjectPersister class for every class of items saved/loaded into cache. A unique ObjectPersister would not be able to strongly type the load/save method and we would have to cast the result of both operations, leading to less robust and less convenient code.

Author:
sni

Constructor Summary
ObjectPersisterFactory(android.app.Application application)
          Creates an ObjectPersisterFactory given an Android application.
ObjectPersisterFactory(android.app.Application application, List<Class<?>> listHandledClasses)
          Creates an ObjectPersisterFactory given an Android application and a list of handled classes.
 
Method Summary
 boolean canHandleClass(Class<?> clazz)
          Wether or not this bus element can persist/unpersist objects of the given class clazz.
abstract
<DATA> ObjectPersister<DATA>
createObjectPersister(Class<DATA> clazz)
          Creates a ObjectPersister for a given class.
protected  android.app.Application getApplication()
           
protected  List<Class<?>> getListHandledClasses()
          Return the list of classes persisted by this factory.
 boolean isAsyncSaveEnabled()
          Indicates whether this ObjectPersisterFactory will set the ObjectPersister instances it produces to save data asynchronously or not.
 void setAsyncSaveEnabled(boolean isAsyncSaveEnabled)
          Set whether this ObjectPersisterFactory will set the ObjectPersister instances it produces to save data asynchronously or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPersisterFactory

public ObjectPersisterFactory(android.app.Application application)
Creates an ObjectPersisterFactory given an Android application. As no list of handled classes is specified, it will act has if it can handle all classes.

Parameters:
application - the android context needed to access android file system or databases to store.

ObjectPersisterFactory

public ObjectPersisterFactory(android.app.Application application,
                              List<Class<?>> listHandledClasses)
Creates an ObjectPersisterFactory given an Android application and a list of handled classes.

Parameters:
application - the android context needed to access android file system or databases to store.
listHandledClasses - the list of classes that is handled by the factory. The factory will try to produce an ObjectPersister for each element of the list.
Method Detail

getApplication

protected final android.app.Application getApplication()

canHandleClass

public boolean canHandleClass(Class<?> clazz)
Wether or not this bus element can persist/unpersist objects of the given class clazz.

Specified by:
canHandleClass in interface Persister
Parameters:
clazz - the class of objets we are looking forward to persist.
Returns:
true if this bus element can persist/unpersist objects of the given class clazz. False otherwise.

createObjectPersister

public abstract <DATA> ObjectPersister<DATA> createObjectPersister(Class<DATA> clazz)
                                                     throws CacheCreationException
Creates a ObjectPersister for a given class.

Parameters:
clazz - the class of the items that need to be saved/loaded from cache.
Returns:
a ObjectPersister able to load/save instances of class clazz.
Throws:
CacheCreationException - if the persist fails to create its cache (it may also create it later, but it is suggested to fail as fast as possible).

setAsyncSaveEnabled

public void setAsyncSaveEnabled(boolean isAsyncSaveEnabled)
Set whether this ObjectPersisterFactory will set the ObjectPersister instances it produces to save data asynchronously or not.

Parameters:
isAsyncSaveEnabled - whether or not data will be saved asynchronously by ObjectPersister instances produced by this factory.

isAsyncSaveEnabled

public boolean isAsyncSaveEnabled()
Indicates whether this ObjectPersisterFactory will set the ObjectPersister instances it produces to save data asynchronously or not.

Returns:
true if the ObjectPersister instances it produces to save data asynchronously. False otherwise.

getListHandledClasses

protected List<Class<?>> getListHandledClasses()
Return the list of classes persisted by this factory.

Returns:
the list of classes persisted by this factory.


Copyright © 2012-2014. All Rights Reserved.