org.kuali.rice.krad.uif.lifecycle.initialize
Class AssignIdsTask

java.lang.Object
  extended by org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase<LifecycleElement>
      extended by org.kuali.rice.krad.uif.lifecycle.initialize.AssignIdsTask
All Implemented Interfaces:
Runnable, ViewLifecycleTask<LifecycleElement>

public class AssignIdsTask
extends ViewLifecycleTaskBase<LifecycleElement>

Assign a unique ID to the component, if one has not already been assigned.

Author:
Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
AssignIdsTask(LifecycleElementState elementState)
          Create a task to assign component IDs during the initialize phase.
 
Method Summary
static String generateId(LifecycleElement element, View view)
          Generate a new ID for a lifecycle element at the current phase.
protected  void performLifecycleTask()
          Performs phase-specific lifecycle processing tasks.
 
Methods inherited from class org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase
getElementState, getElementType, run, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AssignIdsTask

public AssignIdsTask(LifecycleElementState elementState)
Create a task to assign component IDs during the initialize phase.

Parameters:
elementState - The initialize phase for the component.
Method Detail

generateId

public static String generateId(LifecycleElement element,
                                View view)
Generate a new ID for a lifecycle element at the current phase.

This method used a product of primes similar to the one used for generating String hash codes. In order to minimize to collisions a large prime is used, then when collisions are detected a different large prime is used to generate an alternate ID.

The hash code that the generated ID is based on is equivalent (though not identical) to taking the hash code of the string concenation of all class names, non-null IDs, and successor index positions in the lifecycle phase tree for all predecessors of the current phase. This technique leads to a reliably unique ID that is also repeatable across server instances and test runs.

The use of large primes by this method minimizes collisions, and therefore reduces the likelihood of a race condition causing components to come out with different IDs on different server instances and/or test runs.

Parameters:
element - The lifecycle element for which to generate an ID.
view - View containing the lifecycle element.
Returns:
An ID, unique within the current view, for the given element.
See Also:
ViewIndex.observeAssignedId(String), for the algorithm this method is based on.

performLifecycleTask

protected void performLifecycleTask()
Performs phase-specific lifecycle processing tasks.

Specified by:
performLifecycleTask in class ViewLifecycleTaskBase<LifecycleElement>


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.