1 61 62 package org.jaxen.pattern; 63 64 import org.jaxen.Context; 65 66 72 public class NodeTypeTest extends NodeTest { 73 74 public static final NodeTypeTest DOCUMENT_TEST 75 = new NodeTypeTest( DOCUMENT_NODE ); 76 77 public static final NodeTypeTest ELEMENT_TEST 78 = new NodeTypeTest( ELEMENT_NODE ); 79 80 public static final NodeTypeTest ATTRIBUTE_TEST 81 = new NodeTypeTest( ATTRIBUTE_NODE ); 82 83 public static final NodeTypeTest COMMENT_TEST 84 = new NodeTypeTest( COMMENT_NODE ); 85 86 public static final NodeTypeTest TEXT_TEST 87 = new NodeTypeTest( TEXT_NODE ); 88 89 public static final NodeTypeTest PROCESSING_INSTRUCTION_TEST 90 = new NodeTypeTest( PROCESSING_INSTRUCTION_NODE ); 91 92 public static final NodeTypeTest NAMESPACE_TEST 93 = new NodeTypeTest( NAMESPACE_NODE ); 94 95 96 private short nodeType; 97 98 public NodeTypeTest(short nodeType) 99 { 100 this.nodeType = nodeType; 101 } 102 103 105 public boolean matches( Object node, Context context ) 106 { 107 return nodeType == context.getNavigator().getNodeType( node ); 108 } 109 110 public double getPriority() 111 { 112 return -0.5; 113 } 114 115 116 public short getMatchType() 117 { 118 return nodeType; 119 } 120 121 public String getText() 122 { 123 switch (nodeType) 124 { 125 case ELEMENT_NODE: 126 return "child()"; 127 case ATTRIBUTE_NODE: 128 return "@*"; 129 case NAMESPACE_NODE: 130 return "namespace()"; 131 case DOCUMENT_NODE: 132 return "/"; 133 case COMMENT_NODE: 134 return "comment()"; 135 case TEXT_NODE: 136 return "text()"; 137 case PROCESSING_INSTRUCTION_NODE: 138 return "processing-instruction()"; 139 } 140 return ""; 141 } 142 143 public String toString() 144 { 145 return super.toString() + "[ type: " + nodeType + " ]"; 146 } 147 } 148 | Popular Tags |