1 package net.sf.saxon.om; 2 import net.sf.saxon.trans.StaticError; 3 import net.sf.saxon.type.Type; 4 5 8 9 public final class Axis { 10 11 14 15 public static final byte ANCESTOR = 0; 16 18 public static final byte ANCESTOR_OR_SELF = 1; 19 21 public static final byte ATTRIBUTE = 2; 22 24 public static final byte CHILD = 3; 25 27 public static final byte DESCENDANT = 4; 28 30 public static final byte DESCENDANT_OR_SELF = 5; 31 33 public static final byte FOLLOWING = 6; 34 36 public static final byte FOLLOWING_SIBLING = 7; 37 39 public static final byte NAMESPACE = 8; 40 42 public static final byte PARENT = 9; 43 45 public static final byte PRECEDING = 10; 46 48 public static final byte PRECEDING_SIBLING = 11; 49 51 public static final byte SELF = 12; 52 53 56 58 public static final byte PRECEDING_OR_ANCESTOR = 13; 59 60 61 64 65 public static final short[] principalNodeType = 66 { 67 Type.ELEMENT, Type.ELEMENT, Type.ATTRIBUTE, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, Type.NAMESPACE, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, Type.ELEMENT, }; 82 83 86 87 public static final boolean[] isForwards = 88 { 89 false, false, true, true, true, true, true, true, false, true, false, false, true, false, }; 104 105 108 109 public static final boolean[] isReverse = 110 { 111 true, true, false, false, false, false, false, false, false, true, true, true, true, true, }; 126 127 131 132 public static final boolean[] isPeerAxis = 133 { 134 false, false, true, true, false, false, false, true, true, true, false, true, true, false, }; 149 150 154 155 public static final boolean[] isSubtreeAxis = 156 { 157 false, false, true, true, true, true, false, false, true, false, false, false, true, false, }; 172 173 176 177 public static final String [] axisName = 178 { 179 "ancestor", "ancestor-or-self", "attribute", "child", "descendant", "descendant-or-self", "following", "following-sibling", "namespace", "parent", "preceding", "preceding-sibling", "self", "preceding-or-ancestor", }; 194 195 198 199 private Axis() { 200 } 201 202 209 210 public static byte getAxisNumber(String name) throws StaticError { 211 if (name.equals("ancestor")) return ANCESTOR; 212 if (name.equals("ancestor-or-self")) return ANCESTOR_OR_SELF; 213 if (name.equals("attribute")) return ATTRIBUTE; 214 if (name.equals("child")) return CHILD; 215 if (name.equals("descendant")) return DESCENDANT; 216 if (name.equals("descendant-or-self")) return DESCENDANT_OR_SELF; 217 if (name.equals("following")) return FOLLOWING; 218 if (name.equals("following-sibling")) return FOLLOWING_SIBLING; 219 if (name.equals("namespace")) return NAMESPACE; 220 if (name.equals("parent")) return PARENT; 221 if (name.equals("preceding")) return PRECEDING; 222 if (name.equals("preceding-sibling")) return PRECEDING_SIBLING; 223 if (name.equals("self")) return SELF; 224 throw new StaticError("Unknown axis name: " + name); 226 } 227 228 232 233 private static final int DOC = 1<<Type.DOCUMENT; 234 private static final int ELE = 1<<Type.ELEMENT; 235 private static final int ATT = 1<<Type.ATTRIBUTE; 236 private static final int TEX = 1<<Type.TEXT; 237 private static final int PIN = 1<<Type.PROCESSING_INSTRUCTION; 238 private static final int COM = 1<<Type.COMMENT; 239 private static final int NAM = 1<<Type.NAMESPACE; 240 241 private static int[] voidAxisTable = { 242 DOC, 0, DOC|ATT|TEX|PIN|COM|NAM, ATT|TEX|PIN|COM|NAM, ATT|TEX|PIN|COM|NAM, 0, DOC, DOC|ATT|NAM, DOC|ATT|TEX|PIN|COM|NAM, DOC, DOC, DOC|ATT|NAM, 0, }; 256 257 public static boolean isAlwaysEmpty(int axis, int nodeKind) { 258 return (voidAxisTable[axis] & (1<<nodeKind)) != 0; 259 } 260 261 264 265 private static int[] nodeKindTable = { 266 DOC|ELE, DOC|ELE|ATT|TEX|PIN|COM|NAM, ATT, ELE|TEX|PIN|COM, ELE|TEX|PIN|COM, DOC|ELE|ATT|TEX|PIN|COM|NAM, ELE|TEX|PIN|COM, ELE|TEX|PIN|COM, NAM, DOC|ELE, DOC|ELE|TEX|PIN|COM, ELE|TEX|PIN|COM, DOC|ELE|ATT|TEX|PIN|COM|NAM, }; 280 281 284 285 public static boolean containsNodeKind(int axis, int nodeKind) { 286 return (nodeKindTable[axis] & (1<<nodeKind)) != 0; 287 } 288 289 290 291 292 } 293 294 310 311 312 | Popular Tags |