1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.jxpath.ri.compiler;
19
20 import org.apache.commons.jxpath.ri.Compiler;
21
22 /**
23 * Node type test.
24 */
25 public class NodeTypeTest extends NodeTest {
26
27 /**
28 * Render the given node type as a String.
29 *
30 * @param code int
31 * @return String
32 */
33 public static String nodeTypeToString(final int code) {
34 switch (code) {
35 case Compiler.NODE_TYPE_NODE:
36 return "node";
37 case Compiler.NODE_TYPE_TEXT:
38 return "text";
39 case Compiler.NODE_TYPE_COMMENT:
40 return "comment";
41 case Compiler.NODE_TYPE_PI:
42 return "processing-instruction";
43 default:
44 return "UNKNOWN";
45 }
46 }
47
48 private final int nodeType;
49
50 /**
51 * Constructs a new NodeTypeTest.
52 *
53 * @param nodeType to match
54 */
55 public NodeTypeTest(final int nodeType) {
56 this.nodeType = nodeType;
57 }
58
59 /**
60 * Gets the nodeType.
61 *
62 * @return int
63 */
64 public int getNodeType() {
65 return nodeType;
66 }
67
68 @Override
69 public String toString() {
70 return nodeTypeToString(nodeType) + "()";
71 }
72 }