public class NutsHeap extends Object implements NutDaoListener, HeapListener
This class represents a set of nuts. Each Nut is built thanks to an associated NutDao
which only needs a particular path to create it.
A path is an abstract location of one to many nuts because it could be a regular expression. It is relative to
the base path of the NutDao.
All the paths must refer to the same type fo path (CSS, JS, etc).
| Modifier and Type | Class and Description |
|---|---|
static class |
NutsHeap.ListenerHolder
|
| Constructor and Description |
|---|
NutsHeap(NutsHeap other)
Builds a heap by copy.
|
NutsHeap(Object factoryObject,
List<String> pathsList,
boolean isDisposable,
NutDao theNutDao,
String heapId,
NutsHeap... heaps)
Builds a new
NutsHeap. |
NutsHeap(Object factoryObject,
List<String> pathsList,
NutDao theNutDao,
String heapId,
NutsHeap... heaps)
Builds a heap which is not disposable.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCreate(String pattern,
String path)
Refers a path as a resource created by this heap for the given pattern.
|
void |
addObserver(HeapListener listener)
Observes all the nuts in this heap with the given listener.
|
void |
checkFiles(ProcessContext processContext)
Checks that the
NutType and the paths list of this heap are not
null. |
boolean |
containsHeap(NutsHeap heap)
Indicates if the given heap equals to this heap or any heap of its composition.
|
List<Nut> |
create(Nut nut,
String path,
NutDao.PathFormat pathFormat,
ProcessContext processContext)
Delegates method of
NutDao.create(String, com.github.wuic.nut.dao.NutDao.PathFormat, com.github.wuic.ProcessContext)
The DAO is picked from heap or its composition. |
boolean |
equals(Object o) |
NutDao |
findDaoFor(Nut nut)
Finds the
NutDao that created this nut. |
NutsHeap |
findHeapFor(Nut nut)
Finds the
NutsHeap that created this nut. |
NutsHeap[] |
getComposition()
Returns the
heaps that compose this instance. |
Object |
getFactory()
An arbitrary object which helps to know how the listener has been created.
|
String |
getId()
Gets the heap's ID.
|
NutDao |
getNutDao()
|
List<Nut> |
getNuts()
Gets all the nuts of this heap.
|
Set<NutType> |
getNutTypes()
Gets the
NutType types. |
Boolean |
hasCreated(Nut nut)
|
int |
hashCode() |
boolean |
isDisposable()
Indicates if this listener should be removed from the observable object when a call to
NutDaoListener.polling(String, java.util.Set) or NutDaoListener.nutPolled(NutDao, String, Long) returns false. |
boolean |
notifyListeners(NutsHeap observable)
Notifies the listeners that this heap has detected an update in one or many nuts.
|
boolean |
nutPolled(NutDao dao,
String path,
Long timestamp)
Called when a nut has been polled.
|
void |
nutUpdated(NutsHeap heap)
Called when a nut has been updated in the heap.
|
boolean |
polling(String pattern,
Set<String> paths)
When a DAO performs a polling operation, this method is called first with all path which are going to be polled.
|
String |
proxyUriFor(Nut nut)
Delegates method of
NutDao.proxyUriFor(Nut). |
void |
setNutDao(NutDao dao,
Nut nut)
|
NutDao |
withRootPath(String rootPath,
Nut nut)
Delegates method of
NutDao.withRootPath(String). |
public NutsHeap(NutsHeap other)
Builds a heap by copy.
other - the heap to copypublic NutsHeap(Object factoryObject, List<String> pathsList, boolean isDisposable, NutDao theNutDao, String heapId, NutsHeap... heaps) throws IOException
Builds a new NutsHeap. All the paths must be named with an
extension that matches the NutType. If it is not the case, then
an IllegalArgumentException will be thrown.
Some additional heaps could be specified to make a composition.
factoryObject - the factory object (see factory)isDisposable - is disposable or not (see disposablepathsList - the pathstheNutDao - the NutDaoheapId - the heap IDheaps - some other heaps that compose this heapIOException - if the HEAP could not be createdpublic NutsHeap(Object factoryObject, List<String> pathsList, NutDao theNutDao, String heapId, NutsHeap... heaps) throws IOException
Builds a heap which is not disposable.
factoryObject - the factory object (factory)pathsList - the pathstheNutDao - the NutDaoheapId - the heap IDheaps - some other heaps that compose this heapIOException - if the HEAP could not be createdpublic NutDao findDaoFor(Nut nut)
Finds the NutDao that created this nut.
nut - the nutnull if not foundpublic NutsHeap findHeapFor(Nut nut)
Finds the NutsHeap that created this nut.
nut - the nutnull if not foundpublic NutDao getNutDao()
Gets the NutDao of this NutsHeap. Caution, don't use its method like
NutDao.create(String, com.github.wuic.nut.dao.NutDao.PathFormat, com.github.wuic.ProcessContext),
NutDao.proxyUriFor(Nut) or NutDao.withRootPath(String) but to the corresponding proxy methods
in this class which check if the NutDao to actually use is not in one of the heaps
that compose this NutsHeap.
NutDaopublic String proxyUriFor(Nut nut)
Delegates method of NutDao.proxyUriFor(Nut). The DAO is picked from heap or its composition.
nut - the nutpublic NutDao withRootPath(String rootPath, Nut nut)
Delegates method of NutDao.withRootPath(String). The DAO is picked from heap or its composition.
nut - the root nutrootPath - the pathpublic List<Nut> create(Nut nut, String path, NutDao.PathFormat pathFormat, ProcessContext processContext) throws IOException
Delegates method of NutDao.create(String, com.github.wuic.nut.dao.NutDao.PathFormat, com.github.wuic.ProcessContext)
The DAO is picked from heap or its composition.
nut - the root nutpath - the nut path to createpathFormat - the formatprocessContext - the process contextIOException - if any I/O error occurspublic void addObserver(HeapListener listener)
Observes all the nuts in this heap with the given listener.
listener - the listenerpublic final void addCreate(String pattern, String path)
Refers a path as a resource created by this heap for the given pattern.
pattern - the pattern the is generated forpath - the created path resourcepublic void checkFiles(ProcessContext processContext) throws IOException
Checks that the NutType and the paths list of this heap are not
null. If they are, this methods will throw an IllegalArgumentException.
This exception could also be thrown if one path of the list does have a name
which ends with one of the possible extensions.
processContext - the process contextIOException - in I/O error casepublic String getId()
Gets the heap's ID.
public boolean polling(String pattern, Set<String> paths)
When a DAO performs a polling operation, this method is called first with all path which are going to be polled.
The paths are computed thanks to their representation (regex or not) specified when this listener has been registered to the observable.
If the listener returns false, the observable will stop notifying it only during the polling
operation.
polling in interface NutDaoListenerpattern - the pattern (actually the path itself or a regex) corresponding to the pathspaths - all the real paths which are going to be polledfalse if polling should not be done, true otherwisepublic Boolean hasCreated(Nut nut)
Indicates if this NutsHeap has created thanks to its own DAO a Nut. The methods search for the
original nut if the specified nut is a generated one.
nut - the nuttrue if heap has created a Nut with this path, false otherwisepublic boolean containsHeap(NutsHeap heap)
Indicates if the given heap equals to this heap or any heap of its composition. The equality if evaluated recursively through the composition.
heap - the heap to comparetrue if its equals to this heap or to a heap of its compositionpublic boolean nutPolled(NutDao dao, String path, Long timestamp)
Called when a nut has been polled.
When the observable object checks in one operation the changes on a set of nuts, the listener could notifies the observable to stop notifying it only during the operation.
nutPolled in interface NutDaoListenerdao - the DAO which pollspath - the polled pathtimestamp - the timestamp retrieved when poling the nuttrue if this listener needs to be notified of any other update during the observable's operation,
false otherwisepublic final NutsHeap[] getComposition()
Returns the heaps that compose this instance.
public boolean notifyListeners(NutsHeap observable)
Notifies the listeners that this heap has detected an update in one or many nuts.
observable - the heap where change has been detectedfalse for convenient usage in callerpublic void nutUpdated(NutsHeap heap)
Called when a nut has been updated in the heap.
nutUpdated in interface HeapListenerpublic boolean isDisposable()
Indicates if this listener should be removed from the observable object when a call to
NutDaoListener.polling(String, java.util.Set) or NutDaoListener.nutPolled(NutDao, String, Long) returns false.
If a listener is going to be removed, all the other listeners created by the same factory
must be removed if and only if they are also disposable.
isDisposable in interface NutDaoListenertrue if this listener is disposable a described, false otherwisepublic Object getFactory()
An arbitrary object which helps to know how the listener has been created.
getFactory in interface NutDaoListenerCopyright © 2012-2015. All Rights Reserved.