org.merlotxml.merlot
Class IDManager

java.lang.Object
  extended byorg.merlotxml.merlot.IDManager
All Implemented Interfaces:
DTDConstants, MerlotNodeListener

public class IDManager
extends java.lang.Object
implements DTDConstants, MerlotNodeListener

Manages ID and IDRef attributes for one XML file. Generic implementation.

Author:
Jean-Michel Sizun

Field Summary
protected  java.util.Hashtable _attrLastId
          contains the last index value used for each named node.
protected  long _lastTimeAssigned
          Used to check that the same millisecond is not assigned twice.
protected  MerlotDOMNode _rootNode
           
static int NODE_HIGHEST
           
static int NODE_SMALLEST
           
static int NODE_TIMESTAMP
           
static int NONE
           
static int TIMESTAMP
           
static int USERID_TIMESTAMP
           
 
Fields inherited from interface org.merlotxml.util.xml.DTDConstants
ANY, CDATA, COMMENT, COMMENT_KEY, CONTENT_CONCAT, CONTENT_GROUP, CONTENT_LEAF, CONTENT_ONEMAX, CONTENT_OR, CONTENT_PLUS, CONTENT_SINGLE, CONTENT_STAR, EMPTY, ENTITIES, ENTITY, FIXED, GROUP, ID, IDREF, IDREFS, IMPLIED, NMTOKEN, NMTOKENS, NOTATION, PCDATA, PCDATA_KEY, PROCESSING_INSTRUCTION, PROCESSING_INSTRUCTION_KEY, REQUIRED, TOKEN_GROUP
 
Constructor Summary
IDManager(MerlotDOMNode rootNode)
           
 
Method Summary
 java.util.HashMap collectAttributesOfType(MerlotDOMElement start, int dtdConstant)
           
 java.lang.String getDefaultIdValue(MerlotDOMNode node, java.lang.String attrName)
          Returns a default string ID attribute value for a node.
protected  java.lang.String getDefaultIdValueForIndex(MerlotDOMNode node, java.lang.String attrName, int index)
          Returns a default string ID attribute value for a node according to an integer index.
protected  java.util.Map getIDAttrs(MerlotDOMNode node, MerlotDOMNode targetNode, java.lang.String targetAttrName)
          Returns all the ID attributes in the document which belongs to a node and its children.
 java.util.Map getIDAttrs(MerlotDOMNode targetNode, java.lang.String targetAttrName)
          Returns all the ID attributes in the document.
 int getIdTypeSetting()
           
protected  java.util.Vector getIdValues(MerlotDOMNode targetNode, java.lang.String targetAttrName)
          Returns all the ID attributes in the document.
 java.lang.String getLogAttribute()
           
 boolean getLogLastModifiedSetting()
           
 boolean isDuplicate(org.w3c.dom.Attr idAttr, java.util.Vector idValues)
           
 void logChange(MerlotDOMNode node)
           
 void nodeChanged(MerlotDOMNode parent, int[] indices, MerlotDOMNode[] children)
           
 void nodeDeleted(MerlotDOMNode node)
           
 void nodeInserted(MerlotDOMNode parent, int[] indices, MerlotDOMNode[] children)
          notifies the listener that one or more nodes were inserted under the given parent.
 void nodeRemoved(MerlotDOMNode parent, int[] indices, MerlotDOMNode[] children)
          notifies the listener that one or more nodes under the given parent were deleted.
 java.util.HashMap preventDuplicateId(MerlotDOMElement suspect, java.util.Vector idValues)
           
 void setDisabled(boolean disable)
           
 void updateIdRefs(MerlotDOMElement root, java.util.HashMap changes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rootNode

protected MerlotDOMNode _rootNode

_attrLastId

protected java.util.Hashtable _attrLastId
contains the last index value used for each named node.


_lastTimeAssigned

protected long _lastTimeAssigned
Used to check that the same millisecond is not assigned twice.


NONE

public static final int NONE
See Also:
Constant Field Values

NODE_SMALLEST

public static final int NODE_SMALLEST
See Also:
Constant Field Values

NODE_HIGHEST

public static final int NODE_HIGHEST
See Also:
Constant Field Values

TIMESTAMP

public static final int TIMESTAMP
See Also:
Constant Field Values

NODE_TIMESTAMP

public static final int NODE_TIMESTAMP
See Also:
Constant Field Values

USERID_TIMESTAMP

public static final int USERID_TIMESTAMP
See Also:
Constant Field Values
Constructor Detail

IDManager

public IDManager(MerlotDOMNode rootNode)
Method Detail

getIDAttrs

public java.util.Map getIDAttrs(MerlotDOMNode targetNode,
                                java.lang.String targetAttrName)
Returns all the ID attributes in the document. They are returned in a hashtable with Attr instancies as keys and the parent node as values.

Parameters:
targetNode - the node containing the IDREF attribute
targetAttrName - the name of the IDREF attribute

getIDAttrs

protected java.util.Map getIDAttrs(MerlotDOMNode node,
                                   MerlotDOMNode targetNode,
                                   java.lang.String targetAttrName)
Returns all the ID attributes in the document which belongs to a node and its children. Unsaved Ids are not taken into account. They are returned in a hashtable with Attr instancies as keys and the parent node as values.

Parameters:
node - the parent node
targetNode - the node containing the IDREF attribute
targetAttrName - the name of the IDREF attribute

getIdValues

protected java.util.Vector getIdValues(MerlotDOMNode targetNode,
                                       java.lang.String targetAttrName)
Returns all the ID attributes in the document.

Parameters:
targetNode - the node containing the IDREF attribute
targetAttrName - the name of the IDREF attribute

getDefaultIdValue

public java.lang.String getDefaultIdValue(MerlotDOMNode node,
                                          java.lang.String attrName)
Returns a default string ID attribute value for a node. This methods checks if there is no interference with another ID in the document.

Parameters:
node - node containing the ID attribute
attrName - name of the ID attribute

getIdTypeSetting

public int getIdTypeSetting()

getDefaultIdValueForIndex

protected java.lang.String getDefaultIdValueForIndex(MerlotDOMNode node,
                                                     java.lang.String attrName,
                                                     int index)
Returns a default string ID attribute value for a node according to an integer index.

Parameters:
node - node containing the ID attribute
attrName - name of the ID attribute
index - arbitrary integer

nodeInserted

public void nodeInserted(MerlotDOMNode parent,
                         int[] indices,
                         MerlotDOMNode[] children)
notifies the listener that one or more nodes were inserted under the given parent. IDManager is added as a listener in DOMTreeTableAdapter.

Specified by:
nodeInserted in interface MerlotNodeListener

nodeRemoved

public void nodeRemoved(MerlotDOMNode parent,
                        int[] indices,
                        MerlotDOMNode[] children)
notifies the listener that one or more nodes under the given parent were deleted. Their previous indices are given.

Specified by:
nodeRemoved in interface MerlotNodeListener

nodeDeleted

public void nodeDeleted(MerlotDOMNode node)
Specified by:
nodeDeleted in interface MerlotNodeListener

nodeChanged

public void nodeChanged(MerlotDOMNode parent,
                        int[] indices,
                        MerlotDOMNode[] children)
Specified by:
nodeChanged in interface MerlotNodeListener

preventDuplicateId

public java.util.HashMap preventDuplicateId(MerlotDOMElement suspect,
                                            java.util.Vector idValues)

isDuplicate

public boolean isDuplicate(org.w3c.dom.Attr idAttr,
                           java.util.Vector idValues)

updateIdRefs

public void updateIdRefs(MerlotDOMElement root,
                         java.util.HashMap changes)

collectAttributesOfType

public java.util.HashMap collectAttributesOfType(MerlotDOMElement start,
                                                 int dtdConstant)

getLogLastModifiedSetting

public boolean getLogLastModifiedSetting()

getLogAttribute

public java.lang.String getLogAttribute()

setDisabled

public void setDisabled(boolean disable)

logChange

public void logChange(MerlotDOMNode node)