|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.idom.impl.AbstractItem
org.zkoss.idom.impl.AbstractGroup
public abstract class AbstractGroup
A semi-implemented item for group. A group is a item that has child items.
The default implementation of newChildren is for the sematic of Element. A deriving class has to re-implement it, if it is not applicable. Example, Document.
Item,
Serialized Form| Nested Class Summary | |
|---|---|
protected class |
AbstractGroup.ChildArray
The array to hold children. |
protected static class |
AbstractGroup.ElementMap
Stores a 'cached' map of child elements to speed up the access. |
| Field Summary | |
|---|---|
protected List<Item> |
_children
The list of the children. |
| Fields inherited from interface org.zkoss.idom.Item |
|---|
FIND_BY_PREFIX, FIND_BY_REGEX, FIND_BY_TAGNAME, FIND_IGNORE_CASE, FIND_RECURSIVE |
| Constructor Summary | |
|---|---|
protected |
AbstractGroup()
Constructor. |
| Method Summary | |
|---|---|
boolean |
anyElement()
|
Node |
appendChild(Node newChild)
|
Object |
clone()
Clones this object (a deep cloning not including contents contained in Textual nodes). |
int |
coalesce(boolean recursive)
Coalesces children if they are siblings with the same type instances of Textual, Textual.isCoalesceable returns true. |
List<Item> |
detachChildren()
Detaches all children and returns them in a list. |
NodeList |
getChildNodes()
|
List<Item> |
getChildren()
Gets all children. |
Element |
getElement(String tname)
Gets the first Element-type child with the tag name. |
Element |
getElement(String namespace,
String name,
int mode)
Gets the first Element-type child that matches the giving criteria. |
int |
getElementIndex(int indexFrom,
String tname)
Gets the index of the first Element-type child with the specified name. |
int |
getElementIndex(int indexFrom,
String namespace,
String name,
int mode)
Gets the index of the Element-type first child that match the specified criteria. |
Set<String> |
getElementNames()
Returns a readonly set of names of element children. |
List<Element> |
getElements()
Returns a cloned copy of all element childrens |
List<Element> |
getElements(String tname)
Gets a readonly list of children with the tag name. |
List<Element> |
getElements(String namespace,
String name,
int mode)
Gets a readonly list of Element-type children that match the giving criteria. |
String |
getElementValue(String tname,
boolean trim)
Gets the text of the first Element-type child with the tag name, with a trimming option. |
String |
getElementValue(String namespace,
String name,
int mode,
boolean trim)
Gets the value of the first Element-type child that matches the giving criteria, with a trimming option. |
Node |
getFirstChild()
|
Node |
getLastChild()
|
boolean |
hasChildNodes()
|
Node |
insertBefore(Node newChild,
Node refChild)
|
protected List<Item> |
newChildren()
Creates a list to hold child vertices. |
Node |
removeChild(Node oldChild)
|
Node |
replaceChild(Node newChild,
Node oldChild)
|
| Methods inherited from class org.zkoss.idom.impl.AbstractItem |
|---|
cloneNode, compareDocumentPosition, detach, equals, getAttributes, getBaseURI, getDocument, getFeature, getLocalName, getLocator, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getParent, getParentNode, getPrefix, getPreviousSibling, getText, getTextContent, getUserData, hasAttributes, hashCode, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, match, normalize, setLocator, setName, setNodeValue, setParent, setPrefix, setText, setTextContent, setUserData |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.zkoss.idom.Item |
|---|
detach, getDocument, getLocator, getName, getParent, getText, setLocator, setName, setParent, setText |
| Methods inherited from interface org.w3c.dom.Node |
|---|
getNodeType |
| Field Detail |
|---|
protected List<Item> _children
| Constructor Detail |
|---|
protected AbstractGroup()
| Method Detail |
|---|
protected List<Item> newChildren()
The default implementation obeys the sematic of Element, i.e., it doen't allow any child that cannot be a child of Element.
For performance issue, we introduced a map to improve the search speed for Element node associated with a tag name.
public final List<Item> getChildren()
GroupThe returned list is "live". Any modification to it affects
the node. On the other hand, Group.getElements(String) returns
a copy.
Unlike JDOM, it won't coalesce adjacent children automatically since it might violate the caller's expection about List. Rather, we provide coalesce to let caller do the merging explicity. Note: when building a iDOM tree from a source (SAXBuilder.build), coalesce() will be inovked automatically.
Note: not all items supports children. If this item doesn't, it returns an empty list. And, if any invocation tries to add vertices to the returned list will cause UnsupportOperationException.
getChildren in interface Grouppublic final List<Item> detachChildren()
GroupNote: you cannot add children to anther Group by doing
group.addAll(e.getChildren()), because you have to detach
them first. Then, you could use this method:
group.addAll(e.detachChildren());
detachChildren in interface Grouppublic final boolean anyElement()
public final Set<String> getElementNames()
GroupGroup.getElements(java.lang.String, java.lang.String, int) to get elements.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to Group.getChildren()
will affect it.
getElementNames in interface GroupGroup.getElements()public final List<Element> getElements()
GroupUnlike Group.getChildren() and Group.getElementNames(),
the returned list is NOT a 'live-facade' of the real ones.
getElements in interface GroupGroup.getElementNames()
public final int getElementIndex(int indexFrom,
String namespace,
String name,
int mode)
GroupNote: only Element-type children are returned, since others have no name.
getElementIndex in interface GroupindexFrom - the index to start searching from; 0 for beginningnamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the serach mode; zero or any combination of
Item.FIND_xxx, except FIND_RECURSIVE
public final int getElementIndex(int indexFrom,
String tname)
GroupNote: only Element-type children are returned, since others have no name.
getChildren().add(getElementIndex(0, "pre:name"),
new Element("pre:another"));
getElementIndex in interface GroupindexFrom - the index to start searching from; 0 for beginningtname - the tag name (i.e., Namespaceable.getName)
public final Element getElement(String namespace,
String name,
int mode)
GroupNote: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
getElement in interface Groupnamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the search mode; zero or any combination of FIND_xxx.
public final Element getElement(String tname)
GroupNote: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
getElement in interface Grouptname - the tag name (i.e., Namespaceable.getName)
public final List<Element> getElements(String namespace,
String name,
int mode)
GroupUnlike Element.getElementsByTagName(java.lang.String), this method only
returns child elements, excluding grand children and other descedants.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to Group.getChildren()
will affect it.
Note: only Element-type children are returned. Depending on the mode, the searching is usually linear -- take O(n) to complete.
getElements in interface Groupnamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignoremode - the search mode; zero or any combination of FIND_xxx.
public final List<Element> getElements(String tname)
GroupUnlike Element.getElementsByTagName(java.lang.String), this method only
returns child elements, excluding grand children and other descedants.
The returned list is a 'live-facade' of the real ones, so
the performance is good, and any modification to Group.getChildren()
will affect it.
Note: only Element-type children are returned. Also, we did some optimization for this method so its access time is nearly constant.
getElements in interface Grouptname - the tag name (i.e., Namespaceable.getName)
public final String getElementValue(String namespace,
String name,
int mode,
boolean trim)
Group
getElementValue in interface Groupnamespace - the namspace URI if FIND_BY_PREFIX is not specified;
the namespace prefix if FIND_BY_PREFIX specified; null to ingorename - the local name if FIND_BY_TAGNAME is not sepcified;
the tag name if FIND_BY_TAGNAME specified; null to ignore
public final String getElementValue(String tname,
boolean trim)
Group
getElementValue in interface Grouptname - the tag name (i.e., Namespaceable.getName)
public final int coalesce(boolean recursive)
GroupSAXBuilder.build will do the merging automatically.
coalesce in interface Grouprecursive - true to coalesce all descendants;
false to coalesce only the direct childrenpublic final NodeList getChildNodes()
getChildNodes in interface NodegetChildNodes in class AbstractItempublic final Node getFirstChild()
getFirstChild in interface NodegetFirstChild in class AbstractItempublic final Node getLastChild()
getLastChild in interface NodegetLastChild in class AbstractItempublic final boolean hasChildNodes()
hasChildNodes in interface NodehasChildNodes in class AbstractItem
public final Node insertBefore(Node newChild,
Node refChild)
insertBefore in interface NodeinsertBefore in class AbstractItem
public final Node replaceChild(Node newChild,
Node oldChild)
replaceChild in interface NodereplaceChild in class AbstractItempublic final Node removeChild(Node oldChild)
removeChild in interface NoderemoveChild in class AbstractItempublic final Node appendChild(Node newChild)
appendChild in interface NodeappendChild in class AbstractItempublic Object clone()
AbstractItem
clone in interface Itemclone in class AbstractItem
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||