2.17.2: 2011-06-17

net.sf.basedb.util.extensions
Class ActionIterator<A extends Action>

java.lang.Object
  extended by net.sf.basedb.util.extensions.ActionIterator<A>
All Implemented Interfaces:
Iterator<A>

public class ActionIterator<A extends Action>
extends Object
implements Iterator<A>

Iterator for iterating over all actions that will be created by extensions after a call to Registry.useExtensions(ClientContext, ExtensionsFilter, String...). That method returns an ExtensionsInvoker object which in it's turn uses this iterator.

Note the phrase "will be created" above. The actions are created on demand as this iterator moves on the next item. This happens in the hasNext() method, which, for each extension, calls Extension.getActionFactory() and then ActionFactory.getActions(InvokationContext).

The actions returned from the extensions are piled up in an internal buffer that the next() method pick items from. When the buffer is empty the iterator moves on to the actions from next extension until there are no more extensions and the action buffer is empty.

Version:
2.7
Author:
nicklas
Last modified
$Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $

Field Summary
private  A[] actions
           
private  boolean checkNext
           
private  A currentAction
           
private  ExtensionContext<A> currentContext
           
private  boolean hasNext
           
private  Iterator<ExtensionContext<A>> iterator
           
private  int offset
           
 
Constructor Summary
ActionIterator(Iterator<ExtensionContext<A>> iterator)
           
 
Method Summary
 void clearError()
          Clear any error that has been registered for the current action.
 Extension<? extends A> getExtension()
          Get the extension that created the current action.
 ExtensionPoint<? super A> getExtensionPoint()
          Get the extension point that the current action belongs to.
 Renderer<? super A> getRenderer()
          Gets the renderer for the current action.
 boolean hasNext()
           
 A next()
           
 void remove()
          Not supported.
 void setError(String message, Throwable t)
          Register an error with a message for the current action.
 void setError(Throwable t)
          Register an error for the current action.
private  boolean validActions(A[] actions)
          Check that the actions array is a not-null, non-empty array and contains actions of a type that is compatible with the ExtensionPoint.getActionClass() class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentContext

private ExtensionContext<A extends Action> currentContext

currentAction

private A extends Action currentAction

iterator

private final Iterator<ExtensionContext<A extends Action>> iterator

actions

private A extends Action[] actions

offset

private int offset

checkNext

private boolean checkNext

hasNext

private boolean hasNext
Constructor Detail

ActionIterator

ActionIterator(Iterator<ExtensionContext<A>> iterator)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<A extends Action>

next

public A next()
Specified by:
next in interface Iterator<A extends Action>

remove

public void remove()
Not supported.

Specified by:
remove in interface Iterator<A extends Action>
Throws:
UnsupportedOperationException - Always

getExtensionPoint

public ExtensionPoint<? super A> getExtensionPoint()
Get the extension point that the current action belongs to.


getExtension

public Extension<? extends A> getExtension()
Get the extension that created the current action.


getRenderer

public Renderer<? super A> getRenderer()
Gets the renderer for the current action.

Since:
2.9

clearError

public void clearError()
Clear any error that has been registered for the current action.

Since:
2.9
See Also:
setError(Throwable)

setError

public void setError(Throwable t)
Register an error for the current action. The error is handled by the error handler for the extension point.

Parameters:
t - The error to register
Since:
2.9

setError

public void setError(String message,
                     Throwable t)
Register an error with a message for the current action. The error is handled by the error handler for the extension point.

Parameters:
t - The error to register
message - An optional message
Since:
2.17

validActions

private boolean validActions(A[] actions)
Check that the actions array is a not-null, non-empty array and contains actions of a type that is compatible with the ExtensionPoint.getActionClass() class.

NOTE! If the array contains at least one invalid action, all actions, including the valid ones, will be ignored. No exception will be thrown. An error-level log message is written to the log file.

Parameters:
actions - The actions to check
Returns:
TRUE if the actions are valid, FALSE otherwise

2.17.2: 2011-06-17