com.novell.xsl.process
Class Rule

java.lang.Object
  extended bycom.novell.xsl.process.Rule
All Implemented Interfaces:
Comparable
Direct Known Subclasses:
TemplateRule

public abstract class Rule
extends Object
implements Comparable

An abstract class for rules whose match pattern is a single path expression. Rules whose match pattern is a union of path expressions are represented by multiple instances of this class. Subclasses define what happens once a rule has been successfully matched.

This class implements java.lang.Comparable to impose a partial ordering on rules based on the XSL conflict resolution algorithm.


Constructor Summary
  Rule(Pattern pattern, ExpandedQName name, Mode mode, int importance, Priority priority, int number, Node nsContext)
          Constructs a new rule.
protected Rule(Rule original, Pattern pattern)
          Constructs a new rule that is (almost) a shallow copy of the specified rule, with the intent of using the new rule as one of the multiple instances representing a union of path expressions.
 
Method Summary
abstract  Rule cloneForUnion(Pattern pattern)
          An abstract method to create a new rule that is (almost) a shallow copy of this rule and whose actual class is the same as this rule's actual class, with the intent of using the new rule as one of the multiple instances representing a union of path expressions.
 int compareTo(Object obj)
          Compares this rule with another rule for conflict resolution order.
abstract  void dump(PrintWriter out, int indent)
          Dumps this object to the specified output stream.
 int getImportance()
          Returns this rule's importance.
 Mode getMode()
          Returns this rule's mode.
 ExpandedQName getName()
           
 Node getNamespaceContext()
          Return the node that is the namespace context for this template
 int getNumber()
          Returns this rule's identifying number.
 Pattern getPattern()
          Returns this rule's pattern.
 Priority getPriority()
          Returns this rule's priority.
protected static void indent(PrintWriter writer, int indent)
          Utility function for derived classes.
 boolean matches(Node source, ProcessingEnv env, Mode mode)
          Tests if this rule matches the specified source node and the specified mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rule

public Rule(Pattern pattern,
            ExpandedQName name,
            Mode mode,
            int importance,
            Priority priority,
            int number,
            Node nsContext)
Constructs a new rule.

Parameters:
pattern - the rule's path expression
name - the rule's name
mode - the rule's mode
importance - the rule's importance
priority - the rule's priority; null means use the default priority based on the rule's pattern
number - the rule's identifying number
nsContext - The node in the style sheet from which this rule comes

Rule

protected Rule(Rule original,
               Pattern pattern)
Constructs a new rule that is (almost) a shallow copy of the specified rule, with the intent of using the new rule as one of the multiple instances representing a union of path expressions. The new rule is not quite a shallow copy because its pattern is set to a different path expression.

Parameters:
original - the original rule
pattern - the clone's path expression, represented as a chain of FilterExpr objects
See Also:
cloneForUnion(com.novell.xsl.pattern.Pattern)
Method Detail

cloneForUnion

public abstract Rule cloneForUnion(Pattern pattern)
An abstract method to create a new rule that is (almost) a shallow copy of this rule and whose actual class is the same as this rule's actual class, with the intent of using the new rule as one of the multiple instances representing a union of path expressions. The new rule is not quite a shallow copy because its pattern is set to a different path expression.

Parameters:
pattern - the clone's path expression, represented as a chain of FilterExpr objects
Returns:
a clone of this rule, representing one of the path expressions in a union expression

dump

public abstract void dump(PrintWriter out,
                          int indent)
Dumps this object to the specified output stream.

Parameters:
out - the output stream to write to
indent - the number of tabs to indent

getPattern

public Pattern getPattern()
Returns this rule's pattern.

Returns:
this rule's pattern

getName

public ExpandedQName getName()

getMode

public Mode getMode()
Returns this rule's mode.

Returns:
the rule's mode

getImportance

public int getImportance()
Returns this rule's importance. Larger values represent greater importance.

XSL specifies only that certain rules are "more important" than others. Therefore the actual numeric importance values are strictly an artifact of our implementation.

Returns:
this rule's importance

getPriority

public Priority getPriority()
Returns this rule's priority. Larger values represent greater priority.

Returns:
this rule's priority

getNumber

public int getNumber()
Returns this rule's identifying number. This is not part of the XSL spec; it exists in this implementation to help identify rules.

Returns:
this rule's identifying number

compareTo

public int compareTo(Object obj)
Compares this rule with another rule for conflict resolution order. Rules sorted using this comparison are arranged in order of decreasing preference for XSL conflict resolution (earlier rules would be chosen over later rules).

Specified by:
compareTo in interface Comparable
Parameters:
obj - the other Rule to compare with; it is declared as an Object to conform with the Comparable interface
Returns:
a negative integer, zero, or a positive integer depending on whether conflict resolution would prefer this rule, neither rule (a tie), or the other rule
Throws:
ClassCastException - if the specified object is not a Rule

matches

public boolean matches(Node source,
                       ProcessingEnv env,
                       Mode mode)
                throws XSLException
Tests if this rule matches the specified source node and the specified mode.

Parameters:
source - the source node to be tested
mode - the mode to be tested
Returns:
true if this rule matches, false if it does not
Throws:
XSLException - if a fatal error occurs during evaluation

getNamespaceContext

public Node getNamespaceContext()
Return the node that is the namespace context for this template

Returns:
The namespace context node.

indent

protected static void indent(PrintWriter writer,
                             int indent)
Utility function for derived classes.

Parameters:
writer - Output device.
indent - Number of tabs to output.