## net.sf.saxon.trans
Class Mode

    java.lang.Object
      |
      +--net.sf.saxon.trans.Mode

All Implemented Interfaces:
  java.io.Serializable

public class Mode
extends java.lang.Object
implements java.io.Serializable

A Mode is a collection of rules; the selection of a rule to apply to a given element is determined by a Pattern.

See Also:
  Serialized Form

Field Summary
`static int` `ALL_MODES`
`static int` `DEFAULT_MODE`

Constructor Summary
`Mode()` Default constructor - creates a Mode containing no rules
`Mode(Mode omniMode)` Construct a new Mode, copying the contents of an existing Mode

Method Summary
`void` `addRule(Pattern p, java.lang.Object obj, int precedence, double priority)` Add a rule to the Mode.
`int` `getList(int fingerprint, int type)` Determine which list to use for a given pattern (we must also search the generic list)
`int` `getModeNameCode()` Get the name of this mode (for diagnostic output).
`java.lang.Object` `getNextMatchRule(NodeInfo node, java.lang.Object currentHandler, XPathContext context)` Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.
`java.lang.Object` `getRule(NodeInfo node, int min, int max, XPathContext context)` Get the rule corresponding to a given Node, by finding the best Pattern match, subject to a minimum and maximum precedence.
`java.lang.Object` `getRule(NodeInfo node, XPathContext context)` Get the rule corresponding to a given Node, by finding the best Pattern match.
`void` `setModeNameCode(int nameCode)` Set the name of this mode (for diagnostic output).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_MODE

    public static final int DEFAULT_MODE

See Also:
  Constant Field Values

### ALL_MODES

    public static final int ALL_MODES

See Also:
  Constant Field Values

Constructor Detail

### Mode

    public Mode()

  Default constructor - creates a Mode containing no rules

### Mode

    public Mode(Mode omniMode)

  Construct a new Mode, copying the contents of an existing Mode

Parameters:
  `omniMode` - the existing mode. May be null, in which case it is not copied

Method Detail

### setModeNameCode

    public void setModeNameCode(int nameCode)

  Set the name of this mode (for diagnostic output).

  Parameters:
    `nameCode` - a namePool name code, or -1 for the default (unnamed) mode

### getModeNameCode

    public int getModeNameCode()

  Get the name of this mode (for diagnostic output). Note that this will be a QName, in display form. If different prefixes have been used for the mode at different places in the stylesheet it is unpredictable which prefix will be used in the tracing output.

  Returns:
    the name of the mode, or -1 for the default mode.

### addRule

    public void addRule(Pattern p,
                        java.lang.Object obj,
                        int precedence,
                        double priority)

  Add a rule to the Mode.
  The rule effectively replaces any other rule for the same pattern/mode at the same or a lower priority.

  Parameters:
    `p` - a Pattern
    `obj` - the Object to return from getRule() when the supplied node matches this Pattern
    `precedence` - the import precedence of the rule
    `priority` - the explicit or implicit priority of the rule

### getList

    public int getList(int fingerprint,
                       int type)

  Determine which list to use for a given pattern (we must also search the generic list)

### getRule

    public java.lang.Object getRule(NodeInfo node,
                                    XPathContext context)
                             throws XPathException

  Get the rule corresponding to a given Node, by finding the best Pattern match.

  Parameters:
    `node` - the NodeInfo referring to the node to be matched
  Returns:
    the object (e.g. a NodeHandler) registered for that element, if any (otherwise null).
    `XPathException`

### getRule

    public java.lang.Object getRule(NodeInfo node,
                                    int min,
                                    int max,
                                    XPathContext context)
                             throws XPathException

  Get the rule corresponding to a given Node, by finding the best Pattern match, subject to a minimum and maximum precedence. (This supports xsl:apply-imports)

  Parameters:
    `node` - the NodeInfo referring to the node to be matched
  Returns:
    the object (e.g. a NodeHandler) registered for that element, if any (otherwise null).
    `XPathException`

### getNextMatchRule

    public java.lang.Object getNextMatchRule(NodeInfo node,
                                             java.lang.Object currentHandler,
                                             XPathContext context)
                                      throws XPathException

  Get the rule corresponding to a given Node, by finding the next-best Pattern match after the specified object.

  Parameters:
    `node` - the NodeInfo referring to the node to be matched
  Returns:
    the object (e.g. a NodeHandler) registered for that element, if any (otherwise null).
    `XPathException`