|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.day.cq.jcr.adapter.ContentElementAdapter
com.day.cq.jcr.adapter.StructuredContentElement
com.day.cq.jcr.adapter.ContainerListAdapter
public class ContainerListAdapter
The ContainerListAdapter class implements the
ContainerList interface on top of the JCR repository.
NOTE: Most of the code in this class has been copied from the original
ContainerListProxy class with adaptions to the JCR API and
removing references to the stubs used by the ContentBus implementation.
Instances of this class should be used for short-lived objects only, as this class caches information found at access and never checks with the repository whether the information is still accurate on later accesses.
| Nested Class Summary | |
|---|---|
protected static class |
ContainerListAdapter.ContainerIteratorImpl
This class implements a ContainerIterator that provides
the containers stored in the container list |
| Field Summary |
|---|
| Fields inherited from class com.day.cq.jcr.adapter.ContentElementAdapter |
|---|
page, parent |
| Constructor Summary | |
|---|---|
protected |
ContainerListAdapter(PageAdapter page,
StructuredContentElement parent,
java.lang.String label,
ElementInfo elementInfo)
Creates a new instance of this class backed by the given node. |
| Method Summary | |
|---|---|
void |
accept(ContentElementVisitor visitor)
Calls the ContentElementVisitor.visit(Container) method
with this as its parameter. |
void |
clear()
Removes all containers from this container list. |
ContainerIterator |
containerIterator()
Returns a ContainerIterator to iterate over all containers
contained in this container list. |
void |
copyTo(ContentElement dst)
Recursively copies the containers in this container list to the destination container list. |
Container |
createContainer()
Creates a container with an autmoatically generated container label. |
Container |
createContainer(java.lang.String label,
java.lang.String above)
Creates a new container with the exact label. |
Container |
createContainer(java.lang.String labelhint,
java.lang.String above,
boolean exact)
Creates a new container whose label is derived from the given labelhint. |
Container |
getContainer(int index)
Returns the container with given numeric index. |
Container |
getContainer(java.lang.String label)
Returns the Container with the given label. |
Container |
getContainer(java.lang.String label,
boolean create)
Returns the container with the given label, optionally
creating the container if not existing. |
protected ContentElement |
getDeepElement(java.util.StringTokenizer labels,
boolean create)
Accesses the child content element named by the first token in labels and either returns that child element if the
labels do not contain more tokens or returns the result of
forwarding to the child element's getDeepElement method. |
ContentElement |
getElement(java.lang.String label)
Returns the content element with the given label. |
protected java.lang.String |
getNodeType()
Returns Util.NODE_CONTAINERLIST_TYPE as the name of the node type
for nodes representing container lists. |
boolean |
hasContainer(java.lang.String label)
Returns whether this container list has a content element with the given label. |
boolean |
hasElement(java.lang.String label)
Returns whether this container list has a content element with the given label. |
boolean |
isEmpty()
Checks, if this container list is empty, i.e. |
boolean |
isReadOnly()
Returns true if this container list has been defined as
read-only in the CSD. |
void |
moveContainer(java.lang.String label,
java.lang.String above)
Moves a Container to a new location. |
void |
removeContainer(java.lang.String label)
Removes the Container specified by label
from this containerlist. |
int |
size()
Returns the number of containers in this container list. |
protected Container |
wrapContainerNode(java.lang.String label,
javax.jcr.Node containerNode)
Returns a Container based on the given container node with
the defined label. |
| Methods inherited from class com.day.cq.jcr.adapter.StructuredContentElement |
|---|
getItemName |
| Methods inherited from class com.day.cq.jcr.adapter.ContentElementAdapter |
|---|
canModify, getDeepElement, getDeepElement, getElementInfo, getLabel, getModificationTime, getPage, getQualident, getUUID, parent |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.day.cq.contentbus.ContentElement |
|---|
getDeepElement, getDeepElement, getLabel, getModificationTime, getQualident, getUUID, parent |
| Constructor Detail |
|---|
protected ContainerListAdapter(PageAdapter page,
StructuredContentElement parent,
java.lang.String label,
ElementInfo elementInfo)
node.
page - The ContentBus page on which this container list is located.parent - The content element in which this container list is located
as a direct child element.label - The label of this container list.elementInfo - The container list definition.| Method Detail |
|---|
public boolean hasElement(java.lang.String label)
hasContainer(String).
This method is implemented by calling the hasContainer(String)
method.
hasElement in interface ContentElementtrue if it exists;
false otherwise.
public ContentElement getElement(java.lang.String label)
throws NoSuchContentElementException,
ContentBusException
getContainer(String) method.
This method is implemented by calling the getContainer(String)
method.
getElement in interface ContentElementlabel - The name of the direct-child content element to return.
NoSuchContentElementException - If this container list has no
container with the given label.
ContentBusException - if an error occurrspublic boolean hasContainer(java.lang.String label)
hasContainer in interface ContainerListlabel - the label of a container
true if the container exists;
false otherwise;
public Container getContainer(java.lang.String label,
boolean create)
throws ContentBusException
label, optionally
creating the container if not existing.
getContainer in interface ContainerListlabel - The label of the container to return.create - true if the container should be created if
not yet existing.
null if this container list
does not contain such a container and create is
false or if this container list is read-only.
java.lang.IllegalStateException - If the container should be created but the
page on which this container list is located is not in
transaction.
ContentBusException - If any other error occurrs accessing the
named container or creating a new container.
public Container getContainer(java.lang.String label)
throws NoSuchContentElementException,
ContentBusException
Container with the given label. This
implementation wraps child node with the given label in a
ContainerAdapter instance assuming that each child node of the
node backing this container list is backing a container.
getContainer in interface ContainerListlabel - the label of the desired container
NoSuchContentElementException - if the container does not exist
ContentBusException - if an error occurrs
public Container getContainer(int index)
throws NoSuchContentElementException,
ContentBusException
getContainer in interface ContainerListindex - The numeric index of the container to return.
NoSuchContentElementException - If the index is higher than the
number of containers in this container list.
ContentBusException - If any other error occurrs trying to access
the container.
public ContainerIterator containerIterator()
throws ContentBusException
ContainerIterator to iterate over all containers
contained in this container list.
containerIterator in interface ContainerListContainerIterator.
ContentBusException - if an error occurrs preparing the container
iterator.public int size()
size in interface ContainerList
protected ContentElement getDeepElement(java.util.StringTokenizer labels,
boolean create)
throws NoSuchContentElementException,
ContentBusException
labels and either returns that child element if the
labels do not contain more tokens or returns the result of
forwarding to the child element's getDeepElement method.
getDeepElement in class ContentElementAdapterlabels - The tokenized qualident of the ultimate content element to
find.create - true if the method is allowed to create
intermediate content elements if missing.
labels.
NoSuchContentElementException - Is thrown if the first token in
labels does not refer to an existing child
content element of this container and create
is false or this container list is read-only.
ContentBusException - Is thrown if any other error occurrs drilling
down the content element tree.protected java.lang.String getNodeType()
Util.NODE_CONTAINERLIST_TYPE as the name of the node type
for nodes representing container lists.
getNodeType in class StructuredContentElement
public Container createContainer()
throws ContentBusException
This implementation uses a global instance of the
java.util.Random class to get approximately equally
distributed numeric labels in the range between 0 (inclusive) and 100'000
(exclusive). The reason to use this pseudo-random number generator is to
try to prevent too many checks for label duplicate because each check
results in a container node access check. As the label has no
significance as to the container ordering, this is not a big issue.
If the number of containers gets close to the maximum number (100'000) it
tends to take longer to find a "free" number. To prevent to long
processing times a limit is built in which limits the number of loop
iterations to 1000 times the maximum number (100'000'000). If this number
of iterations is reached without finding a "free" number a
ContentBusException is thrown.
After having found a non-existant label, this method calls
getContainer(newLast, null, true), where
newLast is the label found in the first step.
createContainer in interface ContainerListjava.lang.IllegalStateException - If the page on which this container list is
located is not in transaction.
ContentBusException - If any other error occurrs creating the new
container. Especially this exception may be thrown if no
container label may be created in a reasonable amount of
processing.
public Container createContainer(java.lang.String label,
java.lang.String above)
throws ContentBusException
createContainer(label, above, true).
createContainer in interface ContainerListlabel - The (exact) label of the new container to createabove - The (optional) label of the container above which the new
container is inserted. If this is null, an
empty string or not the label of an existing container, the
new container is appended to the end of the container list.
java.lang.IllegalArgumentException - if the labelhint contains
invalid label characters.
ContentBusException - if any error occurrs creating the new
container.
public Container createContainer(java.lang.String labelhint,
java.lang.String above,
boolean exact)
throws ContentBusException
labelhint.
createContainer in interface ContainerListlabelhint - The proposed label of the new container. Depending on
the value of the exact parameter, this label
may be modified or not to create the real label for the new
container.above - The (optional) label of the container above which the new
container is inserted. If this is null, an
empty string or not the label of an existing container, the
new container is appended to the end of the container list.exact - Indicates whether the labelhint parameter is
to be used as the exact name of the new container (true).
Otherwise - if false - the label may be derived
from labelhint by modifying it to ensure it
contains valid label characters and is a unique label within
the container list.
java.lang.IllegalArgumentException - if exact is
true and the labelhint contains
invalid label characters.
ContentBusException - if any error occurrs creating the new
container.
public void moveContainer(java.lang.String label,
java.lang.String above)
throws ContentBusException
Container to a new location. The page that this
container list belongs to, must already be in a transaction. If this
container list is defined read only, this method has no effect.
moveContainer in interface ContainerListlabel - label of container to moveabove - label of container to place above. if this parameter is
null or an empty string, the container is moved
to the end of the list
ContentBusException - if an error occurrs
NoSuchContentElementException - if either the source or above
container does not exist.
java.lang.IllegalStateException - if the page is not in a transaction
public void removeContainer(java.lang.String label)
throws ContentBusException
Container specified by label
from this containerlist. The page that this container list belongs to,
must already be in a transaction. If this container list is defined read
only, this method has no effect.
removeContainer in interface ContainerListlabel - the label of the container to remove
ContentBusException - if an error occurrs
NoSuchContentElementException - if the container does not exist.
java.lang.IllegalStateException - if the page is not in a transaction
public void clear()
throws ContentBusException
clear method is called to clear out the
containers removed. The page which this element belongs to, must already
by in a transaction.
clear in interface ContentElementContentBusException
java.lang.IllegalStateException - if the page is not in a transactionPage#startTransaction()
public void copyTo(ContentElement dst)
throws ContentBusException
This method iteratos over the containers in this container list, creates
a like named container in the destination container list and calls the
copyTo method on the source container handing the newly
created destination container.
copyTo in interface ContentElementdst - The destination container list into which all containers of
this container list are copied.
java.lang.ClassCastException - If the dst content element is
not ContainerList.
ContentBusException - If an error occurrs such as any container
already existing in the destination container list.public boolean isEmpty()
isEmpty in interface ContentElementtrue if this list is empty; false
otherwise.
ContentBusException - if an error occurrs checking whether any
containers exist in this container list.public boolean isReadOnly()
true if this container list has been defined as
read-only in the CSD.
isReadOnly in interface ContainerListisReadOnly in class ContentElementAdaptertrue if this container list is defined as read only;
false otherwise.
public void accept(ContentElementVisitor visitor)
throws ContentBusException
ContentElementVisitor.visit(Container) method
with this as its parameter. It is the task of the called
visit method to traverse the content elements of this
container.
accept in interface ContentElementvisitor - the visitor to call with this instance.
ContentBusException - may be thrown by the visitor's
visit
method in case of an error, which is forwarded to the caller
of this method.
protected Container wrapContainerNode(java.lang.String label,
javax.jcr.Node containerNode)
Container based on the given container node with
the defined label.
label - The labe of the container. This will generally be the same
as the name of the containerNode. This should
not be the empty string or null, otherwise
spurious errors may later occurr.containerNode - The JCR Node providing the contents
of the container.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||