| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr; |
| 9 |
|
| 10 |
|
| 11 |
import net.sf.saxon.type.FunctionItemType; |
| 12 |
import net.sf.saxon.type.ItemType; |
| 13 |
import net.sf.saxon.type.PlainType; |
| 14 |
import net.sf.saxon.value.SequenceType; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public class OperandRole { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public final static int SETS_NEW_FOCUS = 1; |
| 26 |
public final static int USES_NEW_FOCUS = 2; |
| 27 |
public final static int HIGHER_ORDER = 4; |
| 28 |
public final static int IN_CHOICE_GROUP = 8; |
| 29 |
public final static int CONSTRAINED_CLASS = 16; |
| 30 |
public final static int SINGLETON = 32; |
| 31 |
public final static int HAS_SPECIAL_FOCUS_RULES = 64; |
| 32 |
|
| 33 |
public final static OperandRole SAME_FOCUS_ACTION = |
| 34 |
new OperandRole(0, OperandUsage.TRANSMISSION, SequenceType.ANY_SEQUENCE); |
| 35 |
public final static OperandRole FOCUS_CONTROLLING_SELECT = |
| 36 |
new OperandRole(OperandRole.SETS_NEW_FOCUS, OperandUsage.INSPECTION, SequenceType.ANY_SEQUENCE); |
| 37 |
public final static OperandRole FOCUS_CONTROLLED_ACTION = |
| 38 |
new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER, OperandUsage.TRANSMISSION, SequenceType.ANY_SEQUENCE); |
| 39 |
public final static OperandRole INSPECT = |
| 40 |
new OperandRole(0, OperandUsage.INSPECTION, SequenceType.ANY_SEQUENCE); |
| 41 |
public final static OperandRole ABSORB = |
| 42 |
new OperandRole(0, OperandUsage.ABSORPTION, SequenceType.ANY_SEQUENCE); |
| 43 |
public final static OperandRole REPEAT_INSPECT = |
| 44 |
new OperandRole(OperandRole.HIGHER_ORDER, OperandUsage.INSPECTION, SequenceType.ANY_SEQUENCE); |
| 45 |
public final static OperandRole NAVIGATE = |
| 46 |
new OperandRole(0, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE); |
| 47 |
public final static OperandRole REPEAT_NAVIGATE = |
| 48 |
new OperandRole(OperandRole.HIGHER_ORDER, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE); |
| 49 |
public final static OperandRole REPEAT_NAVIGATE_CONSTRAINED = |
| 50 |
new OperandRole(OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS, OperandUsage.NAVIGATION, SequenceType.ANY_SEQUENCE); |
| 51 |
public final static OperandRole SINGLE_ATOMIC = |
| 52 |
new OperandRole(0, OperandUsage.ABSORPTION, SequenceType.SINGLE_ATOMIC); |
| 53 |
public final static OperandRole ATOMIC_SEQUENCE = |
| 54 |
new OperandRole(0, OperandUsage.ABSORPTION, SequenceType.ATOMIC_SEQUENCE); |
| 55 |
public final static OperandRole NEW_FOCUS_ATOMIC = |
| 56 |
new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER, OperandUsage.ABSORPTION, SequenceType.ATOMIC_SEQUENCE); |
| 57 |
public final static OperandRole PATTERN = |
| 58 |
new OperandRole(OperandRole.USES_NEW_FOCUS | OperandRole.HIGHER_ORDER | OperandRole.CONSTRAINED_CLASS, OperandUsage.ABSORPTION, SequenceType.ATOMIC_SEQUENCE); |
| 59 |
|
| 60 |
int properties; |
| 61 |
private OperandUsage usage; |
| 62 |
private SequenceType requiredType = SequenceType.ANY_SEQUENCE; |
| 63 |
|
| 64 |
public OperandRole(int properties, OperandUsage usage) { |
| 65 |
this.properties = properties; |
| 66 |
this.usage = usage; |
| 67 |
} |
| 68 |
|
| 69 |
public OperandRole(int properties, OperandUsage usage, SequenceType requiredType) { |
| 70 |
this.properties = properties; |
| 71 |
this.usage = usage; |
| 72 |
this.requiredType = requiredType; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public boolean setsNewFocus() { |
| 81 |
return (properties & SETS_NEW_FOCUS) != 0; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public boolean hasSameFocus() { |
| 90 |
return (properties & (USES_NEW_FOCUS | HAS_SPECIAL_FOCUS_RULES)) == 0; |
| 91 |
} |
| 92 |
|
| 93 |
public boolean hasSpecialFocusRules() { |
| 94 |
return (properties & HAS_SPECIAL_FOCUS_RULES) != 0; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public boolean isEvaluatedRepeatedly() { |
| 104 |
return ((properties & HIGHER_ORDER) != 0) && ((properties & SINGLETON) == 0); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public boolean isConstrainedClass() { return (properties & CONSTRAINED_CLASS) != 0; } |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public OperandUsage getUsage() { |
| 121 |
return usage; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public SequenceType getRequiredType() { |
| 130 |
return requiredType; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public boolean isInChoiceGroup() { |
| 139 |
return (properties & IN_CHOICE_GROUP) != 0; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public static OperandUsage getTypeDeterminedUsage(ItemType type) { |
| 149 |
if (type instanceof FunctionItemType) { |
| 150 |
return OperandUsage.INSPECTION; |
| 151 |
} else if (type instanceof PlainType) { |
| 152 |
return OperandUsage.ABSORPTION; |
| 153 |
} else { |
| 154 |
return OperandUsage.NAVIGATION; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
public OperandRole modifyProperty(int property, boolean on) { |
| 159 |
int newProp = on ? (properties | property) : (properties & ~property); |
| 160 |
return new OperandRole(newProp, usage, requiredType); |
| 161 |
} |
| 162 |
|
| 163 |
public int getProperties() { |
| 164 |
return properties; |
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|