C
- the type of the data used to configureM
- the type of data being returned by the loaderpublic class Loader<C,M> extends Object implements LoaderHandler.HasLoaderHandlers<C,M>
DataProxy
and DataReader
to help
perform the load operations. The DataProxy
is responsible for
obtaining the remote data. The DataReader
is responsible for
"processing" the remote data and converting the data to the expected format.
Constructor and Description |
---|
Loader(DataProxy<C,M> proxy)
Creates a new base loader instance.
|
Loader(DataProxy<C,T> proxy,
DataReader<M,T> reader)
Creates a new loader with the given proxy and reader.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addBeforeLoadHandler(BeforeLoadEvent.BeforeLoadHandler<C> handler)
Adds a
BeforeLoadEvent handler. |
protected <H extends EventHandler> |
addHandler(<any> type,
H handler)
Adds an event handler to the loader.
|
HandlerRegistration |
addLoaderHandler(LoaderHandler<C,M> handler)
Adds a
LoadEvent handler. |
HandlerRegistration |
addLoadExceptionHandler(LoadExceptionEvent.LoadExceptionHandler<C> handler)
Adds a
LoadExceptionEvent handler. |
HandlerRegistration |
addLoadHandler(LoadHandler<C,M> handler)
Adds a
LoadEvent handler. |
protected boolean |
fireEvent(<any> event)
Fires the given event.
|
C |
getLastLoadConfig()
Returns the last load config.
|
DataProxy<?,?> |
getProxy()
Returns the loader's data proxy.
|
boolean |
isReuseLoadConfig()
Returns true if the load config is being reused.
|
boolean |
load()
Loads the data using the current configuration.
|
boolean |
load(C loadConfig)
Loads the data using the given load configuration.
|
protected void |
loadData(C config)
Load data, delegating to
DataProxy if configured, or forwarding to
loadData(Object) if not. |
protected void |
loadData(C config,
<any> callback)
Called by
loadData(Object) when a data proxy is not being used. |
protected C |
newLoadConfig()
Template method to allow custom BaseLoader subclasses to provide their own
implementation of LoadConfig.
|
protected void |
onLoadFailure(C loadConfig,
Throwable t)
Called when a load operation fails.
|
protected void |
onLoadSuccess(C loadConfig,
M data)
Called when the remote data has been received.
|
protected C |
prepareLoadConfig(C config)
Template method to allow custom subclasses to prepare the load config prior
to loading data
|
protected void |
setLastLoadConfig(C lastLoadConfig)
Sets the most recent load config.
|
void |
setReuseLoadConfig(boolean reuseLoadConfig)
Sets whether the same load config instance should be used for load
operations (defaults to false).
|
public Loader(DataProxy<C,M> proxy)
proxy
- the data proxypublic Loader(DataProxy<C,T> proxy, DataReader<M,T> reader)
proxy
- the data proxyreader
- the data readerpublic HandlerRegistration addBeforeLoadHandler(BeforeLoadEvent.BeforeLoadHandler<C> handler)
BeforeLoadEvent.HasBeforeLoadHandlers
BeforeLoadEvent
handler.addBeforeLoadHandler
in interface BeforeLoadEvent.HasBeforeLoadHandlers<C>
handler
- the handlerprotected <H extends EventHandler> HandlerRegistration addHandler(<any> type, H handler)
H
- type parameter to ensure that the event and handler matchtype
- the type of event to listen forhandler
- the handler to call when the event goes offpublic HandlerRegistration addLoaderHandler(LoaderHandler<C,M> handler)
LoaderHandler.HasLoaderHandlers
LoadEvent
handler.addLoaderHandler
in interface LoaderHandler.HasLoaderHandlers<C,M>
handler
- the handlerpublic HandlerRegistration addLoadExceptionHandler(LoadExceptionEvent.LoadExceptionHandler<C> handler)
LoadExceptionEvent.HasLoadExceptionHandlers
LoadExceptionEvent
handler.addLoadExceptionHandler
in interface LoadExceptionEvent.HasLoadExceptionHandlers<C>
handler
- the handlerpublic HandlerRegistration addLoadHandler(LoadHandler<C,M> handler)
LoadHandler.HasLoadHandlers
LoadEvent
handler.addLoadHandler
in interface LoadHandler.HasLoadHandlers<C,M>
handler
- the handlerpublic C getLastLoadConfig()
public DataProxy<?,?> getProxy()
public boolean isReuseLoadConfig()
public boolean load()
BeforeLoadEvent
before the request, then the LoadEvent
after the load operation.public boolean load(C loadConfig)
BeforeLoadEvent
before the request, then the LoadEvent
after the load operation. The current load configuration object can be
retrieved using getLastLoadConfig()
.loadConfig
- the load configpublic void setReuseLoadConfig(boolean reuseLoadConfig)
reuseLoadConfig
- true to reuseprotected boolean fireEvent(<any> event)
event
- the event to fireprotected void loadData(C config)
DataProxy
if configured, or forwarding to
loadData(Object)
if not.config
- the load configprotected void loadData(C config, <any> callback)
loadData(Object)
when a data proxy is not being used.config
- the load configcallback
- the callbackprotected C newLoadConfig()
protected void onLoadFailure(C loadConfig, Throwable t)
loadConfig
- the load configt
- the exceptionprotected void onLoadSuccess(C loadConfig, M data)
loadConfig
- the load configdata
- dataprotected C prepareLoadConfig(C config)
protected void setLastLoadConfig(C lastLoadConfig)
lastLoadConfig
- the most recent load config to setCopyright © 2018. All rights reserved.