org.benow.web.complete
Class Completer

java.lang.Object
  extended by org.benow.web.complete.Completer
All Implemented Interfaces:
java.lang.Iterable<CompleteResult>, java.util.Iterator<CompleteResult>
Direct Known Subclasses:
ACDemoObjectCompleter, CategoryCompleter, IngredientCompleter, JDBCCompleter, RecipeTitleCompleter

public abstract class Completer
extends java.lang.Object
implements java.util.Iterator<CompleteResult>, java.lang.Iterable<CompleteResult>

A thing which offers possible completions for string values for field(s) within an class. Completers are used to provide possible values for fields during data entry, ie typeahead lookups.

Author:
andy

Nested Class Summary
static interface Completer.Completes
           
 
Field Summary
protected  boolean cancelled
           
protected  java.lang.String parameters
           
protected  java.lang.String prefix
           
 
Constructor Summary
protected Completer(java.lang.String prefix, java.lang.String parameters)
           
 
Method Summary
 void cancel()
          Cancel the lookup, as another lookup request for the same field has come in.
 void close()
          Closes underlying result stream.
protected  void doClose()
           
protected abstract  boolean doHasNext()
           
protected abstract  CompleteResult doNext()
           
static java.util.List<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass, java.lang.String forField, java.lang.String prefix, java.lang.String parameters)
          Get completions for class field using given prefix
static java.util.List<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass, java.lang.String forField, java.lang.String prefix, java.lang.String parameters, int starting, int spanning)
           
static org.benow.java.collection.SubList<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass, java.lang.String forField, java.lang.String prefix, java.lang.String parameters, int starting, int spanning, org.benow.repository.Transaction tx)
          Get completions for class field using given prefix, including a repository search using the given transaction (if the field has been annotated with JSQLComplete).
 java.lang.Class<?> getForClass()
          The class this completer completes for, as provided in the forClass field of the Completer.Completes annotation in the implementing completer.
 java.lang.String getForField()
          The field this completer completes for, as provided in the forField field of the Completer.Completes annotation in the implementing completer.
 boolean hasFailed()
           
 boolean hasNext()
           
protected  void init()
          Do something before any results are generated
protected  boolean isSufficient()
           
 java.util.Iterator<CompleteResult> iterator()
           
 CompleteResult next()
           
 void remove()
           
protected  void setHasFailed(boolean failed)
          Set the failed status of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cancelled

protected boolean cancelled

prefix

protected java.lang.String prefix

parameters

protected java.lang.String parameters
Constructor Detail

Completer

protected Completer(java.lang.String prefix,
                    java.lang.String parameters)
Method Detail

isSufficient

protected boolean isSufficient()
Returns:
true if all required data is given (in params, prefix, etc). If not sufficient, the query will not be done and there will be no results

hasNext

public final boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<CompleteResult>

next

public final CompleteResult next()
Specified by:
next in interface java.util.Iterator<CompleteResult>

doNext

protected abstract CompleteResult doNext()

init

protected void init()
             throws java.lang.Exception
Do something before any results are generated

Throws:
java.lang.Exception

doHasNext

protected abstract boolean doHasNext()

close

public final void close()
Closes underlying result stream. Stream is automatically closed when the end of the results is hit (ie hasNext() returns false), but this method should be used when the end of the results is not hit.


hasFailed

public boolean hasFailed()
Returns:
true if this completer of the given class has previously failed

setHasFailed

protected void setHasFailed(boolean failed)
Set the failed status of the class. If set to failed, completers of this class will not be able to be used. Set to false to re-enable use of the completer

Parameters:
failed -

doClose

protected void doClose()
                throws java.lang.Exception
Throws:
java.lang.Exception

iterator

public java.util.Iterator<CompleteResult> iterator()
Specified by:
iterator in interface java.lang.Iterable<CompleteResult>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<CompleteResult>

cancel

public void cancel()
Cancel the lookup, as another lookup request for the same field has come in.


getForClass

public java.lang.Class<?> getForClass()
The class this completer completes for, as provided in the forClass field of the Completer.Completes annotation in the implementing completer.

Returns:
the class this completer completes for

getForField

public java.lang.String getForField()
The field this completer completes for, as provided in the forField field of the Completer.Completes annotation in the implementing completer.

Returns:
the field this completer completes for

getCompletionsFor

public static java.util.List<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass,
                                                                java.lang.String forField,
                                                                java.lang.String prefix,
                                                                java.lang.String parameters)
                                                         throws java.io.IOException
Get completions for class field using given prefix

Parameters:
forClass -
forField -
prefix -
spanning -
starting -
Returns:
known completions
Throws:
java.io.IOException

getCompletionsFor

public static java.util.List<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass,
                                                                java.lang.String forField,
                                                                java.lang.String prefix,
                                                                java.lang.String parameters,
                                                                int starting,
                                                                int spanning)
                                                         throws java.io.IOException
Throws:
java.io.IOException

getCompletionsFor

public static org.benow.java.collection.SubList<CompleteResults> getCompletionsFor(java.lang.Class<?> forClass,
                                                                                   java.lang.String forField,
                                                                                   java.lang.String prefix,
                                                                                   java.lang.String parameters,
                                                                                   int starting,
                                                                                   int spanning,
                                                                                   org.benow.repository.Transaction tx)
                                                                            throws java.io.IOException
Get completions for class field using given prefix, including a repository search using the given transaction (if the field has been annotated with JSQLComplete).

Parameters:
forClass -
forField -
prefix -
Returns:
known completions
Throws:
java.io.IOException