public class ProxyNutDao extends Object implements NutDao
Internal NutDao
class that maps particular path to a particular Nut
or then
to a particular NutDao
. If the path is not mapped, then a delegated DAO is called.
NutDao.PathFormat
Constructor and Description |
---|
ProxyNutDao(String rootPath,
NutDao delegate)
Builds a new instance thanks to a delegated
NutDao . |
Modifier and Type | Method and Description |
---|---|
void |
addRule(String path,
Nut nut)
Adds a mapping between a path and a nut.
|
void |
addRule(String path,
NutDao dao)
Adds a mapping between a path and a nut DAO.
|
List<Nut> |
create(String path,
NutDao.PathFormat format,
ProcessContext processContext)
Creates a list of
nuts thanks to the given path. |
List<Nut> |
create(String path,
ProcessContext processContext)
Creates a list of
nuts thanks to the given path considered as represented in any format. |
Boolean |
exists(String path,
ProcessContext processContext)
Indicates if the given path exists or not.
|
NutDao |
getNutDao(String path)
Gets a DAO for a particular path.
|
InputStream |
newInputStream(String path,
ProcessContext processContext)
Opens the stream for the given path.
|
void |
observe(String realPath,
NutDaoListener... listeners)
Adds a set of
listeners to be notified when an update has been detected on the nut. |
String |
proxyUriFor(Nut nut)
Returns an URI in a
String representation of a proxy serving the given nut. |
void |
save(Nut nut)
Saves the give nut.
|
Boolean |
saveSupported()
Indicates if this DAO is able to save a nut, which depends on the underlying protocol.
|
void |
shutdown()
Shutdowns this DAO by releasing its resources.
|
String |
toString() |
NutDao |
withRootPath(String rootPath)
Returns an instance that prefixes any nut name to be created with the given root path.
|
public void addRule(String path, Nut nut)
Adds a mapping between a path and a nut.
path
- the pathnut
- the nut returned when path is usedpublic void addRule(String path, NutDao dao)
Adds a mapping between a path and a nut DAO.
path
- the pathdao
- the NutDao
to call when path is usedpublic NutDao getNutDao(String path)
Gets a DAO for a particular path.
path
- the proxy pathpublic void observe(String realPath, NutDaoListener... listeners) throws IOException
Adds a set of listeners
to be notified when an update has been detected on the nut.
The targeted nut is represented by the specified path.
The listeners will be stored in a weak reference so if no strong reference to them exist, they will be garbage collected.
observe
in interface NutDao
realPath
- the real path name of the nut.listeners
- some listeners to be notified when an update has been detected on a nutIOException
- if an I/O occurs while retrieving last update of the nutpublic List<Nut> create(String path, ProcessContext processContext) throws IOException
Creates a list of nuts
thanks to the given path considered as represented in any format.
create
in interface NutDao
path
- the path representing the location of the nut(s)processContext
- the process context calling this methodIOException
- if an I/O error occurs when creating the nutNutDao.create(String, com.github.wuic.nut.dao.NutDao.PathFormat, com.github.wuic.ProcessContext)
public List<Nut> create(String path, NutDao.PathFormat format, ProcessContext processContext) throws IOException
Creates a list of nuts
thanks to the given path.
A NutDao.PathFormat
also gives information on the format used in the string representation of the given path.
create
in interface NutDao
path
- the path representing the location of the nut(s)format
- the path formatprocessContext
- the process context calling this methodIOException
- if an I/O error occurs when creating the nutpublic String proxyUriFor(Nut nut)
Returns an URI in a String
representation of a proxy serving the given nut.
If many proxies are defined, proxy URI is selected in a round-robin mode. Each time a proxy is used, it won't be reused until all other proxies have been used too.
proxyUriFor
in interface NutDao
nut
- the nutnull
if not proxy is setpublic void save(Nut nut)
Saves the give nut. An UnsupportedOperationException
will be thrown if the implementation supports
only nut access.
public Boolean saveSupported()
Indicates if this DAO is able to save a nut, which depends on the underlying protocol.
saveSupported
in interface NutDao
true
if NutDao.save(Nut)
is supported, false
otherwisepublic void shutdown()
Shutdowns this DAO by releasing its resources.
public NutDao withRootPath(String rootPath)
Returns an instance that prefixes any nut name to be created with the given root path.
withRootPath
in interface NutDao
rootPath
- the root pathpublic InputStream newInputStream(String path, ProcessContext processContext) throws IOException
Opens the stream for the given path.
newInputStream
in interface NutDao
path
- the path to accessprocessContext
- the process context calling this methodIOException
- if stream could not be openedpublic Boolean exists(String path, ProcessContext processContext) throws IOException
Indicates if the given path exists or not.
exists
in interface NutDao
path
- the path the DAO should be able to resolveprocessContext
- the process context calling this methodtrue
if path is resolved, false
otherwiseIOException
- if any I/O error occursCopyright © 2012-2015. All Rights Reserved.