JSAPI 2.0

javax.speech.recognition
Class GrammarEvent

Object
  extended by SpeechEvent
      extended by GrammarEvent

public class GrammarEvent
extends SpeechEvent

Event issued to GrammarListeners when events associated with Grammars occur.

GrammarListeners attached to a Grammar receive only GrammarEvents associated with that Grammar. GrammarListeners attached to a GrammarManager receive associated GrammarEvents for all managed Grammars.

The source for a GrammarEvent is always a Grammar object.

See Also:
Grammar, GrammarListener, addGrammarListener, addGrammarListener

Field Summary
static int DEFAULT_MASK
          The default mask for events in this class.
static int GRAMMAR_ACTIVATED
          Event issued when a Grammar changes state from deactivated to activated.
static int GRAMMAR_CHANGES_COMMITTED
          Event issued when a Recognizer commits changes to a Grammar.
static int GRAMMAR_CHANGES_REJECTED
          Event issued when a Recognizer rejects changes to a Grammar.
static int GRAMMAR_DEACTIVATED
          Event issued when a Grammar changes state from activated to deactivated.
 
Fields inherited from class SpeechEvent
DISABLE_ALL, ENABLE_ALL
 
Constructor Summary
GrammarEvent(Grammar source, int id)
          Constructs a GRAMMAR_ACTIVATED or GRAMMAR_DEACTIVATED GrammarEvent.
GrammarEvent(Grammar source, int id, boolean activatableChanged, boolean definitionChanged, GrammarException grammarException)
          Constructs a GRAMMAR_CHANGES_COMMITTED or GRAMMAR_CHANGES_REJECTED GrammarEvent.
 
Method Summary
 GrammarException getGrammarException()
          Returns a GrammarException if an error is found in the source Grammar.
 boolean isActivatableChanged()
          Returns true for a GRAMMAR_CHANGES_COMMITTED event if the activatable property of the source Grammar changed.
 boolean isDefinitionChanged()
          Returns true for a GRAMMAR_CHANGES_COMMITTED event if the definition of the source Grammar changed.
 String paramString()
          Returns a parameter String that contains the event identifier in text form.
 String toString()
          Returns a printable String.
 
Methods inherited from class SpeechEvent
getId, getSource
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GRAMMAR_CHANGES_COMMITTED

public static final int GRAMMAR_CHANGES_COMMITTED
Event issued when a Recognizer commits changes to a Grammar. This event is issued immediately following the CHANGES_COMMITTED RecognizerEvent issued to RecognizerListeners. That event indicates that changes have been applied from all Grammars of a GrammarManager.

This event is specific to each individual Grammar. It is issued when the definition of the Grammar is changed, when its activatable property is changed, or both. The isDefinitionChanged and isActivatableChanged methods indicate these conditions.

If any syntactic or logical errors are detected for a Grammar during the commit, a GRAMMAR_CHANGES_REJECTED event is generated rather than this event.

See Also:
GRAMMAR_CHANGES_REJECTED, CHANGES_COMMITTED, isDefinitionChanged, isActivatableChanged, resume, GrammarEvent(Grammar, int, boolean, boolean, GrammarException), Constant Field Values

GRAMMAR_CHANGES_REJECTED

public static final int GRAMMAR_CHANGES_REJECTED
Event issued when a Recognizer rejects changes to a Grammar. This event is issued immediately following the CHANGES_REJECTED RecognizerEvent that is issued to RecognizerListeners. That event indicates that changes have been rejected for all changed Grammars of a GrammarManager.

This event is specific to each individual changed Grammar. The getGrammarException method returns a non-null GrammarException if the Grammar contains any syntactic or logical errors.

See Also:
GRAMMAR_CHANGES_COMMITTED, CHANGES_REJECTED, getGrammarException, GrammarException, GrammarEvent(Grammar, int, boolean, boolean, GrammarException), Constant Field Values

GRAMMAR_ACTIVATED

public static final int GRAMMAR_ACTIVATED
Event issued when a Grammar changes state from deactivated to activated. The isActive method of the Grammar will now return true.

Grammar activation changes follow one of two RecognizerEvents:

  1. A CHANGES_COMMITTED event - in this case a GRAMMAR_CHANGES_COMMITTED event where isActivatableChanged returns true also precedes this event
  2. An ENGINE_FOCUSED event.

See Grammar Activation for details about Grammar activation and deactivation.

See Also:
GRAMMAR_ACTIVATED, GRAMMAR_CHANGES_COMMITTED, isActivatableChanged, Grammar, isActive, CHANGES_COMMITTED, ENGINE_FOCUSED, GrammarEvent(Grammar, int), Constant Field Values

GRAMMAR_DEACTIVATED

public static final int GRAMMAR_DEACTIVATED
Event issued when a Grammar changes state from activated to deactivated. The isActive method of the Grammar will now return false.

Grammar deactivation changes follow one of two RecognizerEvents:

  1. A CHANGES_COMMITTED event - in this case a GRAMMAR_CHANGES_COMMITTED event where isActivatableChanged returns true also precedes this event
  2. an ENGINE_DEFOCUSED event.

See Grammar Activation for details about Grammar activation and deactivation.

See Also:
GRAMMAR_DEACTIVATED, GRAMMAR_CHANGES_COMMITTED, isActivatableChanged, Grammar, isActive, CHANGES_COMMITTED, ENGINE_DEFOCUSED, GrammarEvent(Grammar, int), Constant Field Values

DEFAULT_MASK

public static final int DEFAULT_MASK
The default mask for events in this class.

The following events are delivered by default: GRAMMAR_CHANGES_COMMITTED, GRAMMAR_CHANGES_REJECTED, GRAMMAR_ACTIVATED, GRAMMAR_DEACTIVATED.

Use setGrammarMask to change the GrammarEvent mask if desired.

See Also:
GRAMMAR_CHANGES_COMMITTED, GRAMMAR_CHANGES_REJECTED, GRAMMAR_ACTIVATED, GRAMMAR_DEACTIVATED, setGrammarMask, Constant Field Values
Constructor Detail

GrammarEvent

public GrammarEvent(Grammar source,
                    int id)
             throws IllegalArgumentException
Constructs a GRAMMAR_ACTIVATED or GRAMMAR_DEACTIVATED GrammarEvent.

Parameters:
source - the Grammar object that issued the event
id - the event identifier
Throws:
IllegalArgumentException - if called with an inappropriate event ID
See Also:
GRAMMAR_ACTIVATED, GRAMMAR_DEACTIVATED

GrammarEvent

public GrammarEvent(Grammar source,
                    int id,
                    boolean activatableChanged,
                    boolean definitionChanged,
                    GrammarException grammarException)
             throws IllegalArgumentException
Constructs a GRAMMAR_CHANGES_COMMITTED or GRAMMAR_CHANGES_REJECTED GrammarEvent.

For a GRAMMAR_CHANGES_COMMITTED event, the activatableChanged and definitionChanged parameters indicate what properties of the Grammar have changed. Otherwise, these parameters are false.

For a GRAMMAR_CHANGES_REJECTED event, if the Grammar contains an error, then the grammarException parameter specifies the error encountered. Otherwise, the grammarException is null.

Parameters:
source - the Grammar object that issued the event
id - the event identifier
activatableChanged - true if the Grammar's activatable property changed
definitionChanged - true if the Grammar's definition changed
grammarException - non-null description if error encountered, otherwise null
Throws:
IllegalArgumentException - if called with an inappropriate event ID
See Also:
GRAMMAR_CHANGES_COMMITTED, GRAMMAR_CHANGES_REJECTED, isActivatableChanged, isDefinitionChanged, getGrammarException, RecognizerEvent.CHANGES_COMMITTED, RecognizerEvent.CHANGES_REJECTED
Method Detail

isDefinitionChanged

public boolean isDefinitionChanged()
Returns true for a GRAMMAR_CHANGES_COMMITTED event if the definition of the source Grammar changed. Returns false in all other cases.

Returns:
flag that the source Grammar definition has changed.
See Also:
GRAMMAR_CHANGES_COMMITTED, getSource

isActivatableChanged

public boolean isActivatableChanged()
Returns true for a GRAMMAR_CHANGES_COMMITTED event if the activatable property of the source Grammar changed. Returns false in all other cases.

Returns:
flag that the source Grammars activatable property changed.
See Also:
GRAMMAR_CHANGES_COMMITTED, getSource

getGrammarException

public GrammarException getGrammarException()
Returns a GrammarException if an error is found in the source Grammar. This applies to a GRAMMAR_CHANGES_REJECTED event. Returns null in all other cases.

Returns:
a GrammarException with information about the source Grammar error
See Also:
GRAMMAR_CHANGES_REJECTED, getSource

paramString

public String paramString()
Returns a parameter String that contains the event identifier in text form.

The method toString may provide more detail. This method is useful for event-logging and for debugging.

Specified by:
paramString in class SpeechEvent
Returns:
a String that contains the event identifier in text form.
See Also:
toString

toString

public String toString()
Returns a printable String. Useful for event-logging and debugging.

The method paramString also provides printable information.

Specified by:
toString in class SpeechEvent
Returns:
A printable string.
See Also:
paramString

JSAPI 2.0

JavaTM Speech API 2.0, Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.

Free Web Hosting