org.inria.ns.reflex.xml
Class NamedItem

java.lang.Object
  extended by org.inria.ns.reflex.xml.NamedItem
All Implemented Interfaces:
Map.Entry, NamedType, ChildItem, Removable, Renamable, Unwrappable, NamedNode

public class NamedItem
extends Object
implements Map.Entry, Removable, Renamable, ChildItem, NamedNode, Unwrappable

An item with a name, a value, and a parent. Suitable for representing attributes and namespaces, attributes that must present them as element, and elements that must present them as attributes.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
NamedItem(Object value)
          Create an orphan unnamed item (not an attribute).
NamedItem(QName name, Object value)
          Create an orphan item.
NamedItem(QName name, Object value, Object parent)
          Create a new item.
NamedItem(QName name, Object value, Object parent, boolean isAttribute)
          Create a new item.
 
Method Summary
 QName getDOMName()
          Return the non-null name of this item.
 Object getKey()
          Return the name of this item.
 Object getParent()
          Return the parent of this item.
 QName getTypeName()
          A named item is either an attribute, an element, a namespace node, or a text node (if it doesn't have a name).
 Object getValue()
          Return the value of this item.
 QName getXPathName()
          Return the non-null name of this item.
 boolean isAttribute()
          Indicates whether this item is an attribute (and perhaps a namespace) or an element.
static EntryMap newEntryMap()
          Create a new entry map of named items.
static EntryMap newEntryMap(Object parent)
          Create a new entry map of named items.
 void remove()
          Remove this item from its parent.
 void rename(QName newName)
          Rename this item.
 void setAttribute(boolean isAttribute)
          Set whether this item is an attribute (and perhaps a namespace) or an element.
 void setParent(Object parent)
          Set a parent for this item.
 Object setValue(Object value)
          Set the value of this item.
 String toString()
          Return the string value of the item value.
 Object unwrap()
          Return the value wrapped in this item.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map.Entry
equals, hashCode
 

Constructor Detail

NamedItem

public NamedItem(QName name,
                 Object value,
                 Object parent)
Create a new item. By default, it is an attribute.

Parameters:
name - The non-null item name.
value - The item value, that can be null.
parent - The parent of the item, that can be null.

NamedItem

public NamedItem(QName name,
                 Object value,
                 Object parent,
                 boolean isAttribute)
Create a new item.

Parameters:
name - The non-null item name.
value - The item value, that can be null.
parent - The parent of the item, that can be null.
isAttribute - true if this item is an attribute, false otherwise.

NamedItem

public NamedItem(QName name,
                 Object value)
Create an orphan item. By default, it is an attribute.

Parameters:
name - The non-null item name.
value - The item value, that can be null.

NamedItem

public NamedItem(Object value)
Create an orphan unnamed item (not an attribute).

Parameters:
name - The non-null item name.
value - The item value, that can be null.
Method Detail

getKey

public Object getKey()
Return the name of this item.

Specified by:
getKey in interface Map.Entry
Returns:
The non-null qualified name of this item.
See Also:
QName

getValue

public Object getValue()
Return the value of this item.

Specified by:
getValue in interface Map.Entry
Returns:
The value of this item, that can be null.

setValue

public Object setValue(Object value)
Set the value of this item.

Specified by:
setValue in interface Map.Entry
Parameters:
value - The new value, that can be null.
Returns:
The previous value, that can be null.

remove

public void remove()
Remove this item from its parent.

It is the responsability of the parent to remove its item, if it is not orphan.

Specified by:
remove in interface Removable
See Also:
XMaster.remove(Object, Object)

rename

public void rename(QName newName)
Rename this item.

It is the responsability of the parent to rename its item, if it is not orphan. The parent must take care that the item have to be removed from the map it was belonging, if any, and restore in that map.

Specified by:
rename in interface Renamable
Parameters:
newName - The new name of this item.
See Also:
getKey(), XMaster.rename(Object, Object, QName)

getParent

public Object getParent()
Return the parent of this item.

Specified by:
getParent in interface ChildItem
Returns:
The parent of this item, that can be null.

setParent

public void setParent(Object parent)
Set a parent for this item.

Parameters:
parent - The parent to set, that can be null.

getDOMName

public QName getDOMName()
Return the non-null name of this item.

Specified by:
getDOMName in interface NamedNode
Returns:
The qualified name of this item.
See Also:
XMLNames.DOCUMENT_DOM_NAME, XMLNames.TEXT_DOM_NAME, XMLNames.COMMENT_DOM_NAME

getXPathName

public QName getXPathName()
Return the non-null name of this item.

Specified by:
getXPathName in interface NamedNode
Returns:
The qualified name of this item.
See Also:
XMLNames.DOCUMENT_XPATH_NAME, XMLNames.TEXT_XPATH_NAME, XMLNames.COMMENT_XPATH_NAME

isAttribute

public boolean isAttribute()
Indicates whether this item is an attribute (and perhaps a namespace) or an element.

Returns:
true if this item is an attribute or a namespace, false if it is an element.

setAttribute

public void setAttribute(boolean isAttribute)
Set whether this item is an attribute (and perhaps a namespace) or an element.

Parameters:
isAttribute - true if this item is an attribute or a namespace, false if it is an element.

toString

public String toString()
Return the string value of the item value.

Overrides:
toString in class Object
Returns:
The string computed on the value of the item by the master operator
See Also:
XMaster.stringValueOf(Object)

newEntryMap

public static EntryMap newEntryMap()
Create a new entry map of named items. All named items in the map has the returned entry map as parent.

Returns:
A new entry map.

newEntryMap

public static EntryMap newEntryMap(Object parent)
Create a new entry map of named items. All named items in the map has the parent given.

Parameters:
parent - The parent of all entries in the map.
Returns:
A new entry map.

getTypeName

public QName getTypeName()
A named item is either an attribute, an element, a namespace node, or a text node (if it doesn't have a name).

Specified by:
getTypeName in interface NamedType
Returns:
The type of this item.
See Also:
isAttribute(), XMLNames.ATTRIBUTE_TYPE_QNAME, XMLNames.ELEMENT_TYPE_QNAME, XMLNames.NAMESPACE_TYPE_QNAME, XMLNames.TEXT_TYPE_QNAME

unwrap

public Object unwrap()
Return the value wrapped in this item.

Specified by:
unwrap in interface Unwrappable
Returns:
The item value.